omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. cook

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    • Profile
    • Following 0
    • Followers 1
    • Topics 22
    • Posts 161
    • Best 25
    • Controversial 0
    • Groups 0

    cook

    @cook

    42
    Reputation
    5327
    Profile views
    161
    Posts
    1
    Followers
    0
    Following
    Joined Last Online
    Location Japan

    cook Unfollow Follow

    Best posts made by cook

    • [sharing] logging_setup

      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
      cook
      cook
    • [share code] SliderWithLabel class for ui.Slider() featuring editable label

      This is a wrapper for ui.Slider() that shows a label above the slider thumb with the current value (it slides along). Here are some features this provides:

      • The displayed label is editable (it is a textfield) and entering a new number updates the slider position
      • Has a custom value attribute based on a user-set max_val argument.
      • Setting 'max_val' will create a SliderWithLabel.value based on slider.value * max_val. It will return a rounded integer. A normal slider has a value between 0 and 1.0. max_val gives convenience. Default is 100.
      • can set the value for the default display value. Default is 50 (Half)
      • can set the tint_color for the bar. Default is 0.7 so there is no color.
      • set the frame for SliderWithLabel works well.
      • remember that this needs a height of 60!! It's a lot, I know. But don't worry about it!! Make everything else in your view smaller!!
      • changed `delegate is gone in favour of being able to assign an action.
      • added can now style the label with the usual style attributes (background_color etc)

      Code is here

      posted in Pythonista
      cook
      cook
    • RE: [Bug/Missing Feature] Pythonista is missing from AirDrop

      @Webmaster4o I just read this because it was linked from another post.

      I also had the idea that it'd be easy to share.
      It is possible to do... you have to share an url that uses the pythonista url scheme. If you have a script on the receiving device to open you just utilize the sys args.
      When you send an url over airdrop, the receiving device opens it right away (no menu). So... your receiving script can just take the sent script (from sys args) and create a new file, for example.

      posted in Pythonista
      cook
      cook
    • RE: [Share] Position a ui.control in a view

      @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
      cook
      cook
    • RE: Setting Attributes for a Custom View class > best approach?

      Really... Thanks for the input guys... !
      @phuket2 @ccc @dgelessus

      posted in Pythonista
      cook
      cook
    • RE: [Share Code] File Template to automatically add an header comment block

      @lukaskollmer okay thanks. This looks like something I might add a bit later into the game. I guess because I'm not great at coding yet that I often just experiment... Maybe I will just use the same stuff but to prepend it to the current file. (Which...maybe that can be an addition to your script... to use it from the wrench menu for scripts that don't have it yet.)

      posted in Pythonista
      cook
      cook
    • RE: Where do I start with Python/ Pythonista?

      @Zakilas welcome!

      Did you read through the official Python Tutorial? It's on Pythonista. You can access it by swiping left on the main screen, which brings up the console. At the top there is a help icon. In the help screen you will find a lot of documentation and there is one called "Language Tutorial". I suggest reading that through as well. It's not too long. (here it is online)

      My only suggestion though is that I think you can try to read a lot, and that's helpful, but you really ought to just go for it.

      So- think of something you want to do or a problem you want to solve. Code something to do that.

      Start with something on the light side :)

      You also have an incredible community here to ask. So, when you have some questions or problems please ask! I think it's useful to keep things in one thread, and also please provide examples of your problems if you have any - that will help others to help you!

      One of the first things I made with pythonista was a simple script to count money. I need to count money sometimes and I never liked punching so many numbers and trying to remember if I hit the right plus or equals button etc. So it was very simple - using just the console for input (example: how many 10,000yen bills?) and in the end it added everything up and printed the total for me with a summary. Sounds really really simple to me now but at that time it took me a while to figure it out (I knew nothing about python!). Now I would probably do it differently as I've become familiar with making user interfaces etc.

      Anyway... go for it! Do something easy!

      posted in Pythonista
      cook
      cook
    • RE: Deleted row index for ListDataSource

      @phuket2 thanks for the link. I will read up on that later. Looks like a nice article!

      I had no idea about the MVC method, to be honest. I think though that I was wondering about this sort of thing in particular about this project I am doing. Was trying to understand how to lay out everything. I know that I could do everything in a custom view class, but I felt as if that would be too difficult to navigate the code.

      So I split up into a few classes and it seems okay.

      One class is for dealing with the data (mostly SQL management)
      Then I have my UI

      So perhaps I have a sort of MVC thing going on - but my C is mixed in with my V. My UI class has actions that control my data. I don't see a point to make a separate thing just to put those actions, especially when it's just a few lines of code for some.

      Anyway... Will read through the article more. I think it's very helpful to know how to organize your code. I'm able to do that better now that I have a better handle on what's going on. I've learned some nice gymnastics. Might get bronze. Let's see.

      posted in Pythonista
      cook
      cook
    • RE: Deleted row index for ListDataSource

      @brumm @Phuket2 thanks for the reply. I was afraid the only real (built in) way to do it was to construct the data source as @brumm has shown. But, I don't need to have all this extra stuff around... perhaps I'll leave it as is....!

      The other nice thing about the ListDataSource is that you can have multiple lines displayed in the cell (which I want!). It seems we are limited to two lines in tableview_cell_for_row construction.

      So perhaps I will stick with my gymnastics for now. I might need to change it later.... but expect to see me in the Olympics.

      posted in Pythonista
      cook
      cook
    • RE: High school student created apps on the App Store

      @Webmaster4o ask your principal if you can start a club and get a credit?

      posted in Pythonista
      cook
      cook

    Latest posts made by cook

    • RE: [Share] Position a ui.control in a view

      @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
      cook
      cook
    • RE: [Share] Position a ui.control in a view

      @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
      cook
      cook
    • RE: Welcome to the new forum!

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

      posted in Announcements
      cook
      cook
    • RE: Project Distribution (Need Ideas)

      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
      cook
      cook
    • RE: FREE Bible App w/ source code

      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
      cook
      cook
    • RE: History popup [share]

      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
      cook
      cook
    • RE: History popup [share]

      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
      cook
      cook
    • RE: History popup [share]

      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
      cook
      cook
    • RE: [sharing] logging_setup

      @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
      cook
      cook
    • [sharing] logging_setup

      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
      cook
      cook