• Phuket2

    Over some years it has been brought up before how some people have expresssed interest in supporting the Pythonista App/project in terms of some addtional financal support. A lot of peple get a lot out of this App and their are some in a position to give back. Its never been brought up it that it should be maditory or that if you contribute you get any special attention. BTW, a lot of people already make big contributions, via the forum help, the issues repo, writing very important tools such as StaSh etc.
    Anyway, @omz the reason why I bring it up again today is because I joined this site today that allowed me to support a podcast 'Talk Python To Me' which I am sure you are aware of. I dont get as much out of the podcast as I do from Pythonistia, but I still do get a lot out of it.
    Ok, its slightly different as there is no cost to listen to the podcasts, however he still has sponsors.
    I felt good I was able to contribute to the show. I wont say how much I contributed, but it wasn't much. But of course a lot of not much's can quickly add up. He also goes into a brief explaination about how he wants to use the money raised. Eg. Supporting his escalating bandwidth costs for serving up the podcast, hiring a professional to edit the audio of the recordings etc...
    In no way do i see this as begging. He is just stating the financial realities of producing the show. My observation, he is basically a indie industry guy not unlike yourself.

    Anyway, sorry to bring it up again. Just food for thought!

    posted in General Discussion read more
  • Phuket2

    A lazy Sunday :) I just thought I would share this small thing I did. It's very simple. It's just a function that returns a view that has a Cancel and OK button. When making a ui is a good chance you will need something like this over and over again. My implementation may not be to your liking, but it makes sense to me to have some code like this in a snippet for example.
    I didn't go for super flexibility, just the basics of what I would normally require. Stupidity enough, I didn't have a function like this as a snippet, but i will do now. I probably should have made the padding numbers variables.

    import ui
    def cancel_ok_view(action=None, **kwargs):
        returns a ui.View with a Cancel and OK buttons.  The action is
        shared, so you will have to check the name or title for the logic
        -Note the **kwargs age passed to the ui.View
        def make_btn(name, title, action=None, **kwargs):
            btn = ui.Button(name=name,
            btn.width = 100
            return btn
        v = ui.View(frame=(0, 0, 215, 40), **kwargs)
        ok_cancel = make_btn('cancel', 'Cancel', action=action)
        ok_cancel.x = 5
        ok_cancel.y = 4
        ok_btn = make_btn('ok', 'OK', action=action)
        ok_btn.x = ok_cancel.frame.max_x + 5
        ok_btn.y = 4
        return v
    class MyClass(ui.View):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
        def make_view(self):
            v = cancel_ok_view(bg_color=None, action=self.btn_action)
            v.y = self.height - v.height
            v.x = self.width - v.width
        def btn_action(self, sender):
            print('Button named {} pressed'.format(sender.name))
    if __name__ == '__main__':
        f = (0, 0, 320, 480)
        mc = MyClass(frame=f)

    posted in Pythonista read more
  • Phuket2

    @mikael , thanks for your reply. The more I think about it, when I was a programmer, should never have coded in the workflow like I do here. I always got the data pretty well sorted out very early in the process. Even if I had to use something as crude as a csv file to get started (more often was resource files, c structs or a database or combination of these persistent storage types). Mind you this was not for web deployment, whilst there was a web, without dedicated isdn lines, you had no chance to transmit what we would have called large datasets at the time.
    Of course the data storage building/processing was a totally different process development from your end user application.
    So i think I will try and be more mindful of that in the future. In my little attempts here, i mix all this in together. In hind sight its no wonder I end up chasing my tail so much. In my opinion, I should be basically writing a presentation app that displays and manipulates my data. Not sure how others think about that. But I am going to do it anyway in the hope it will help me focus more.

    Regards to how I used shelve, basically I didn't know what I was doing from a object design perspective. It was just to get something going. I really dont like the whole pickle thing. A few reasons, first I am ignorant about pickling, also version problems with pickling. I also dont like shelve uses 3 files, it drives me crazy. But I used it to get started because everyone could run the code.
    I would have preferred to use TinyDB. But ultimately I would like to have a have a base strorage system that you can subclass. The subclass would inherit the ability to handle a key,value storage. But you could change/extend the underlying storage engine say from shelve to TinyDB with very little work. Hmmmm, well that's what I think I want, at least to start with. For locally run apps, It appears to mean you can do a lot with simple key,value storage systems.
    Also keeps the complexity to data you are likely to be dealing with in a local Pythonista App.

    So i will try a few different things. It's a good learning exercise, even if I do go down the wrong track for a while. I will also try to get my head around your comments about using the dunder methods, setitem & getitem. I used them a long time ago. But got myself in trouble with side effects that can occur if you are not using them properly. Maybe I am a bit better equipped today to use them in a more informed way, maybe not :).

    Again, thanks for your feedback. I really appreciate it. Unfortunately for me to have a in person conversation with a Python programmer, its approx 2 hr travel into Bangkok for meetup's they have there. 2hr's is a very modest estimate, once in Bangkok, then have to get to the venue. Depending on traffic & time you could easily double that. Through the network of Thai's I know, I have come across a few that can program a little in Python, but the language barrier makes it very difficult to have very meaningful conversations. Oh well, thats my life history :). Sorry, just in the mood for typing.

    posted in Pythonista read more
  • Phuket2

    @mikael , thanks. Your solution, it was 100% correct. Anyone interested, I updated the repo.
    I am going to play some more to see if can get this better. Maybe it's fools errand, but it keeps me out of trouble :)

    posted in Pythonista read more
  • Phuket2

    @dgelessus , lol. Another strange one. I am on iOS 11.2 I still get the problem I mentioned above. Problem is I cant remember when it start happening. But I do feel its has been escalating in frequency. It's funny, I tried a few things to replicate it when writing this post and I couldn't get it to happen :( I know the problem is still there though. So annoying. But I am sure the best fix for me was actually clicking on the preview view. Not other places. What sort of worked, but not all the time was to click the expansion arrow to go full screen, then hit it again. But it did not always work.
    Anyway, whatever works for ppl. It's very frustrating until you find your own way to re-sync your cursor. I have in the past have to do a select all, copy, discard the post and copy into a new post.

    posted in General Discussion read more
  • Phuket2

    @mikael , thanks. Will try. I actually didn't think of that, but in the back of my head I thought something like that was going on even though what you say escaped me,but now you point it out it makes sense. I thought when i did the copy.copy and copy.deepcopy would detach something like this (even though I didn't know what I was looking for). But I think I understand now why that would not have worked.
    Again thanks, I should be able to solve it now.

    posted in Pythonista read more
  • Phuket2

    This may not just work for the iPad and the smart Apple keyboard , but thats what I use. But often when I am writing on the forum and change focus out of the input field, when i tap back into the input field my cursor can be out of sync. It can be hard to get it back into the right place. Eg, the cursor might appear 2 lines down, but still the input is going where it should. Anyway, I have found if you just tap on the preview field, then tap back to the input field, this seems to re-sync your cursors location.
    I just mention this because it was driving me crazy. Anyway, this seems to work for me.

    posted in General Discussion read more
  • Phuket2

    Back again :) I started to try to make a storage object for the table using shelve. Was a first try, my idea was to try to make the storage a more of a generic class, so you overwrite the read/write methods also the file creation.
    But I had a bit of a epiphany at least in my mind. I have always struggled with how to implement a persistent class into the class I want to persist certain attrs with. It may be clear for you guys, but I has always done my head in(the egg before the chicken thing
    ). I can do it, but It never seems elegant , feels wrong.
    So my epiphany was to create the storage file first and populate it, and pass the storage class to the class I want to persist attrs. Then use the storage file to populate the classes data. Look, this may be crap way to do things, but the workflow to me seems a lot more natural. Please if you have the time comment on this approach, good or bad/scathing does not matter, would love to hear thoughts on this approach.

    Anyway, I have a problem I cant seem to solve. It's to do with writing the contents of self.items back to the shelve file. The simple int self.selected works fine. But the list of dicts contained in self.Items generates at Type Error "can't pickle CheckMarkTable objects". The start of the call chain occurs in the CheckMarkTable method "will_close". I have add comments above the line saying what I have tried etc. I am sure its something simple, but now I feel like my head is going to explode. I just cant see the problem. Also I haven't done much with shelve and pickling. The trace back is listed below.
    To make things a little easier I created a repo here.

    So to Summarise

    1. I would love to hear any feedback on the idea of first creating and populating a storage class, and passing it to target class instead of data params.
    2. If anyone can see why I am getting the error when trying to write the self.items attr, I would be great full to get a solution.

    Note: I have just used shelve here as a starting point. I am hoping to make the storage class more generic so you can choose to write your own and just overwrite a few methods.

    Traceback (most recent call last):
    File "/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/nested_dict/porrmansdialog2.py", line 138, in will_close
    self.storage.write('items', self.items)
    File "/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/nested_dict/porrmansdialog2.py", line 50, in write
    db[k] = v
    File "/var/containers/Bundle/Application/F132DFB7-BD77-4096-ADA6-D8CA8F4468F2/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/shelve.py", line 125, in setitem
    TypeError: can't pickle CheckMarkTable objects

    posted in Pythonista read more
  • Phuket2

    I was just playing around. Just thought I would share what I was doing. I was trying to basically make a checkmark list. I was trying to keep it simple and small. I might look a little on the large size, its mainly the comments, there is not much to it though.
    Basically its just me thinking out aloud. The dialogs package is great, but still is hard to override it's behaviour easily. I am using multiple inheritance, which some may say is bad form. I am not sure. But I put some notes above the class about what I was doing. It's not supposed to be a finished class. More like just a test before going further.
    Maybe useful for new Pythonista members new to the ui module. However, as i say, some may take exception to the use of the multiple inheritance.

    import ui
    poor mans list dialog... Just playing around. Wanted to see how the
    multiple inheritance would workout.  It seems to have worked ok!
    I was hoping to make it a bit smaller in code lines than it is,
    but the logic is the logic. Could probably shave off a few lines,
    but not that many I think.
    Besides playing around I was thinking of having a number of these
    classes just specfic to a single pupose like a checkmark list etc...
    But keeping them small and managable.
    The dialogs module is good. But it is a bit inflexible. Sometimes
    you have to fight hard to override some behaviour you may want/need
    Anyway, this is just a start or thinking out aloud.  I will make some mods,
    to handle sections and ui.TableViewCell's
    I also included the image in the dict but not doing anthing with it as yet.
    I think its still a good example if you are new to Pythonista to see
    how easily you can make your own list.  HOWEVER, not sure what the seasoned
    Python programmers here will think of me using multiple inheitance.
    What i have done maybe be considered bad form, I am not sure.
    I was trying to get a small footprint.  I couldn't see any reason why this
    should be bad.  The base classes and there params dont overlap.
    class CheckMarkTable(ui.View, ui.ListDataSource):
        def __init__(self, items=None, selection=None, *args, **kwargs):
            # call the base init methods explicitly. I know there is a way
            # to call with super and it works it out, but I have had problems
            # with that past. This seems more straight fwd to me.
            ui.View.__init__(self, *args, **kwargs)
            ui.ListDataSource.__init__(self, [])
            # setup up the ui.TableView, pointing data_source and delegate to self
            tbl = ui.TableView(frame=self.bounds, flex='WH')
            tbl.data_source = tbl.delegate = self
            self.action = self._action
            items = items or []
            self.items = [{'title': str(item), 'image': None, 'accessory_type': ''}
                          for item in items]
            self.selected = selection
        def _action(self, sender):
            # called when a cell is tapped
        def set_checkmark(self, row):
            if row is None:
            # if the same row is selected, toggle the value
            if self.selected == row:
                if self.items[row]['accessory_type'] == 'checkmark':
                    self.items[row]['accessory_type'] = ''
                    self.items[row]['accessory_type'] = 'checkmark'
                # clear the previous selections and set the new selection
                self.items[row]['accessory_type'] = 'checkmark'
            self.selected = row
        def get_selected_item(self):
            # get the data item of the selected row
            if self.selected is not None:
                return self.items[self.selected]
        def clear_selection(self):
            # set all the item['accessory_type'] = ''
            for item in self.items:
                item['accessory_type'] = ''
    if __name__ == '__main__':
        f = (0, 0, 320, 480)
        items = ['Red', 'Green', 'Blue', 'Black', 'Orange', 'Yellow']
        t = CheckMarkTable(frame=f, items=items, selection=None, name='List')
        t.present('sheet', animated=False)

    posted in Pythonista read more
  • Phuket2

    (Sorry I wrote this a few days ago, but looks like i forgot to submit it) :(
    @reticulated , thanks for your detailed reply. Sounds great what you are doing. I also agree about the padding. I also try to use a content_view same as @omz when doing such things. It's super helpful. Only small issue iteration over items in the view. But @JonB ViewWalker helps with that.
    I never use pickle. I am just scared of it :). Just because I dont understand all the gotchas. But for the config/state etc... if you say choose json, for config/settings etc, you could possibly have an object that does the read/writes etc in your storage of choice, shelve for example. But the object may allow for different storage's. I only mention because TinyDB project has this concept of custom Middleware and storage. But this maybe over the top.
    But really looking fwd to seeing your project. I have put a watch on this thread so i will get updates

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!