Commit 769e1085 authored by Guido van Rossum's avatar Guido van Rossum

AttrDialog.py: some structural changes

listtree.py: "Print" -> "List" in description
parent 68680039
...@@ -100,18 +100,24 @@ class ReadonlyOption(Option): ...@@ -100,18 +100,24 @@ class ReadonlyOption(Option):
def addoption(self): def addoption(self):
self.label = Label(self.frame, self.label = Label(self.frame,
{'textvariable': self.var, {'textvariable': self.var,
'anchor': 'e',
Pack: {'side': 'right'}}) Pack: {'side': 'right'}})
class Dialog: class Dialog:
def __init__(self, master): def __init__(self, master):
self.master = master self.master = master
self.fixclasses()
self.refresh() self.refresh()
self.top = Toplevel(self.master) self.top = Toplevel(self.master)
self.top.title(self.__class__.__name__) self.top.title(self.__class__.__name__)
self.top.minsize(1, 1) self.top.minsize(1, 1)
self.addchoices() self.addchoices()
def refresh(self): pass # Must override
def fixclasses(self): pass # May override
def addchoices(self): def addchoices(self):
self.choices = {} self.choices = {}
list = [] list = []
...@@ -133,6 +139,11 @@ class Dialog: ...@@ -133,6 +139,11 @@ class Dialog:
cl = self.stringoption cl = self.stringoption
self.choices[k] = cl(self, k) self.choices[k] = cl(self, k)
# Must override:
options = {}
classes = {}
# May override:
booleanoption = BooleanOption booleanoption = BooleanOption
stringoption = StringOption stringoption = StringOption
enumoption = EnumOption enumoption = EnumOption
...@@ -155,7 +166,8 @@ class PackDialog(Dialog): ...@@ -155,7 +166,8 @@ class PackDialog(Dialog):
try: try:
Pack.config(self.dialog.widget, Pack.config(self.dialog.widget,
{self.option: self.current}) {self.option: self.current})
except TclError: except TclError, msg:
print msg
self.refresh() self.refresh()
class booleanoption(packoption, BooleanOption): pass class booleanoption(packoption, BooleanOption): pass
...@@ -211,7 +223,7 @@ class RemotePackDialog(PackDialog): ...@@ -211,7 +223,7 @@ class RemotePackDialog(PackDialog):
'newinfo', 'newinfo',
self.widget)) self.widget))
except TclError, msg: except TclError, msg:
print 'send pack newinfo', self.widget, ':', msg print msg
return return
dict = {} dict = {}
for i in range(0, len(words), 2): for i in range(0, len(words), 2):
...@@ -231,10 +243,14 @@ class RemotePackDialog(PackDialog): ...@@ -231,10 +243,14 @@ class RemotePackDialog(PackDialog):
try: try:
self.dialog.master.send( self.dialog.master.send(
self.dialog.app, self.dialog.app,
'pack', 'config', self.dialog.widget, 'pack',
'-'+self.option, self.current) 'config',
self.dialog.widget,
'-'+self.option,
self.dialog.master.tk.merge(
self.current))
except TclError, msg: except TclError, msg:
print 'send pack config ... :', msg print msg
self.refresh() self.refresh()
class booleanoption(remotepackoption, BooleanOption): pass class booleanoption(remotepackoption, BooleanOption): pass
...@@ -246,14 +262,17 @@ class WidgetDialog(Dialog): ...@@ -246,14 +262,17 @@ class WidgetDialog(Dialog):
def __init__(self, widget): def __init__(self, widget):
self.widget = widget self.widget = widget
if self.addclasses.has_key(self.widget.widgetName): self.klass = widget.winfo_class()
Dialog.__init__(self, widget)
def fixclasses(self):
if self.addclasses.has_key(self.klass):
classes = {} classes = {}
for c in (self.classes, for c in (self.classes,
self.addclasses[self.widget.widgetName]): self.addclasses[self.klass]):
for k in c.keys(): for k in c.keys():
classes[k] = c[k] classes[k] = c[k]
self.classes = classes self.classes = classes
Dialog.__init__(self, widget)
def refresh(self): def refresh(self):
self.configuration = self.widget.config() self.configuration = self.widget.config()
...@@ -276,7 +295,8 @@ class WidgetDialog(Dialog): ...@@ -276,7 +295,8 @@ class WidgetDialog(Dialog):
self.current = self.var.get() self.current = self.var.get()
try: try:
self.dialog.widget[self.option] = self.current self.dialog.widget[self.option] = self.current
except TclError: except TclError, msg:
print msg
self.refresh() self.refresh()
class booleanoption(widgetoption, BooleanOption): pass class booleanoption(widgetoption, BooleanOption): pass
...@@ -338,26 +358,25 @@ class WidgetDialog(Dialog): ...@@ -338,26 +358,25 @@ class WidgetDialog(Dialog):
_tristate = {'State': ('normal', 'active', 'disabled')} _tristate = {'State': ('normal', 'active', 'disabled')}
_bistate = {'State': ('normal', 'disabled')} _bistate = {'State': ('normal', 'disabled')}
addclasses = { addclasses = {
'button': _tristate, 'Button': _tristate,
'radiobutton': _tristate, 'Radiobutton': _tristate,
'checkbutton': _tristate, 'Checkbutton': _tristate,
'entry': _bistate, 'Entry': _bistate,
'text': _bistate, 'Text': _bistate,
'menubutton': _tristate, 'Menubutton': _tristate,
'slider': _bistate, 'Slider': _bistate,
} }
class RemoteWidgetDialog(WidgetDialog): class RemoteWidgetDialog(WidgetDialog):
def __init__(self, master, app, widget): def __init__(self, master, app, widget):
self.master = master
self.app = app self.app = app
self.widget = widget self.widget = widget
self.refresh() self.klass = master.send(self.app,
self.top = Toplevel(self.master) 'winfo',
self.top.title(self.app + ' WidgetDialog') 'class',
self.top.minsize(1, 1) self.widget)
self.addchoices() Dialog.__init__(self, master)
def refresh(self): def refresh(self):
try: try:
...@@ -366,7 +385,7 @@ class RemoteWidgetDialog(WidgetDialog): ...@@ -366,7 +385,7 @@ class RemoteWidgetDialog(WidgetDialog):
self.widget, self.widget,
'config')) 'config'))
except TclError, msg: except TclError, msg:
print 'send widget config', self.widget, ':', msg print msg
return return
dict = {} dict = {}
for item in items: for item in items:
...@@ -376,10 +395,7 @@ class RemoteWidgetDialog(WidgetDialog): ...@@ -376,10 +395,7 @@ class RemoteWidgetDialog(WidgetDialog):
dict[key] = value dict[key] = value
self.configuration = dict self.configuration = dict
self.update() self.update()
self.current['.class'] = self.master.send(self.app, self.current['.class'] = self.klass
'winfo',
'class',
self.widget)
self.current['.name'] = self.widget self.current['.name'] = self.widget
class remotewidgetoption: # Mix-in class class remotewidgetoption: # Mix-in class
...@@ -393,7 +409,7 @@ class RemoteWidgetDialog(WidgetDialog): ...@@ -393,7 +409,7 @@ class RemoteWidgetDialog(WidgetDialog):
'-'+self.option, '-'+self.option,
self.current) self.current)
except TclError, msg: except TclError, msg:
print 'send widget config :', msg print msg
self.refresh() self.refresh()
class booleanoption(remotewidgetoption, BooleanOption): pass class booleanoption(remotewidgetoption, BooleanOption): pass
......
# Print a remote app's widget tree (names and classes only) # List a remote app's widget tree (names and classes only)
import sys import sys
import string import string
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment