From: Kevin A. <al...@se...> - 2001-09-02 22:43:40
|
> From: Ronald D Stephens > > I guess what I have in mind is this. I want to set up a > collection of several sliders, to use as data input devices. Then, I need > to do a calculation on the data, and send the output to a results > slider. In other words, if S1 thorugh S5 are the input sliders, I > need to do something like > > (S1 +5(S2) + 3(S3) -4(S4))/S5 > > and then output the result to an output slider. Okay, this is a very specific problem, which I'll go into below. In general, you'll have to decide whether to use the widgets as data storage or whether they simply represent a 'view' of some internal variables you keep track of yourself. The samples have example of doing both. You want to use the 'value' attribute of the slider. For example, if you have a a slider with a name of 'sld1' then: self.components.sld1.value will give you an integer that you can use in your calculation. Then when you have your calculated value, do something like: def displayResult(self, result): self.components.sldResult.value = int(result) I would wrap up the calculation in its own method (as an example I'll just refer to it as 'calcResult'), which returns your result. You can have the result slider dynamically changed by responding to a 'select' event for all the sliders. def on_sld1_select(self, target, event): result = self.calcResult() self.displayResult(result) You would need a separate handler for each slider, so rather than do that, you could use a background handler. I remember you asking about background handlers before. Your background has a name, I'll assume it is 'bgMin' like the 'minimal.py' sample and that sliders one through five are named like the one above. def on_bgMin_select(self, target, event): name = target.name if name[:3] == 'sld' and int(name[3:]) in [1,2,3,4,5]: self.displayResult(self.calcResult()) There are other ways to solve your problem, but something like that should work. Your result slider will change dynamically as you drag sliders one through five. You'll want to initialize all your sliders with appropriate min/mix values, but you can change these dynamically while the program is running by setting the 'min' and 'max' attributes or using the 'setRange(min, max) method. If you later decide that you also want to display the results and inputs numerically as well as via a slider you can add StaticText or TextField (with 'editable' = 0) widgets that are updated as the slider values change. ka |