[Python-checkins] r64657 - sandbox/trunk/ttk-gsoc/samples/theming.py
guilherme.polo
python-checkins at python.org
Wed Jul 2 15:10:54 CEST 2008
Author: guilherme.polo
Date: Wed Jul 2 15:10:53 2008
New Revision: 64657
Log:
Renamed _current_options to _custom_options as it only stores custom options
per widget now.
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 Wed Jul 2 15:10:53 2008
@@ -16,7 +16,7 @@
import cStringIO
import Tkinter
from tkSimpleDialog import Dialog, askstring
-from tkMessageBox import showwarning
+from tkMessageBox import showwarning, showerror
from tkFileDialog import askopenfilename
def map_widgets():
@@ -95,10 +95,8 @@
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")
+ w.add(ttk.Frame(w, width=150, height=150), text="Tab 1")
+ w.add(ttk.Frame(w, width=150, height=150), text="Tab 2")
return w
def widget_treeview(widget, master, **kw):
@@ -106,7 +104,7 @@
w = widget(master, columns=[0, 1], **kw)
w.column('#0', width=70)
for i in range(2):
- w.column(i, width=40, )
+ w.column(i, width=40)
w.heading(i, text=i)
w.insert('', 'end', text="Row %d" % i, values=[i, i + 1])
return w
@@ -120,11 +118,9 @@
def widget_paned(widget, master, **kw):
"""Create a sample Panedwindow with two children."""
- w = widget(master, height=150, **kw)
- c1 = ttk.Label(w, text="Top")
- c2 = ttk.Label(w, text="Bottom")
- w.add(c1)
- w.add(c2)
+ w = widget(master, height=150, orient='vertical', **kw)
+ w.add(ttk.Label(w, text="Top"))
+ w.add(ttk.Label(w, text="Bottom"))
return w
def widget_expand(widget, master, **kw):
@@ -303,7 +299,7 @@
else:
self.result = Tkinter.PhotoImage(name=img_name, file=img_path)
except Tkinter.TclError, err:
- showwarning("Error creating image", err, parent=self)
+ showerror("Error creating image", err, parent=self)
return False
return True
@@ -380,13 +376,13 @@
if not isinstance(values['opts'], dict):
raise ValueError
except (NameError, SyntaxError), err:
- showwarning("Invalid options specification",
+ showerror("Invalid options specification",
"Options should be formatted according to a dict.\n\n"
"Error: %s" % err,
parent=self)
return False
except ValueError:
- showwarning("Invalid options specification",
+ showerror("Invalid options specification",
"Options should be formatted according to a dict.",
parent=self)
return False
@@ -403,14 +399,14 @@
self.master = frame.master
width = 640
- height = width - 50#int(width * 3 / 4)
+ height = width - 50
self.master.geometry('%dx%d' % (width, height))
self.master.minsize(width, height)
self.master.title(title)
self._style = ttk.Style(self.master)
self._current_widget = {'layout': None, 'widget': None}
- self._current_options = None
+ self._custom_options = {} # custom options per widget
self.__create_menu()
self.__setup_widgets()
@@ -437,7 +433,7 @@
widget_style = "Custom.%s" % widget_name
widget_name = treeview.item(treeview.parent(sel))['text']
else:
- self._empty_layout_text()
+ self._empty_layout()
widget = self._widget[widget_name]
widget_style = widget_style or widget['class']
@@ -473,12 +469,13 @@
self._widget[name]['tv_item'] != selection)
def _remove_previous_widgets(self):
- """Remove widgets from the style frames."""
- self._current_options = self._current_options or []
- # remove previous widgets
- for widget in self._current_options:
+ """Remove labels and entries from the style frames."""
+ widgets = self._configframe.pack_slaves() + self._mapframe.pack_slaves()
+
+ for widget in widgets:
+ if widget.winfo_class() == 'TButton':
+ continue
widget.pack_forget()
- self._current_options = []
def _update_style_configframe(self):
"""Update the configure frame for the current widget."""
@@ -522,21 +519,18 @@
entry.validate()
entry.pack(side='top', fill='x', pady=3)
- self._current_options = self._current_options or []
- self._current_options.extend([lbl, entry])
-
def _update_layout_text(self, layout_name):
"""Update the layout text for the current widget."""
output = cStringIO.StringIO()
pprint.pprint(self._style.layout(layout_name), stream=output)
layout = output.getvalue()
output.close()
- self._empty_layout_text()
+ self._empty_layout()
self.layouttext.layout = layout_name
self.layouttext.insert('1.0', layout) # set new text
- def _empty_layout_text(self):
- """Clear current text in the layout text widget."""
+ def _empty_layout(self):
+ """Clear current text in the layout text widget and unset layout."""
self.layouttext.delete('1.0', 'end')
self.layouttext.layout = None
@@ -547,7 +541,7 @@
return
text = self.layouttext.get('1.0', 'end')
- if not text.strip(): # no text
+ if not text.strip(): # no layout
return
# XXX Warning: eval usage!
self._style.layout(layout, eval(text))
@@ -563,7 +557,7 @@
def _ask_new_frame_opt(self, frame, func):
"""Open a dialog asking for a new option to be added in the
- specified frame."""
+ specified frame and then add it."""
widget = self._current_widget
if widget['widget'] is None:
showwarning("No widget active",
@@ -575,10 +569,16 @@
dlg = NewOption(self.master)
if dlg.result is not None:
option, value = dlg.result
+
+ if layout_name not in self._custom_options:
+ self._custom_options[layout_name] = []
+
+ self._custom_options[layout_name].append(option)
self._add_opt_frame(frame, func, layout_name, option, value)
def _ask_new_element(self, frame):
- """Open a dialog for getting data for a new style element."""
+ """Open a dialog for getting data for a new style element and then
+ create it."""
dlg = NewElement(self.master, imglist=self._imagelist)
if dlg.result:
name = dlg.result['elementname']
@@ -598,7 +598,7 @@
self._style.element_create(name, dlg.result['etype'], *args,
**dlg.result['opts'])
except Tkinter.TclError, err:
- showwarning("Element couldn't be created",
+ showerror("Element couldn't be created",
"The specified element couldn'be created, reason: "
"\n%s" % err, parent=self.master)
else:
More information about the Python-checkins
mailing list