summaryrefslogtreecommitdiffstats
path: root/Tools/pynche/ChipViewer.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1998-01-29 23:48:55 (GMT)
committerBarry Warsaw <barry@python.org>1998-01-29 23:48:55 (GMT)
commit7080a7f69e52f54a1d0386bf05494e83eeace568 (patch)
tree4fa309c265bdf9d280f265a70661901396a9b1c8 /Tools/pynche/ChipViewer.py
parentc45c2f3dc1a2cca5f0254a0ef34f7bc16d1bfbf1 (diff)
downloadcpython-7080a7f69e52f54a1d0386bf05494e83eeace568.zip
cpython-7080a7f69e52f54a1d0386bf05494e83eeace568.tar.gz
cpython-7080a7f69e52f54a1d0386bf05494e83eeace568.tar.bz2
Initial revision
Diffstat (limited to 'Tools/pynche/ChipViewer.py')
-rw-r--r--Tools/pynche/ChipViewer.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/Tools/pynche/ChipViewer.py b/Tools/pynche/ChipViewer.py
new file mode 100644
index 0000000..e173a62
--- /dev/null
+++ b/Tools/pynche/ChipViewer.py
@@ -0,0 +1,71 @@
+from Tkinter import *
+import Pmw
+
+class ChipWidget(Pmw.MegaWidget):
+ _WIDTH = 80
+ _HEIGHT = 100
+
+ def __init__(self, parent=None, **kw):
+ optionsdefs = (('chipcolor', 'blue', self.__set_color),
+ ('width', self._WIDTH, self.__set_dims),
+ ('height', self._HEIGHT, self.__set_dims),
+ ('text', 'Color', self.__set_label),
+ )
+ self.defineoptions(kw, optionsdefs)
+
+ # initialize base class -- after defining options
+ Pmw.MegaWidget.__init__(self, parent)
+ interiorarg = (self.interior(),)
+
+ # create the label
+ self.__label = self.createcomponent(
+ # component name, aliases, group
+ 'label', (), None,
+ # widget class, widget args
+ Label, interiorarg)
+ self.__label.grid(row=0, column=0)
+
+ # create the color chip
+ self.__chip = self.createcomponent(
+ 'chip', (), None,
+ Frame, interiorarg,
+ relief=RAISED, borderwidth=2)
+ self.__chip.grid(row=1, column=0)
+
+ # create the color name
+ self.__name = self.createcomponent(
+ 'name', (), None,
+ Label, interiorarg,)
+ self.__name.grid(row=2, column=0)
+
+ # Check keywords and initialize options
+ self.initialiseoptions(ChipWidget)
+
+ # called whenever `chipcolor' option is set
+ def __set_color(self):
+ color = self['chipcolor']
+ self.__chip['background'] = color
+ self.__name['text'] = color
+
+ def __set_dims(self):
+ width = self['width']
+ height = self['height']
+ self.__chip.configure(width=width, height=height)
+
+ def __set_label(self):
+ self.__label['text'] = self['text']
+
+Pmw.forwardmethods(ChipWidget, Frame, '__chip')
+
+
+
+if __name__ == '__main__':
+ root = Pmw.initialise(fontScheme='pmw1')
+ root.title('ChipWidget demonstration')
+
+ exitbtn = Button(root, text='Exit', command=root.destroy)
+ exitbtn.pack(side=BOTTOM)
+ widget = ChipWidget(root, chipcolor='red', width=200,
+ text='Selected Color')
+ widget.pack()
+ root.mainloop()