--- a/Pmw/Pmw_2_1_1/doc/example.orig.py 2022-06-23 16:54:50.004934300 +0200
+++ b/Pmw/Pmw_2_1_1/doc/example.py 2023-01-11 21:14:32.093645279 +0100
@@ -1,79 +1,81 @@
-import tkinter
+import tkinter
import Pmw
-
+
+
class ThresholdScale(Pmw.MegaWidget):
""" Megawidget containing a scale and an indicator.
"""
-
- def __init__(self, parent = None, **kw):
+
+ def __init__(self, parent=None, **kw):
# Define the megawidget options.
optiondefs = (
- ('colors', ('green', 'red'), None),
- ('threshold', 50, None),
- ('value', None, Pmw.INITOPT),
+ ('colors', ('green', 'red'), None),
+ ('threshold', 50, None),
+ ('value', None, Pmw.INITOPT),
)
self.defineoptions(kw, optiondefs)
-
+
# Initialise base class (after defining options).
Pmw.MegaWidget.__init__(self, parent)
-
+
# Create the components.
interior = self.interior()
-
+
# Create the indicator component.
self.indicator = self.createcomponent('indicator',
- (), None,
- tkinter.Frame, interior,
- width = 16,
- height = 16,
- borderwidth = 2,
- relief = 'raised')
+ (), None,
+ tkinter.Frame, interior,
+ width=16,
+ height=16,
+ borderwidth=2,
+ relief='raised')
self.indicator.grid()
-
+
# Create the scale component.
self.scale = self.createcomponent('scale',
- (), None,
- tkinter.Scale, interior,
- command = self._doCommand,
- tickinterval = 20,
- length = 200,
- from_ = 100,
- to = 0,
- showvalue = 0)
+ (), None,
+ tkinter.Scale, interior,
+ command=self._doCommand,
+ tickinterval=20,
+ length=200,
+ from_=100,
+ to=0,
+ showvalue=0)
self.scale.grid()
-
+
value = self['value']
if value is not None:
self.scale.set(value)
-
+
# Check keywords and initialise options.
self.initialiseoptions()
def _doCommand(self, valueStr):
- if self.scale.get() > self['threshold']:
- color = self['colors'][1]
- else:
- color = self['colors'][0]
- self.indicator.configure(background = color)
+ if self.scale.get() > self['threshold']:
+ color = self['colors'][1]
+ else:
+ color = self['colors'][0]
+ self.indicator.configure(background=color)
+
Pmw.forwardmethods(ThresholdScale, tkinter.Scale, 'scale')
-
+
# Initialise tkinter and Pmw.
root = Pmw.initialise()
root.title('Pmw ThresholdScale demonstration')
# Create and pack two ThresholdScale megawidgets.
mega1 = ThresholdScale()
-mega1.pack(side = 'left', padx = 10, pady = 10)
+mega1.pack(side='left', padx=10, pady=10)
mega2 = ThresholdScale(
- colors = ('green', 'yellow'),
- threshold = 75,
- value = 80,
- indicator_width = 32,
- scale_width = 25)
-mega2.pack(side = 'left', padx = 10, pady = 10)
+ colors=('green', 'yellow'),
+ threshold=75,
+ value=80,
+ indicator_width=32,
+ scale_width=25)
+mega2.pack(side='left', padx=10, pady=10)
# Let's go.
root.mainloop()
--- a/Pmw/Pmw_2_1_1/doc/exercises.orig.py 2022-06-23 16:54:50.004934300 +0200
+++ b/Pmw/Pmw_2_1_1/doc/exercises.py 2023-01-11 21:15:20.873804924 +0100
@@ -1,123 +1,125 @@
-import tkinter
+import tkinter
import Pmw
-
+
+
class ThresholdScale(Pmw.MegaWidget):
""" Megawidget containing a scale and an indicator.
"""
-
- def __init__(self, parent = None, **kw):
+
+ def __init__(self, parent=None, **kw):
# Define the megawidget options.
optiondefs = (
- ('colors', ('green', 'red'), None),
- ('orient', 'vertical', Pmw.INITOPT),
- ('labelmargin', 0, Pmw.INITOPT),
- ('labelpos', None, Pmw.INITOPT),
- ('threshold', (50,), None),
- ('value', None, Pmw.INITOPT),
+ ('colors', ('green', 'red'), None),
+ ('orient', 'vertical', Pmw.INITOPT),
+ ('labelmargin', 0, Pmw.INITOPT),
+ ('labelpos', None, Pmw.INITOPT),
+ ('threshold', (50,), None),
+ ('value', None, Pmw.INITOPT),
)
self.defineoptions(kw, optiondefs)
-
+
# Initialise base class (after defining options).
Pmw.MegaWidget.__init__(self, parent)
-
+
# Create the components.
interior = self.interior()
-
+
# Create the indicator component.
self.indicator = self.createcomponent('indicator',
- (), None,
- tkinter.Frame, interior,
- width = 16,
- height = 16,
- borderwidth = 2,
- relief = 'raised')
-
+ (), None,
+ tkinter.Frame, interior,
+ width=16,
+ height=16,
+ borderwidth=2,
+ relief='raised')
+
# Create the value component.
self.value = self.createcomponent('value',
- (), None,
- tkinter.Label, interior,
- width = 3)
-
+ (), None,
+ tkinter.Label, interior,
+ width=3)
+
# Create the scale component.
- if self['orient'] == 'vertical':
- # The default scale range seems to be
- # the wrong way around - reverse it.
- from_ = 100
- to = 0
- else:
- from_ = 0
- to = 100
+ if self['orient'] == 'vertical':
+ # The default scale range seems to be
+ # the wrong way around - reverse it.
+ from_ = 100
+ to = 0
+ else:
+ from_ = 0
+ to = 100
self.scale = self.createcomponent('scale',
- (), None,
- tkinter.Scale, interior,
- orient = self['orient'],
- command = self._doCommand,
- tickinterval = 20,
- length = 200,
- from_ = from_,
- to = to,
- showvalue = 0)
-
+ (), None,
+ tkinter.Scale, interior,
+ orient=self['orient'],
+ command=self._doCommand,
+ tickinterval=20,
+ length=200,
+ from_=from_,
+ to=to,
+ showvalue=0)
+
value = self['value']
if value is not None:
self.scale.set(value)
-
- # Use grid to position all components
- if self['orient'] == 'vertical':
- self.indicator.grid(row = 1, column = 1)
- self.value.grid(row = 2, column = 1)
- self.scale.grid(row = 3, column = 1)
- # Create the label.
- self.createlabel(interior, childRows=3)
- else:
- self.indicator.grid(row = 1, column = 1)
- self.value.grid(row = 1, column = 2)
- self.scale.grid(row = 1, column = 3)
- # Create the label.
- self.createlabel(interior, childCols=3)
+
+ # Use grid to position all components
+ if self['orient'] == 'vertical':
+ self.indicator.grid(row=1, column=1)
+ self.value.grid(row=2, column=1)
+ self.scale.grid(row=3, column=1)
+ # Create the label.
+ self.createlabel(interior, childRows=3)
+ else:
+ self.indicator.grid(row=1, column=1)
+ self.value.grid(row=1, column=2)
+ self.scale.grid(row=1, column=3)
+ # Create the label.
+ self.createlabel(interior, childCols=3)
# Check keywords and initialise options.
self.initialiseoptions()
def _doCommand(self, valueStr):
- valueInt = self.scale.get()
- colors = self['colors']
- thresholds = self['threshold']
- color = colors[-1]
- for index in range(len(colors) - 1):
- if valueInt <= thresholds[index]:
- color = colors[index]
- break
- self.indicator.configure(background = color)
- self.value.configure(text = valueStr)
+ valueInt = self.scale.get()
+ colors = self['colors']
+ thresholds = self['threshold']
+ color = colors[-1]
+ for index in range(len(colors) - 1):
+ if valueInt <= thresholds[index]:
+ color = colors[index]
+ break
+ self.indicator.configure(background=color)
+ self.value.configure(text=valueStr)
+
Pmw.forwardmethods(ThresholdScale, tkinter.Scale, 'scale')
-
+
# Initialise tkinter and Pmw.
root = Pmw.initialise()
root.title('Pmw ThresholdScale demonstration')
# Create and pack two ThresholdScale megawidgets.
-mega1 = ThresholdScale(scale_showvalue = 1)
-mega1.pack(side = 'left', padx = 10, pady = 10)
+mega1 = ThresholdScale(scale_showvalue=1)
+mega1.pack(side='left', padx=10, pady=10)
mega2 = ThresholdScale(
- colors = ('green', 'yellow', 'red'),
- threshold = (50, 75),
- value = 80,
- indicator_width = 32,
- scale_width = 25)
-mega2.pack(side = 'left', padx = 10, pady = 10)
+ colors=('green', 'yellow', 'red'),
+ threshold=(50, 75),
+ value=80,
+ indicator_width=32,
+ scale_width=25)
+mega2.pack(side='left', padx=10, pady=10)
# Create and pack two horizontal ThresholdScale megawidgets.
mega3 = ThresholdScale(
- orient = 'horizontal',
- labelpos = 'n',
- label_text = 'Horizontal')
-mega3.pack(side = 'top', padx = 10, pady = 10)
-mega4 = ThresholdScale(orient = 'horizontal')
-mega4.pack(side = 'top', padx = 10, pady = 10)
+ orient='horizontal',
+ labelpos='n',
+ label_text='Horizontal')
+mega3.pack(side='top', padx=10, pady=10)
+mega4 = ThresholdScale(orient='horizontal')
+mega4.pack(side='top', padx=10, pady=10)
# Let's go.
root.mainloop()