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.
Persistent background anim in ui
-
Hi
Using the ui editor I created a custom view - I then create shapes etc that are drawn into that view which I name in the editor as the events custom class.I created elements that sit on top of the bg custom view in ui editor and set the alphas to allow the bg to bleed through..
Not seeing any bg though...how do I animate these lines persistently in the bg constantly changing position etc like a kind of interference effect?
What is the process for layering ui elements on top of each other using alphas and the ui editor?
Should I be using scene view instead for bg anim?
Should the other elements that sit atop bg be subviews of the bg element?
class bgLines(ui.View): def __init__(self): self.w = ui.get_screen_size()[0] self.h = ui.get_screen_size()[1] self.lines=[] for v in range(0,random.randint(10,int(self.h/4))): path = ui.Path.rect(0,0,self.w,1) path.line_width = random.uniform(1,10) self.lines.append(ShapeNode(path,(0.01, random.uniform(0.1,0.4), .01),(0.01, random.uniform(0.1,0.2), .01),shadow=((.82,1,85), 1, 1, 2) )) self.lines[v].position=(self.w/2,random.uniform(0,int(self.h))) self.lines[v].alpha=(random.uniform(0,0.25))```
-
seems to me, if you want to use shapenodes, you ought to be using a sceneview.
-
Well really I just wanna draw some lines in the bg of a simple ui generated with UI editor.
I could generate those lines using scene or ui module.
I want to understand how I can move them using ui if possible and/or how to get them visible under done other buttons and text etc. -
Ok my original post was a bit of a wacky scene/ui mutation - say I have this code below and want it to play in the bg of a UI that I have constructed using UI designer:
class bgLines(ui.View): def __init__(self): self.w = ui.get_screen_size()[0] self.h = ui.get_screen_size()[1] self.lines=[] for v in range(0,random.randint(10,int(self.h/4))): self.lines.append(ui.Path.rect ((self.w/2),random.uniform(0,int(self.h)),self.w,random.uniform(1,10))) ui.set_color('green') self.lines[v].stroke()
How do I layer the UI elements to correctly reveal the bg undearneath?
I have set their alphas to 0.5 but I’m not seeing the bgLines view underneath.
Do I need to subview the elements that are on top to the bgLines view?Any help appreciated
-
https://gist.github.com/94b79fcd4241c518b77a5fcf60db2c89
drawing in ui myst happen inside
draw
. You can "animate" by callingset_needs_display
fromupdate
. Or, if you wanted fixed lines, moving around, you would use animate with position.Ui designer sets a background color by default. Instead, set bg_color=None for your top view, that way, the bgLines view shows through between the ui elements.
-
That’s great thanks for explaining !
Im a little confused about a couple of things:Why do I need to redeclare the bgLines view?
bgv=bgLines(flex='wh') bgv.alpha=.2 bgv.tint_color='red' bgv.update_interval=.1
In my case I have made a pyui file that contains the bgLines custom view but pushed to the back.
So is it necessary to subView the buttons/bgLines ? or. Or is there an arrangement of subviews in the UI editor that would get all this working?
I have it working your way but if I am able to reduce any further editing of views etc outside of the UI designer that would be ideal.If not no probs - just trying to understand the inheritance of the views via the designer.
Ie isn’t the blank canvas of the designer effectively the root ? So if I add a custom view push it to the back and then add a button etc isn’t this the same as :
root.add_subview(bgv) root.add_subview(topview)
Thanks again for your help!
-
you could use the bglines as the root view, true, then add your loaded view as the subview. I redeclared bgLines, because yours wouldn't work (draw inside init instead of draw, and i think you had some errors in your line drawing code-- unless you intended to only use half of the screen). in that cae, just be sure to set your pyui bgcolor to None. Also, be sure that if you use nested Views in tour pyui, that each of those is set to bgcolor=None
-
ahh, yes, you could also use your pyui as root, add the bgv as a subview, and send bgv to back.