Presenting view and console
that update_interval looks much cleaner :) but I don't have access to the beta, didn't know there was one.
on the other hand I needed the full console because I don't have the screen real-estate for an in-view text box - and then there's the amount of logs I go through when I do check the console…
hiding the view temporarily to check the logs was just what I was looking for :)
Phuket2 last edited by
@KalyJupiter , ok, I understand. Was not sure of your complete requirements. Sometimes bare bones examples can be misleading, because the implementation can get more complex. Here is a gist That shows the same example, just with the beta in mind. Forget the button code. I just have that as a snippet. So easy for me to use in examples.
Your approach seems fine, but you need to find an elegant solution to exit your loop. The small problem is that ui.ButtonItem is slightly different than other ui elements.
Ui.ButtonItem is not subclassed from ui.View like most of the ui elements. The below snippet shows they are different. So for example, uiButtonItem does not have an on_screen attr.
If you search the forum, you will find the beta sign up form. I have no idea before the beta will make it to the App Store version. I have a feeling it wont be too long, but i am just guessing.
import ui print("ui.ButtonItem") print(dir(ui.ButtonItem())) print("\n\nui.Button") print(dir(ui.Button()))
cheers, I found the beta signup form :)
and I'm not worried about exiting the loop
Hmm, for some reason I thought the console is only shown the first time a particular script prints to it... but maybe I am mistaken.
If you are doing lots of back and forth between console and ui, you might also consider an Overlay. This woeks similar to a popover, but does not disappear when you interact with the console, and can be dragged around, minimized, etc. You can also have multiple Overlays active at the same time.
That Overlay class is quite nice :) I'll keep it around for later, but it does have some quirks:
for one, the below crashes when trying to set the .text:
if __name__=='__main__': view = ui.View() view.frame = (0, 0, 240, 240) view.flex = 'WH' view.background_color = 'white' valuefield = ui.TextField() valuefield.frame = (120, 34, 120, 34) valuefield.text = "ana" # ⇒ crashes Pythonista view.add_subview(valuefield) o=Overlay(content=view,parent=AppWindows.root())
Hmm, I couldn't reproduce the crash, though to get to run I had to add
nameto view (something I should fix), and also enabled touch so the textfield is active.
Can you enable the faulthandler (see @dgelessus's pythonista_startup repo) and let me know exactly what is crashing?
from overlay import Overlay,AppWindows import ui if __name__=='__main__': view = ui.View(name='hello') view.frame = (0, 0, 240, 240) view.flex = 'WH' view.background_color = 'white' valuefield = ui.TextField() valuefield.frame = (120, 34, 120, 34) valuefield.text = "ana" # ⇒ crashes Pythonista view.add_subview(valuefield) o=Overlay(content=view,parent=AppWindows.root()) o.content_view.touch_enabled=True
Fatal Python error: Aborted Current thread 0x000000016e117000 (most recent call first): ------------------------------------------------------------------------ Objective-C exception details: NSInternalInconsistencyException: Only run on the main thread! Stack trace: 0 CoreFoundation 0x000000018316fd50 <redacted> + 148 1 libobjc.A.dylib 0x0000000182684528 objc_exception_throw + 56 2 CoreFoundation 0x000000018316fc0c <redacted> + 0 3 Foundation 0x0000000183afec90 <redacted> + 88 4 UIFoundation 0x000000018d64a70c <redacted> + 1008 5 UIFoundation 0x000000018d64a194 <redacted> + 1672 6 UIFoundation 0x000000018d656de8 <redacted> + 168 7 UIFoundation 0x000000018d647494 <redacted> + 4628 8 UIFoundation 0x000000018d647f30 <redacted> + 196 9 UIFoundation 0x000000018d648640 <redacted> + 340 10 UIFoundation 0x000000018d6513b0 <redacted> + 2180 11 UIFoundation 0x000000018d67aed0 <redacted> + 332 12 UIFoundation 0x000000018d6a0528 <redacted> + 160 13 UIKit 0x000000018d1cd658 <redacted> + 524 14 UIKit 0x000000018c5c4eac <redacted> + 248 15 UIKit 0x000000018c57c000 <redacted> + 1256 16 QuartzCore 0x000000018714d0b4 <redacted> + 184 17 QuartzCore 0x0000000187151194 <redacted> + 332 18 QuartzCore 0x00000001870bff24 <redacted> + 336 19 QuartzCore 0x00000001870e6340 <redacted> + 540 20 QuartzCore 0x00000001870e7180 <redacted> + 92 21 CoreFoundation 0x00000001831178b8 <redacted> + 32 22 CoreFoundation 0x0000000183115270 <redacted> + 412 23 CoreFoundation 0x00000001830362f8 CFRunLoopRunSpecific + 468 24 Foundation 0x0000000183a5e6e4 <redacted> + 304 25 Foundation 0x0000000183a7dafc <redacted> + 96 26 Py3Kit 0x0000000102687508 -[PYK3Interpreter setupInterpreterThreadRunLoop] + 252 27 Foundation 0x0000000183b5f860 <redacted> + 996 28 libsystem_pthread.dylib 0x0000000182d9c32c <redacted> + 308 29 libsystem_pthread.dylib 0x0000000182d9c1f8 <redacted> + 0 30 libsystem_pthread.dylib 0x0000000182d9ac38 thread_start + 4 End of exception details.
mmkay, looks like we need a
@on_main_threadsomeplace. Could you try adding this in front of the init method of Overlay?
yep, that worked :D I put it on attach
@on_main_thread def attach(self):
now that Overlay is awesome for a quick settings screen :)
struct_engineer last edited by struct_engineer
My first post to the forum.
Using the Overlay class successfully — added the decorator to the attach function as was mentioned.
@on_main_thread def attach(self): self.parent.addSubview_(self)
In my demo file, I have a main image overlay (resizable) and two auxilary image overlays (resizable). Each of the overlays could have any kind of UI elements; just showing images for proof of concept.
I have found that, for each overlay, the following statements must be in the order shown or else the overlay window will not resize.
ooo=Overlay(name='abc', content=vvv, parent=AppWindows.root()) ooo.content_view.border_width=2 vvv.content_mode=ui.CONTENT_SCALE_ASPECT_FIT
Here is my demo file; provide your own PNG files (foo.png and fooe.png).
from overlay import Overlay, AppWindows from gestures import Gestures import ui if __name__=='__main__': iv0=ui.ImageView(frame=(0,0,300,300)) iv0.image=ui.Image.named('test:Peppers') iv0.name='OMAIN▪️' iv1=ui.ImageView(frame=(0,0,200,200)) iv1.image=ui.Image.named('foo.png') iv1.name='ICR▪️' iv1.alpha=1 overlay1=Overlay(content=iv1,parent=AppWindows.root()) overlay1.content_view.border_width=2 iv1.border_width=1 iv1.content_mode=ui.CONTENT_SCALE_ASPECT_FIT iv2=ui.ImageView(frame=(0,0,200,200)) iv2.image=ui.Image.named('fooe.png') iv2.name='E▪️' iv2.alpha=1 overlay2=Overlay(content=iv2,parent=AppWindows.root()) overlay2.content_view.border_width=2 iv2.border_width=1 iv2.content_mode=ui.CONTENT_SCALE_ASPECT_FIT omain=Overlay(name='abc', content=iv0, parent=AppWindows.root()) omain.content_view.border_width=2 iv0.border_width=1 iv0.content_mode=ui.CONTENT_SCALE_ASPECT_FIT
@struct_engr, excellent first post.
struct_engr_ last edited by
Had to register as a new account.
Could not access my old account.
Several recover password attempts did not work.
So my new username is struct_engr_ (added underline character at the end)
@struct_engr_ , did your recover password attempts result in no email arriving, or was there some other issue?
struct_engr_ last edited by
no email arrived ASFAIK
carefully checked spam folder
possible that email hit blacklisted IP addresses
certain IP addresses blocked because of spam