• cook

    @ccc @phuket2 you had a lot going on here with this and I didn't see. Sorry! Ian's original post got me thinking about layout a lot, and I started on something as well. I really like how you can do a lot of auto layout in html with css or javascript and it's really useful. I think the same is possible for UI. So far I have:

    • distribute horizontally (equal distribution) with padding is possible
    • distribute vertically (equal distribution) with padding is possible
    • adjust width/height/x/y by percent (rather than by points or pixels)

    Working on a grid distribution.

    None of this is too hard or rocket science. Just a bunch of numbers. I'm sure anyone could do it...
    It's really different than what @phuket2 has above though...!!

    I don't know why I didn't think to do this before... I seem to use a kind of distribution for doing buttons at times, but having it in a module would be much easier. Will share once I've got kinks worked out...

    With what I have already I could do @phuket2 's battleship grid without the headache! But I want to improve the functions to make it even more straightforward.

    posted in Pythonista read more
  • cook

    @phuket2 I like the idea of this!

    Here's a thought:
    For vertical alignment you have another term you can use:

    Top
    Middle
    Bottom

    posted in Pythonista read more
  • cook

    @Webmaster4o
    The date from the post above:
    2015-08-05T15:37:01.049Z

    posted in Announcements read more
  • cook

    Sorry I don't quite follow...
    Do you want to know good ways to back up your files or good ways to give your files to others?

    posted in Pythonista read more
  • cook

    Great!
    I'd also like something similar with Japanese Living Bible....need to get it somehow first. I think I may write to the publishing company.

    posted in Pythonista read more
  • cook

    The copy sounds very useful to me. I don't use the console too much, but these days I'm starting to more. Being able to copy things easily would be great.

    Will try the search bar thing again. Was on my iPad but will try like you said.

    posted in Pythonista read more
  • cook

    An unfortunate bit about the search bar in the title bar- in panel presentation the width is limited.... Maybe there's some workaround but...

    posted in Pythonista read more
  • cook

    Thank you @jonb. I am not sure if I will use this too much. But it's nice to just read through the UI code. Especially this part about hijacking UI.buttonitem:
    I will try to use that for something else. That's really cool!!

    
    searchField=ui.TextField()
    searchField.placeholder='Search'
    searchField.frame=(0,0,180,32)
        searchField.clear_button_mode='always'
    editor.apply_ui_theme(searchField)
    searchBarButton=ui.ButtonItem()
        ObjCInstance(searchBarButton).customView=searchField
    

    posted in Pythonista read more
  • cook

    @ccc yeah I havent really ventured out into making a project that incorporates more than one file yet. But of course when I do (and from now on) I think this sort of thing will be very nice. It's much better than cluttering up the console!!

    posted in Pythonista read more
  • cook

    Didn't know about the logger module until I was reading this discussion initiated by @phuket2. Thanks @ccc for mentioning about the logging module.

    I've made logging_setup.py just for ease of use. I'm just sharing it if anyone wants to.

    This has a few defaults:

    • prints to a file (.txt b/c Pythonista doesn't open .log by default)
    • Note: if used in different scripts, the 'name' arg is important for logging to different files.
    • mode is set to overwrite (you can set it with keyword arg)
    • format looks like this: "DEBUG: this is a message." (can change with fmt keyword)

    A few benefits:

    • can have the log file in a tab in the editor
    • can use the 'Find' in editor to search the log
    • no console take-over when running your script

    Quick setup:

    import logging
    import logging_setup
    log = logging_setup.logging_setup('my_log') #use a unique name
    log.debug('a message for the log')
    log.error('oh no.')
    log.warning('oh no.')
    log.critical('call 911... or omz')
    log.info('well now it seems you have some mighty fine logging going on.')
    logging.shutdown() #necessary at the end of the script running
    

    I did test this with using it in a few different files at the same time. I didn't think it was going to work because of name spaces (ex: if you use log in two files and have imported one file into the other) - but it seems to work fine. One very important thing: if you do not use logging.shutdown() it will not work properly (seems that logs are carried over from before).

    Code:

    logging_setup.py

    posted in Pythonista read more
  • cook

    @Phuket2 the syntax may be strange but considering that parenthesis are used for other things it isn't...

    Consider:

    >>> (0)
    0
    >>> (0,)
    (0,)
    

    posted in Pythonista read more
  • cook

    According to this the above is deprecated in iOS 9. Apparently using prefersStatusBarHidden for the UIViewController is what is needed. This shows up as a method in the console autocomplete but when trying to actually call it I get the error that there is no such method. ???

    >>> a = ObjCClass('UIViewController').alloc().init()
    >>> a.prefersStatusBarHidden(True)
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/var/containers/Bundle/Application/E466E17B-54D9-45D4-BC0D-A2A4CFD1F40C/Pythonista3.app/Frameworks/PythonistaKit3.framework/pylib/site-packages/objc_util.py", line 796, in __call__
        method_name, kwarg_order = resolve_instance_method(obj, self.name, args, kwargs)
      File "/var/containers/Bundle/Application/E466E17B-54D9-45D4-BC0D-A2A4CFD1F40C/Pythonista3.app/Frameworks/PythonistaKit3.framework/pylib/site-packages/objc_util.py", line 403, in resolve_instance_method
        raise AttributeError('No method found for %s' % (name,))
    AttributeError: No method found for prefersStatusBarHidden
    

    posted in Pythonista read more
  • cook

    Thanks @Cethric . Though...if I change to functions I believe the setStatusBarHidden_(True) is okay. The thing that is not okay is setting prefersStatusBarHidden_(True) on a view object. The method is not there.

    Perhaps my error is that prefersStatusBarHidden belongs to something else?

    Anyway it seems this is the way to enable this functionality if it wasn't set in the info.plist (which I believe it isn't for Pythonista).

    posted in Pythonista read more
  • cook

    Not sure if this is really possible but I don't know if I have the right things here. It seems possible from reading around that despite what is set in the info.plist that one can programmatically hide the status bar (time, battery etc).

    I thought someone had already tried this but I couldn't find anything in the forum. Sorry for wasting time if it was already discussed I just couldn't find it.

    I've tried this, doesn't work:

    from objc_util import *
    import ui
    
    #try to get a true full screen without any iOS status bar.
    
    v = ui.View()
    ObjCInstance(v).prefersStatusBarHidden_ = True #likely wrong but i'm not sure...
    v.present(hide_title_bar=True)
    
    shared_application = ObjCClass('UIApplication').sharedApplication()
    shared_application.setStatusBarHidden_ = True
    
    

    posted in Pythonista read more
  • cook

    @JonB thank you! Good to know!

    posted in Pythonista read more
  • cook

    I want to set a color in objc... Not sure what it needs.

    I'm working on UISlider...
    This doesn't work:

    setThumbTintColor_(ui.parse_color('#566565'))

    @omz @jonb

    posted in Pythonista read more
  • cook

    Lol...also he joined at the same time he posted and who joins a forum to find something from 9 months ago and then repost a comment!?

    posted in Pythonista read more
  • cook

    @phuket2 I understand the point you are trying to make. My thoughts are just the same as @jonb has said. If I had a dollar for every time I pushed the 'copy' button on top of the tableview delegates code in the docs.... For now I'll just leave an action. I don't think there's a need for any other callbacks. If there was a delegate I think at most we have four options:

    1. value_did_change_by_sliding
    2. value_did_change_by_typing
    3. label_should_enter_value (return true or false)
    4. slider_should_slide (return true or false)

    But option three and four are also possible to implement just with some keyword args. Option one and two just seem the same overall. I think in the end you just get a bit of overkill implementing a delegate when most likely people just need to get the sender.value which is easier to implement with the action.

    Anyway... I have some thoughts about MVC ... not specific to this but it got me thinking. When I have some time to write them down a bit I'll share with you.

    posted in Pythonista read more
  • cook

    @phuket2 I think just having an action is more in-line with how the ui.Slider() works so it seems more appropriate to me. I don't imagine there's much more that one would want to do and effectively this action does what the delegate was doing.

    (Also... A little less code to implement an action!!)

    posted in Pythonista read more
  • cook

    Thanks @jonb. I've actually removed the delegate bit in favour of setting an action.

    Also updated with a bit more functionality: ability to set style (and other) attributes of the label.

    Next up: min/max value setting and different style of numbers.

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!