Debian Codegraph @

fltk/test/log_slider.py

raw symbols SCIP
1 #
2 # "$Id: log_slider.py 1 2025-10-25 21:39:48Z andreasheld $"
3 #
4 # Adjuster test program for pyFLTK the Python bindings
5 # for the Fast Light Tool Kit (FLTK).
6 #
7 # FLTK copyright 1998-1999 by Bill Spitzak and others.
8 # pyFLTK copyright 2003 by Andreas Held and others.
9 #
10 # This library is free software you can redistribute it and/or
11 # modify it under the terms of the GNU Library General Public
12 # License, version 2.0 as published by the Free Software Foundation.
13 #
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Library General Public License for more details.
18 #
19 # You should have received a copy of the GNU Library General Public
20 # License along with this library if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 # USA.
23 #
24 # Please report all bugs and problems to "[email protected]".
25 #
26
27 from fltk import *
28 import math
29
30 try:
31 valuator_format_can_return_buffer = fltk.pyfltk_features['valuator_format_can_return_buffer']
32 except:
33 valuator_format_can_return_buffer = False
34
35 if not valuator_format_can_return_buffer:
36 raise Exception("This version of fltk cannot override Fl_Valuator::format(). You need to upgrade for log-sliders to work")
37
38 si_base_name = {-6: "um",
39 -3: "mm",
40 0: "m",
41 3: "km"}
42
43 class LogSlider(Fl_Value_Slider):
44 def _init__(x, y, w, h, label):
45 Fl_Value_Slider.__init__(x,y,w,h,label)
46
47 def format(self):
48 x = self.value()
49 si_base = math.floor(x/3)*3
50 return f"{10. ** (x - si_base):.0f}\n{si_base_name[si_base]}"
51
52
53 if __name__=='__main__':
54 window = Fl_Window(800, 600, "Log-slider demo")
55 slider = LogSlider(100,100, 600, 100, "Distance")
56 slider.type(FL_HORIZONTAL)
57 slider.bounds(-6, 3) # from 1um to 1km
58 slider.step(1./8.)
59
60 window.end();
61 window.resizable()
62 window.show()
63
64 Fl.run()