-
rewire88
When I said I moved the black oval I meant I moved it's location on the screen to test this front back thing - I left the code in the init. Unclear language on my part.
Thanks for your help. I'm slowly getting a better understanding of views and images.
-
rewire88
Thanks, this is basically what I was looking for. I'll have to study the context stuff to understand what it's doing.
I still have a problem with having this in the 'background' though. I moved the static black oval to the same position as the slider controlled orange oval, and the black oval is always in front. I tried adding 'bring_to_front' and 'send_to_back' a few different places for the u and iv images, but no luck. What am I missing?
-
rewire88
I've been working on this and I have basically what I wanted with the graphs and controls. There are still some fundamental things I don't understand though with how 'View' works.
My graph has axes and labels that indicate frequency and dB level. It seems inefficient to draw these static elements each time when they don't change at all. I tried a few things, but found out I need to put statements in the draw() method to get them to work. I'm not sure why this is. Is this just the way it works and all 'static' graphics like this are always part of the draw() everytime? Is there a better standard practice approach to this type of problem?
Here's a simplified example, using the previous code from this thread, showing my ignorance. The black oval would be analogous to the graph axes and labels that aren't changing.
import ui class testClass(ui.View): def __init__(self): self.height,self.width=400,400 self.background_color='white' self.slider=ui.Slider() self.slider.center=(200,200) self.slider.action=self.ss_slide self.add_subview(self.slider) path2=ui.Path.oval(300,100,75,30) ui.set_color('black') path2.fill() # wondering why this doesn't get drawn def draw(self): path=ui.Path.oval(100,100,75,30*self.slider.value) ui.set_color('orange') path.fill() def ss_slide(self,sender): self.set_needs_display() u=testClass() u.present('sheet')
-
rewire88
Thanks, very helpful. I was sure global variables weren't the right way to go but didn't know how to do it correctly.
I still have all sorts of questions and things to explore. My biggest puzzle is how to organize things. I'm going to have multiple controls. Probably 5 sliders controlling different different gain/frequency graphs. (Set Left channel gains, flip switch and use same sliders to set Right channel gains, etc.) Then a bunch of simple selectors for things like noise reduction ON/OFF. I'll probably make a rough draft with everything in one big class to get it to work then refactor.
-
rewire88
Scaling and figuring out coordinates isn't the problem at all, but it's my lack of basic Python knowledge about classes, inheritance, etc. I'm just trying to start with something simple - move a slider up and down and have a shape on the screen follow along.
After your hint I'm able to move an oval up and down. Very crude but it's a start.
import ui import math ss=100 class testDrawClass(ui.View): def __init__(self): self.height, self.width=400,400 self.background_color='white' def draw(self): global ss path = ui.Path.oval(100,ss,75,30) ui.set_color('red') path.fill() def ss_slide(self,sender): global ss ss=(400*sender.value) ss=math.floor(ss) print("ss:",ss) self.set_needs_display() u = testDrawClass() slider = ui.Slider() slider.action=u.ss_slide slider.center=(200,200) u.add_subview(slider) u.present('sheet')
-
rewire88
Great, that's what I was looking for - just needed a foothold. Thanks!
-
rewire88
New to Pythonista and I'm trying to make a script with a bank of sliders that control gains on a separate plot (gain vs. frequency). I've played around with 'ui' and I've got basic controls to work, but I'm lost as far as adding a plot to the ui. The plot should change in real time as the sliders are adjusted, like a graphic EQ in audio.
Is this possible? Can someone point me to the general method I need to use, which modules I need to study, etc.