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.
Encapsulating PYUI files into PY files
-
I do all my Pythonista hacking with the onscreen keyboard and I am quite happy with that but I certainly understand that others prefer an external keyboard.
I wrote my first code in the 1970's and yet I still feel like I am just poking in the dark. However, collaborative coding is all the rage these daze for good reason. We learn faster by working with other folks on code.
One more snippet for you to consider...
pyui_variable.py
This code will create, use, and automatically delete a temporary file.A great place for learning the Standard Library is the Python Module of the Week website and associated book.
-
I'd gladly help you with your code. I need something more productive to do with my programming skills. I'm right now caught up in an OS X app that converts images to ASCII art, so yeah, really productive and useful. It'll revolutionize the ASCII art industry. ;-)
Anyway, PLEASE post your code on GitHub! I insist that you let me help out. :-)
-
@Gerzer, really, thanks for the offer. I have no code to speak of. I have just been trying snippets here and there from time to time. I am still trying to revolutionise the UI world :) it's very hard to improve on what omz has already done. I find myself doing some helper functions/ classes for a few days only to come to the realisation, practically would not help much at all, or worse still more burdensome to use.
I think I have come up with an abstraction, that maybe useful, but it remains to been seen. It's a view layout manager class. So you can for example add a title bar, a bottom bar, a left and right bar or full content bar. The idea these views, self resize, position , handle orientation etc. with help from flex of course. Looking at most iPad apps, made up of these basic elements arranged in different configs. Anyway, early days on that one. May also turn out to be a dud, but fun trying.But I will be out action for the next 10 days for the most part. Friends arriving later today, they will be here for close to 10 days. So I will have little time to do anything during this time.
Would be happy to look at your ASCII art app if you want some feedback. I have a Mac Pro, late 2013 model I think. Not that I am a art guy. But come across some of these apps when I was looking at the python module for creating ascii banners in the console. Would be a nice addition to Pythonistia I think just to spruce up some console apps.But look thanks again, below is the last lame attempt I had with trying to pass a memory file to ui.load_view(). It's a mess because I was trying different things without knowing what I was doing. Just poking in the dark :)
import StringIO import ui, json _aview = [{u'attributes': {u'custom_class': u'main', u'flex': u'', u'name': u'Main', u'border_color': u'RGBA(0.000000,0.000000,0.000000,1.000000)', u'enabled': True, u'tint_color': u'RGBA(0.000000,0.478000,1.000000,1.000000)', u'background_color': u'RGBA(1.000000,1.000000,1.000000,1.000000)'}, u'frame': u'{{0, 0}, {320, 504}}', u'nodes': [{u'attributes': {u'flex': u'', u'name': u'switch1', u'border_color': u'RGBA(0.000000,0.000000,0.000000,1.000000)', u'enabled': True, u'value': True, u'uuid': u'E3628BC2-CB40-43BE-A68E-DFDFE587E315'}, u'frame': u'{{238.5, 19.5}, {51, 31}}', u'nodes': [], u'class': u'Switch'}, {u'attributes': {u'flex': u'', u'font_bold': False, u'font_size': 15, u'uuid': u'62C7DAF4-12CF-4FF6-9EAA-8B443398D3BD', u'title': u'Ok', u'border_color': u'RGBA(0.000000,0.000000,0.000000,1.000000)', u'enabled': True, u'action': u'hit_test', u'name': u'button1'}, u'frame': u'{{224, 455.5}, {80, 32}}', u'nodes': [], u'class': u'Button'}, {u'attributes': {u'flex': u'', u'font_size': 17, u'name': u'label1', u'text': u'Test Label', u'border_color': u'RGBA(0.000000,0.000000,0.000000,1.000000)', u'enabled': True, u'text_color': u'RGBA(0.000000,0.000000,0.000000,1.000000)', u'alignment': u'left', u'uuid': u'6F6DFFF1-495A-4468-A6B1-E7CEC7508E34'}, u'frame': u'{{17.5, 18.5}, {150, 32}}', u'nodes': [], u'class': u'Label'}], u'class': u'View'}] if __name__ == '__main__': fh = StringIO.StringIO() fh.write(_aview) #json.dump(_aview, fh) print fh.buflist v = ui.load_view(fh) v.present() fh.close
-
@ccc, wow. Sounds like you must be older than me. I am 50. I started coding mid 80's. I did most my work in c. I still did HyperCard, SuperCard and later VB. not sure if you ever wrote XCMDs :) all my c work was on Mac's with the 68000 line. So different to python programming :) the thing I remember doing the most was calling hlock(h) so could get to a pointer **h without the memory manager moving the data on me :) but because I sold out and went into management, it's been so many years since I did any commercial programming. Selling out worked out though. Retired very early, and now have time to program for fun a a leisurely pace. Sorry to mix my personal info here, but as there are no profiles, hard to know about people. I think profiles here would be a great addition.
But anyway, thanks for the temp file code. I will save that away. I realise it will be one of those routines you just write off the top of your head, just a lot floating in my head now ;)Also, will look at the website you suggested. When I was younger I would have read and re read the std lib docs. I am enjoying learning by trail abd error at the moment. But if I had to make a living from Python, sure I would take the other approach. When I was a Apple developer, I read most of those menacing white binders, I also attended the WWDC for many years. Back then it was held in San Jose. Also did some disassembly debugging courses at Apple. So I am not shy to learn the hard way, just as I am getting older looking to enjoy it more :)
Again, thanks for your comments. The community here adds to the enjoyment of learning Python.
-
Phuket2, the problem with many of the attempts above is that the parameter that
ui.load_view()
is expecting is a file system path to a pyui file and not a file handle. That is why in my code above, I passed intemp_file.name
instead of justtemp_file
. StringIO and other in-memory files do not have file system paths.The only way around this limitation in the current ui.load_view() method is to create your own replacement function as suggest by JonB above.
-
My age is already
well documented
in the forum. -
@ccc, sorry I was lazy, I just did a Google search or two, I didn't work out your exact age (in code challenge), but pretty close. The day you posted 20,000 days, google reports 54.7582 years. Then days from then until now, was 286 + 16 hours. So you are still 55 and will be 56 in August 22nd. although I am only 50, I have lived 3 life times already ;) the new 56 is the new 30. These young guys can never keep up :)
-
@ccc, on stackflow people have said normally functions that expect a file path would normally deal with a file handle also. I am not sure this is true or not, or if iOS is challenging in this regard. But I understand the temp file concept, I just don't like it. Again, I know it's not life changing, just digging into things. It's a bit of a tangent, but still helps me to learn
-
that is sometimes true, and often a good design, but requires coding it that way specifically. unless the documentation specifically mention that feature, you shouldn't assume it. the tempfile approach is nice in that it will automatically clean up after itself. however the NamedTemporaryFile approach doesn't work on windows, since you can't reopen an open file, so you have to manually delete it.
-
@JonB, thanks. I thought as much regarding the file handles and paths, however I would also have not been surprised if Python had yet another super cool trick up its sleeve.
Regarding feature requests for Pythonistia , is there any managed table of requests that omz looks at? As far as I can see, it appears, people make the requests here in the forum. I don't want to that at the moment, given the work being done on 1.6. I am sure he doesn't need the distraction.