[Python-checkins] r64563 - sandbox/trunk/ttk-gsoc/samples/theming.py
guilherme.polo
python-checkins at python.org
Fri Jun 27 19:46:35 CEST 2008
Author: guilherme.polo
Date: Fri Jun 27 19:46:34 2008
New Revision: 64563
Log:
Added factories for notebook, treeview, scrollbar and combobox
Modified:
sandbox/trunk/ttk-gsoc/samples/theming.py
Modified: sandbox/trunk/ttk-gsoc/samples/theming.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/samples/theming.py (original)
+++ sandbox/trunk/ttk-gsoc/samples/theming.py Fri Jun 27 19:46:34 2008
@@ -23,9 +23,12 @@
unwanted_names = ('Style', 'LabeledScale', 'OptionMenu')
# some widgets contain Vertical and Horizontal layouts
special = ('Progressbar', 'Scale', 'Scrollbar')
- sample_text = ('Button', 'Checkbutton', 'Label', 'Radiobutton')
- sample_text_size = ('Labelframe', )
- sample_progress = ('Progressbar', )
+
+ sample = {'Button': widget_text, 'Checkbutton': widget_text,
+ 'Label': widget_text, 'Radiobutton': widget_text,
+ 'Labelframe': widget_text_size, 'Combobox': widget_values,
+ 'Progressbar': widget_progress, 'Notebook': widget_notebook,
+ 'Treeview': widget_treeview, 'Scrollbar': widget_expand}
for name in ttk.__all__:
if name in unwanted_names:
@@ -41,28 +44,25 @@
if name in special:
widget_d['layouts'] = ('Horizontal', 'Vertical')
- if name in sample_text:
- widget_d['factory'] = widget_text
- elif name in sample_text_size:
- widget_d['factory'] = widget_text_size
- elif name in sample_progress:
- widget_d['factory'] = widget_progress
+ if name in sample:
+ widget_d['factory'] = sample[name]
widgets[name] = widget_d
return widgets
-
def widget_text(widget, master, text="Sample", **kw):
"""Instantiate widget and set its text option to a custom value."""
return widget(master, text=text, **kw)
-
def widget_text_size(widget, master, text="Sample", width=150, **kw):
"""Instantiate widget and set its text option to a custom value and
set a size for it."""
return widget(master, text=text, width=width, height=width, **kw)
+def widget_values(widget, master, **kw):
+ """Instantiate widget with some custom values."""
+ return widget(master, values=["Value %d" % i for i in range(5)], **kw)
def widget_progress(widget, master, maximum=10, **kw):
"""Instantiate a progressbar and step it a bit."""
@@ -70,6 +70,32 @@
w.step(4)
return w
+def widget_notebook(widget, master, **kw):
+ """Create a sample notebook with 2 tabs."""
+ w = widget(master, **kw)
+ t1 = ttk.Frame(w, width=150, height=150)
+ t2 = ttk.Frame(w, width=150, height=150)
+ w.add(t1, text="Tab 1")
+ w.add(t2, text="Tab 2")
+ return w
+
+def widget_treeview(widget, master, **kw):
+ """Create a sample treeview with 2 columns and 2 rows."""
+ w = widget(master, columns=[0, 1], **kw)
+ w.column('#0', width=70)
+ for i in range(2):
+ w.column(i, width=40, )
+ w.heading(i, text=i)
+ w.insert('', 'end', text="Row %d" % i, values=[i, i + 1])
+ return w
+
+def widget_expand(widget, master, **kw):
+ """Instantiate widget and configure it to expand."""
+ w = widget(master, **kw)
+ fill = 'x' if 'horizontal' in str(w['orient']) else 'y'
+ w.pack_configure(expand=True, fill=fill)
+ return w
+
class AutoScroll(object):
"""Configure the scrollbars for a widget."""
More information about the Python-checkins
mailing list