1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00
This commit is contained in:
Shlomi Fish 2018-03-19 19:42:28 +02:00
parent 16d8b00e7f
commit 640f398e6b
2 changed files with 36 additions and 110 deletions

View file

@ -273,6 +273,7 @@ def _dict_from_tcltuple(ttuple, cut_minus=True):
return tclobjs_to_py(retdict) return tclobjs_to_py(retdict)
def _list_from_statespec(stuple): def _list_from_statespec(stuple):
"""Construct a list from the given statespec tuple according to the """Construct a list from the given statespec tuple according to the
accepted statespec accepted by _format_mapdict.""" accepted statespec accepted by _format_mapdict."""
@ -281,7 +282,7 @@ def _list_from_statespec(stuple):
typename = getattr(val, 'typename', None) typename = getattr(val, 'typename', None)
if typename is None: if typename is None:
nval.append(val) nval.append(val)
else: # this is a Tcl object else: # this is a Tcl object
val = str(val) val = str(val)
if typename == 'StateSpec': if typename == 'StateSpec':
val = val.split() val = val.split()
@ -289,6 +290,7 @@ def _list_from_statespec(stuple):
return [_flatten(spec) for spec in zip(iter(nval[::2]), iter(nval[1::2]))] return [_flatten(spec) for spec in zip(iter(nval[::2]), iter(nval[1::2]))]
def _list_from_layouttuple(ltuple): def _list_from_layouttuple(ltuple):
"""Construct a list from the tuple returned by ttk::layout, this is """Construct a list from the tuple returned by ttk::layout, this is
somewhat the reverse of _format_layoutlist.""" somewhat the reverse of _format_layoutlist."""
@ -301,12 +303,12 @@ def _list_from_layouttuple(ltuple):
res.append((name, opts)) res.append((name, opts))
indx += 1 indx += 1
while indx < len(ltuple): # grab name's options while indx < len(ltuple): # grab name's options
opt, val = ltuple[indx:indx + 2] opt, val = ltuple[indx:indx + 2]
if not opt.startswith('-'): # found next name if not opt.startswith('-'): # found next name
break break
opt = opt[1:] # remove the '-' from the option opt = opt[1:] # remove the '-' from the option
indx += 2 indx += 2
if opt == 'children': if opt == 'children':
@ -316,6 +318,7 @@ def _list_from_layouttuple(ltuple):
return res return res
def _val_or_dict(options, func, *args): def _val_or_dict(options, func, *args):
"""Format options then call func with args and options and return """Format options then call func with args and options and return
the appropriate result. the appropriate result.
@ -327,11 +330,12 @@ def _val_or_dict(options, func, *args):
options = _format_optdict(options) options = _format_optdict(options)
res = func(*(args + options)) res = func(*(args + options))
if len(options) % 2: # option specified without a value, return its value if len(options) % 2: # option specified without a value, return its value
return res return res
return _dict_from_tcltuple(res) return _dict_from_tcltuple(res)
def _convert_stringval(value): def _convert_stringval(value):
"""Converts a value to, hopefully, a more appropriate Python object.""" """Converts a value to, hopefully, a more appropriate Python object."""
value = unicode(value) value = unicode(value)
@ -342,6 +346,7 @@ def _convert_stringval(value):
return value return value
def tclobjs_to_py(adict): def tclobjs_to_py(adict):
"""Returns adict with its values converted from Tcl objects to Python """Returns adict with its values converted from Tcl objects to Python
objects.""" objects."""
@ -352,7 +357,7 @@ def tclobjs_to_py(adict):
else: else:
val = list(map(_convert_stringval, val)) val = list(map(_convert_stringval, val))
elif hasattr(val, 'typename'): # some other (single) Tcl object elif hasattr(val, 'typename'): # some other (single) Tcl object
val = _convert_stringval(val) val = _convert_stringval(val)
adict[opt] = val adict[opt] = val
@ -371,12 +376,11 @@ class Style(object):
master = tkinter._default_root or tkinter.Tk() master = tkinter._default_root or tkinter.Tk()
else: else:
raise RuntimeError("No master specified and tkinter is " raise RuntimeError("No master specified and tkinter is "
"configured to not support default master") "configured to not support default master")
self.master = master self.master = master
self.tk = self.master.tk self.tk = self.master.tk
def configure(self, style, query_opt=None, **kw): def configure(self, style, query_opt=None, **kw):
"""Query or sets the default value of the specified option(s) in """Query or sets the default value of the specified option(s) in
style. style.
@ -387,7 +391,6 @@ class Style(object):
kw[query_opt] = None kw[query_opt] = None
return _val_or_dict(kw, self.tk.call, self._name, "configure", style) return _val_or_dict(kw, self.tk.call, self._name, "configure", style)
def map(self, style, query_opt=None, **kw): def map(self, style, query_opt=None, **kw):
"""Query or sets dynamic values of the specified option(s) in """Query or sets dynamic values of the specified option(s) in
style. style.
@ -403,7 +406,6 @@ class Style(object):
return _dict_from_tcltuple( return _dict_from_tcltuple(
self.tk.call(self._name, "map", style, *(_format_mapdict(kw)))) self.tk.call(self._name, "map", style, *(_format_mapdict(kw))))
def lookup(self, style, option, state=None, default=None): def lookup(self, style, option, state=None, default=None):
"""Returns the value specified for option in style. """Returns the value specified for option in style.
@ -413,8 +415,7 @@ class Style(object):
state = ' '.join(state) if state else '' state = ' '.join(state) if state else ''
return self.tk.call(self._name, "lookup", style, '-%s' % option, return self.tk.call(self._name, "lookup", style, '-%s' % option,
state, default) state, default)
def layout(self, style, layoutspec=None): def layout(self, style, layoutspec=None):
"""Define the widget layout for given style. If layoutspec is """Define the widget layout for given style. If layoutspec is
@ -451,31 +452,28 @@ class Style(object):
lspec = None lspec = None
if layoutspec: if layoutspec:
lspec = _format_layoutlist(layoutspec)[0] lspec = _format_layoutlist(layoutspec)[0]
elif layoutspec is not None: # will disable the layout ({}, '', etc) elif layoutspec is not None: # will disable the layout ({}, '', etc)
lspec = "null" # could be any other word, but this may make sense # could be any other word, but this may make sense
# when calling layout(style) later # when calling layout(style) later
lspec = "null"
return _list_from_layouttuple( return _list_from_layouttuple(
self.tk.call(self._name, "layout", style, lspec)) self.tk.call(self._name, "layout", style, lspec))
def element_create(self, elementname, etype, *args, **kw): def element_create(self, elementname, etype, *args, **kw):
"""Create a new element in the current theme of given etype.""" """Create a new element in the current theme of given etype."""
spec, opts = _format_elemcreate(etype, False, *args, **kw) spec, opts = _format_elemcreate(etype, False, *args, **kw)
self.tk.call(self._name, "element", "create", elementname, etype, self.tk.call(self._name, "element", "create", elementname, etype,
spec, *opts) spec, *opts)
def element_names(self): def element_names(self):
"""Returns the list of elements defined in the current theme.""" """Returns the list of elements defined in the current theme."""
return self.tk.call(self._name, "element", "names") return self.tk.call(self._name, "element", "names")
def element_options(self, elementname): def element_options(self, elementname):
"""Return the list of elementname's options.""" """Return the list of elementname's options."""
return self.tk.call(self._name, "element", "options", elementname) return self.tk.call(self._name, "element", "options", elementname)
def theme_create(self, themename, parent=None, settings=None): def theme_create(self, themename, parent=None, settings=None):
"""Creates a new theme. """Creates a new theme.
@ -487,11 +485,10 @@ class Style(object):
if parent: if parent:
self.tk.call(self._name, "theme", "create", themename, self.tk.call(self._name, "theme", "create", themename,
"-parent", parent, "-settings", script) "-parent", parent, "-settings", script)
else: else:
self.tk.call(self._name, "theme", "create", themename, self.tk.call(self._name, "theme", "create", themename,
"-settings", script) "-settings", script)
def theme_settings(self, themename, settings): def theme_settings(self, themename, settings):
"""Temporarily sets the current theme to themename, apply specified """Temporarily sets the current theme to themename, apply specified
@ -504,12 +501,10 @@ class Style(object):
script = _script_from_settings(settings) script = _script_from_settings(settings)
self.tk.call(self._name, "theme", "settings", themename, script) self.tk.call(self._name, "theme", "settings", themename, script)
def theme_names(self): def theme_names(self):
"""Returns a list of all known themes.""" """Returns a list of all known themes."""
return self.tk.call(self._name, "theme", "names") return self.tk.call(self._name, "theme", "names")
def theme_use(self, themename=None): def theme_use(self, themename=None):
"""If themename is None, returns the theme in use, otherwise, set """If themename is None, returns the theme in use, otherwise, set
the current theme to themename, refreshes all widgets and emits the current theme to themename, refreshes all widgets and emits
@ -550,7 +545,6 @@ class Widget(tkinter.Widget):
""" """
tkinter.Widget.__init__(self, master, widgetname, kw=kw) tkinter.Widget.__init__(self, master, widgetname, kw=kw)
def identify(self, x, y): def identify(self, x, y):
"""Returns the name of the element at position x, y, or the empty """Returns the name of the element at position x, y, or the empty
string if the point does not lie within any element. string if the point does not lie within any element.
@ -558,7 +552,6 @@ class Widget(tkinter.Widget):
x and y are pixel coordinates relative to the widget.""" x and y are pixel coordinates relative to the widget."""
return self.tk.call(self._w, "identify", x, y) return self.tk.call(self._w, "identify", x, y)
def instate(self, statespec, callback=None, *args, **kw): def instate(self, statespec, callback=None, *args, **kw):
"""Test the widget's state. """Test the widget's state.
@ -572,7 +565,6 @@ class Widget(tkinter.Widget):
return bool(ret) return bool(ret)
def state(self, statespec=None): def state(self, statespec=None):
"""Modify or inquire widget state. """Modify or inquire widget state.
@ -583,7 +575,8 @@ class Widget(tkinter.Widget):
if statespec is not None: if statespec is not None:
statespec = ' '.join(statespec) statespec = ' '.join(statespec)
return self.tk.splitlist(str(self.tk.call(self._w, "state", statespec))) return self.tk.splitlist(
str(self.tk.call(self._w, "state", statespec)))
class Button(Widget): class Button(Widget):
@ -604,7 +597,6 @@ class Button(Widget):
""" """
Widget.__init__(self, master, "ttk::button", kw) Widget.__init__(self, master, "ttk::button", kw)
def invoke(self): def invoke(self):
"""Invokes the command associated with the button.""" """Invokes the command associated with the button."""
return self.tk.call(self._w, "invoke") return self.tk.call(self._w, "invoke")
@ -627,7 +619,6 @@ class Checkbutton(Widget):
""" """
Widget.__init__(self, master, "ttk::checkbutton", kw) Widget.__init__(self, master, "ttk::checkbutton", kw)
def invoke(self): def invoke(self):
"""Toggles between the selected and deselected states and """Toggles between the selected and deselected states and
invokes the associated command. If the widget is currently invokes the associated command. If the widget is currently
@ -661,19 +652,16 @@ class Entry(Widget, tkinter.Entry):
""" """
Widget.__init__(self, master, widget or "ttk::entry", kw) Widget.__init__(self, master, widget or "ttk::entry", kw)
def bbox(self, index): def bbox(self, index):
"""Return a tuple of (x, y, width, height) which describes the """Return a tuple of (x, y, width, height) which describes the
bounding box of the character given by index.""" bounding box of the character given by index."""
return self.tk.call(self._w, "bbox", index) return self.tk.call(self._w, "bbox", index)
def identify(self, x, y): def identify(self, x, y):
"""Returns the name of the element at position x, y, or the """Returns the name of the element at position x, y, or the
empty string if the coordinates are outside the window.""" empty string if the coordinates are outside the window."""
return self.tk.call(self._w, "identify", x, y) return self.tk.call(self._w, "identify", x, y)
def validate(self): def validate(self):
"""Force revalidation, independent of the conditions specified """Force revalidation, independent of the conditions specified
by the validate option. Returns False if validation fails, True by the validate option. Returns False if validation fails, True
@ -704,14 +692,12 @@ class Combobox(Entry):
Entry.__init__(self, master, "ttk::combobox", **kw) Entry.__init__(self, master, "ttk::combobox", **kw)
def __setitem__(self, item, value): def __setitem__(self, item, value):
if item == "values": if item == "values":
value = _format_optdict({item: value})[1] value = _format_optdict({item: value})[1]
Entry.__setitem__(self, item, value) Entry.__setitem__(self, item, value)
def configure(self, cnf=None, **kw): def configure(self, cnf=None, **kw):
"""Custom Combobox configure, created to properly format the values """Custom Combobox configure, created to properly format the values
option.""" option."""
@ -720,7 +706,6 @@ class Combobox(Entry):
return Entry.configure(self, cnf, **kw) return Entry.configure(self, cnf, **kw)
def current(self, newindex=None): def current(self, newindex=None):
"""If newindex is supplied, sets the combobox value to the """If newindex is supplied, sets the combobox value to the
element at position newindex in the list of values. Otherwise, element at position newindex in the list of values. Otherwise,
@ -728,7 +713,6 @@ class Combobox(Entry):
or -1 if the current value does not appear in the list.""" or -1 if the current value does not appear in the list."""
return self.tk.call(self._w, "current", newindex) return self.tk.call(self._w, "current", newindex)
def set(self, value): def set(self, value):
"""Sets the value of the combobox to value.""" """Sets the value of the combobox to value."""
self.tk.call(self._w, "set", value) self.tk.call(self._w, "set", value)
@ -789,7 +773,8 @@ class Labelframe(Widget):
""" """
Widget.__init__(self, master, "ttk::labelframe", kw) Widget.__init__(self, master, "ttk::labelframe", kw)
LabelFrame = Labelframe # tkinter name compatibility
LabelFrame = Labelframe # tkinter name compatibility
class Menubutton(Widget): class Menubutton(Widget):
@ -847,7 +832,6 @@ class Notebook(Widget):
""" """
Widget.__init__(self, master, "ttk::notebook", kw) Widget.__init__(self, master, "ttk::notebook", kw)
def add(self, child, **kw): def add(self, child, **kw):
"""Adds a new tab to the notebook. """Adds a new tab to the notebook.
@ -855,13 +839,11 @@ class Notebook(Widget):
restored to its previous position.""" restored to its previous position."""
self.tk.call(self._w, "add", child, *(_format_optdict(kw))) self.tk.call(self._w, "add", child, *(_format_optdict(kw)))
def forget(self, tab_id): def forget(self, tab_id):
"""Removes the tab specified by tab_id, unmaps and unmanages the """Removes the tab specified by tab_id, unmaps and unmanages the
associated window.""" associated window."""
self.tk.call(self._w, "forget", tab_id) self.tk.call(self._w, "forget", tab_id)
def hide(self, tab_id): def hide(self, tab_id):
"""Hides the tab specified by tab_id. """Hides the tab specified by tab_id.
@ -870,19 +852,16 @@ class Notebook(Widget):
tabs may be restored with the add command.""" tabs may be restored with the add command."""
self.tk.call(self._w, "hide", tab_id) self.tk.call(self._w, "hide", tab_id)
def identify(self, x, y): def identify(self, x, y):
"""Returns the name of the tab element at position x, y, or the """Returns the name of the tab element at position x, y, or the
empty string if none.""" empty string if none."""
return self.tk.call(self._w, "identify", x, y) return self.tk.call(self._w, "identify", x, y)
def index(self, tab_id): def index(self, tab_id):
"""Returns the numeric index of the tab specified by tab_id, or """Returns the numeric index of the tab specified by tab_id, or
the total number of tabs if tab_id is the string "end".""" the total number of tabs if tab_id is the string "end"."""
return self.tk.call(self._w, "index", tab_id) return self.tk.call(self._w, "index", tab_id)
def insert(self, pos, child, **kw): def insert(self, pos, child, **kw):
"""Inserts a pane at the specified position. """Inserts a pane at the specified position.
@ -891,7 +870,6 @@ class Notebook(Widget):
moves it to the specified position.""" moves it to the specified position."""
self.tk.call(self._w, "insert", pos, child, *(_format_optdict(kw))) self.tk.call(self._w, "insert", pos, child, *(_format_optdict(kw)))
def select(self, tab_id=None): def select(self, tab_id=None):
"""Selects the specified tab. """Selects the specified tab.
@ -901,7 +879,6 @@ class Notebook(Widget):
pane.""" pane."""
return self.tk.call(self._w, "select", tab_id) return self.tk.call(self._w, "select", tab_id)
def tab(self, tab_id, option=None, **kw): def tab(self, tab_id, option=None, **kw):
"""Query or modify the options of the specific tab_id. """Query or modify the options of the specific tab_id.
@ -912,12 +889,10 @@ class Notebook(Widget):
kw[option] = None kw[option] = None
return _val_or_dict(kw, self.tk.call, self._w, "tab", tab_id) return _val_or_dict(kw, self.tk.call, self._w, "tab", tab_id)
def tabs(self): def tabs(self):
"""Returns a list of windows managed by the notebook.""" """Returns a list of windows managed by the notebook."""
return self.tk.call(self._w, "tabs") or () return self.tk.call(self._w, "tabs") or ()
def enable_traversal(self): def enable_traversal(self):
"""Enable keyboard traversal for a toplevel window containing """Enable keyboard traversal for a toplevel window containing
this notebook. this notebook.
@ -965,9 +940,7 @@ class Panedwindow(Widget, tkinter.PanedWindow):
""" """
Widget.__init__(self, master, "ttk::panedwindow", kw) Widget.__init__(self, master, "ttk::panedwindow", kw)
forget = tkinter.PanedWindow.forget # overrides Pack.forget
forget = tkinter.PanedWindow.forget # overrides Pack.forget
def insert(self, pos, child, **kw): def insert(self, pos, child, **kw):
"""Inserts a pane at the specified positions. """Inserts a pane at the specified positions.
@ -977,7 +950,6 @@ class Panedwindow(Widget, tkinter.PanedWindow):
moves it to the specified position.""" moves it to the specified position."""
self.tk.call(self._w, "insert", pos, child, *(_format_optdict(kw))) self.tk.call(self._w, "insert", pos, child, *(_format_optdict(kw)))
def pane(self, pane, option=None, **kw): def pane(self, pane, option=None, **kw):
"""Query or modify the options of the specified pane. """Query or modify the options of the specified pane.
@ -989,7 +961,6 @@ class Panedwindow(Widget, tkinter.PanedWindow):
kw[option] = None kw[option] = None
return _val_or_dict(kw, self.tk.call, self._w, "pane", pane) return _val_or_dict(kw, self.tk.call, self._w, "pane", pane)
def sashpos(self, index, newpos=None): def sashpos(self, index, newpos=None):
"""If newpos is specified, sets the position of sash number index. """If newpos is specified, sets the position of sash number index.
@ -1000,7 +971,8 @@ class Panedwindow(Widget, tkinter.PanedWindow):
Returns the new position of sash number index.""" Returns the new position of sash number index."""
return self.tk.call(self._w, "sashpos", index, newpos) return self.tk.call(self._w, "sashpos", index, newpos)
PanedWindow = Panedwindow # tkinter name compatibility
PanedWindow = Panedwindow # tkinter name compatibility
class Progressbar(Widget): class Progressbar(Widget):
@ -1023,7 +995,6 @@ class Progressbar(Widget):
""" """
Widget.__init__(self, master, "ttk::progressbar", kw) Widget.__init__(self, master, "ttk::progressbar", kw)
def start(self, interval=None): def start(self, interval=None):
"""Begin autoincrement mode: schedules a recurring timer event """Begin autoincrement mode: schedules a recurring timer event
that calls method step every interval milliseconds. that calls method step every interval milliseconds.
@ -1031,14 +1002,12 @@ class Progressbar(Widget):
interval defaults to 50 milliseconds (20 steps/second) if ommitted.""" interval defaults to 50 milliseconds (20 steps/second) if ommitted."""
self.tk.call(self._w, "start", interval) self.tk.call(self._w, "start", interval)
def step(self, amount=None): def step(self, amount=None):
"""Increments the value option by amount. """Increments the value option by amount.
amount defaults to 1.0 if omitted.""" amount defaults to 1.0 if omitted."""
self.tk.call(self._w, "step", amount) self.tk.call(self._w, "step", amount)
def stop(self): def stop(self):
"""Stop autoincrement mode: cancels any recurring timer event """Stop autoincrement mode: cancels any recurring timer event
initiated by start.""" initiated by start."""
@ -1063,7 +1032,6 @@ class Radiobutton(Widget):
""" """
Widget.__init__(self, master, "ttk::radiobutton", kw) Widget.__init__(self, master, "ttk::radiobutton", kw)
def invoke(self): def invoke(self):
"""Sets the option variable to the option value, selects the """Sets the option variable to the option value, selects the
widget, and invokes the associated command. widget, and invokes the associated command.
@ -1090,7 +1058,6 @@ class Scale(Widget, tkinter.Scale):
""" """
Widget.__init__(self, master, "ttk::scale", kw) Widget.__init__(self, master, "ttk::scale", kw)
def configure(self, cnf=None, **kw): def configure(self, cnf=None, **kw):
"""Modify or query scale options. """Modify or query scale options.
@ -1102,7 +1069,6 @@ class Scale(Widget, tkinter.Scale):
if any(['from' in kw, 'from_' in kw, 'to' in kw]): if any(['from' in kw, 'from_' in kw, 'to' in kw]):
self.event_generate('<<RangeChanged>>') self.event_generate('<<RangeChanged>>')
def get(self, x=None, y=None): def get(self, x=None, y=None):
"""Get the current value of the value option, or the value """Get the current value of the value option, or the value
corresponding to the coordinates x, y if they are specified. corresponding to the coordinates x, y if they are specified.
@ -1190,7 +1156,6 @@ class Treeview(Widget):
""" """
Widget.__init__(self, master, "ttk::treeview", kw) Widget.__init__(self, master, "ttk::treeview", kw)
def bbox(self, item, column=None): def bbox(self, item, column=None):
"""Returns the bounding box (relative to the treeview widget's """Returns the bounding box (relative to the treeview widget's
window) of the specified item in the form x y width height. window) of the specified item in the form x y width height.
@ -1200,14 +1165,12 @@ class Treeview(Widget):
closed item or is scrolled offscreen), returns an empty string.""" closed item or is scrolled offscreen), returns an empty string."""
return self.tk.call(self._w, "bbox", item, column) return self.tk.call(self._w, "bbox", item, column)
def get_children(self, item=None): def get_children(self, item=None):
"""Returns a tuple of children belonging to item. """Returns a tuple of children belonging to item.
If item is not specified, returns root children.""" If item is not specified, returns root children."""
return self.tk.call(self._w, "children", item or '') or () return self.tk.call(self._w, "children", item or '') or ()
def set_children(self, item, *newchildren): def set_children(self, item, *newchildren):
"""Replaces item's child with newchildren. """Replaces item's child with newchildren.
@ -1216,7 +1179,6 @@ class Treeview(Widget):
ancestor of item.""" ancestor of item."""
self.tk.call(self._w, "children", item, newchildren) self.tk.call(self._w, "children", item, newchildren)
def column(self, column, option=None, **kw): def column(self, column, option=None, **kw):
"""Query or modify the options for the specified column. """Query or modify the options for the specified column.
@ -1227,13 +1189,11 @@ class Treeview(Widget):
kw[option] = None kw[option] = None
return _val_or_dict(kw, self.tk.call, self._w, "column", column) return _val_or_dict(kw, self.tk.call, self._w, "column", column)
def delete(self, items): def delete(self, items):
"""Delete all specified items and all their descendants. The root """Delete all specified items and all their descendants. The root
item may not be deleted.""" item may not be deleted."""
self.tk.call(self._w, "delete", items) self.tk.call(self._w, "delete", items)
def detach(self, *items): def detach(self, *items):
"""Unlinks all of the specified items from the tree. """Unlinks all of the specified items from the tree.
@ -1242,19 +1202,16 @@ class Treeview(Widget):
displayed. The root item may not be detached.""" displayed. The root item may not be detached."""
self.tk.call(self._w, "detach", items) self.tk.call(self._w, "detach", items)
def exists(self, item): def exists(self, item):
"""Returns True if the specified item is present in the three, """Returns True if the specified item is present in the three,
False otherwise.""" False otherwise."""
return bool(self.tk.call(self._w, "exists", item)) return bool(self.tk.call(self._w, "exists", item))
def focus(self, item=None): def focus(self, item=None):
"""If item is specified, sets the focus item to item. Otherwise, """If item is specified, sets the focus item to item. Otherwise,
returns the current focus item, or '' if there is none.""" returns the current focus item, or '' if there is none."""
return self.tk.call(self._w, "focus", item) return self.tk.call(self._w, "focus", item)
def heading(self, column, option=None, **kw): def heading(self, column, option=None, **kw):
"""Query or modify the heading options for the specified column. """Query or modify the heading options for the specified column.
@ -1286,26 +1243,22 @@ class Treeview(Widget):
return _val_or_dict(kw, self.tk.call, self._w, 'heading', column) return _val_or_dict(kw, self.tk.call, self._w, 'heading', column)
def identify(self, component, x, y): def identify(self, component, x, y):
"""Returns a description of the specified component under the """Returns a description of the specified component under the
point given by x and y, or the empty string if no such component point given by x and y, or the empty string if no such component
is present at that position.""" is present at that position."""
return self.tk.call(self._w, "identify", component, x, y) return self.tk.call(self._w, "identify", component, x, y)
def identify_row(self, y): def identify_row(self, y):
"""Returns the item ID of the item at position y.""" """Returns the item ID of the item at position y."""
return self.identify("row", 0, y) return self.identify("row", 0, y)
def identify_column(self, x): def identify_column(self, x):
"""Returns the data column identifier of the cell at position x. """Returns the data column identifier of the cell at position x.
The tree column has ID #0.""" The tree column has ID #0."""
return self.identify("column", x, 0) return self.identify("column", x, 0)
def identify_region(self, x, y): def identify_region(self, x, y):
"""Returns one of: """Returns one of:
@ -1317,20 +1270,17 @@ class Treeview(Widget):
* Availability: Tk 8.6""" * Availability: Tk 8.6"""
return self.identify("region", x, y) return self.identify("region", x, y)
def identify_element(self, x, y): def identify_element(self, x, y):
"""Returns the element at position x, y. """Returns the element at position x, y.
* Availability: Tk 8.6""" * Availability: Tk 8.6"""
return self.identify("element", x, y) return self.identify("element", x, y)
def index(self, item): def index(self, item):
"""Returns the integer index of item within its parent's list """Returns the integer index of item within its parent's list
of children.""" of children."""
return self.tk.call(self._w, "index", item) return self.tk.call(self._w, "index", item)
def insert(self, parent, index, iid=None, **kw): def insert(self, parent, index, iid=None, **kw):
"""Creates a new item and return the item identifier of the newly """Creates a new item and return the item identifier of the newly
created item. created item.
@ -1347,13 +1297,12 @@ class Treeview(Widget):
opts = _format_optdict(kw) opts = _format_optdict(kw)
if iid: if iid:
res = self.tk.call(self._w, "insert", parent, index, res = self.tk.call(self._w, "insert", parent, index,
"-id", iid, *opts) "-id", iid, *opts)
else: else:
res = self.tk.call(self._w, "insert", parent, index, *opts) res = self.tk.call(self._w, "insert", parent, index, *opts)
return res return res
def item(self, item, option=None, **kw): def item(self, item, option=None, **kw):
"""Query or modify the options for the specified item. """Query or modify the options for the specified item.
@ -1364,7 +1313,6 @@ class Treeview(Widget):
kw[option] = None kw[option] = None
return _val_or_dict(kw, self.tk.call, self._w, "item", item) return _val_or_dict(kw, self.tk.call, self._w, "item", item)
def move(self, item, parent, index): def move(self, item, parent, index):
"""Moves item to position index in parent's list of children. """Moves item to position index in parent's list of children.
@ -1374,27 +1322,23 @@ class Treeview(Widget):
it is moved to the end. If item was detached it is reattached.""" it is moved to the end. If item was detached it is reattached."""
self.tk.call(self._w, "move", item, parent, index) self.tk.call(self._w, "move", item, parent, index)
reattach = move # A sensible method name for reattaching detached items reattach = move # A sensible method name for reattaching detached items
def next(self, item): def next(self, item):
"""Returns the identifier of item's next sibling, or '' if item """Returns the identifier of item's next sibling, or '' if item
is the last child of its parent.""" is the last child of its parent."""
return self.tk.call(self._w, "next", item) return self.tk.call(self._w, "next", item)
def parent(self, item): def parent(self, item):
"""Returns the ID of the parent of item, or '' if item is at the """Returns the ID of the parent of item, or '' if item is at the
top level of the hierarchy.""" top level of the hierarchy."""
return self.tk.call(self._w, "parent", item) return self.tk.call(self._w, "parent", item)
def prev(self, item): def prev(self, item):
"""Returns the identifier of item's previous sibling, or '' if """Returns the identifier of item's previous sibling, or '' if
item is the first child of its parent.""" item is the first child of its parent."""
return self.tk.call(self._w, "prev", item) return self.tk.call(self._w, "prev", item)
def see(self, item): def see(self, item):
"""Ensure that item is visible. """Ensure that item is visible.
@ -1403,32 +1347,26 @@ class Treeview(Widget):
portion of the tree.""" portion of the tree."""
self.tk.call(self._w, "see", item) self.tk.call(self._w, "see", item)
def selection(self, selop=None, items=None): def selection(self, selop=None, items=None):
"""If selop is not specified, returns selected items.""" """If selop is not specified, returns selected items."""
return self.tk.call(self._w, "selection", selop, items) return self.tk.call(self._w, "selection", selop, items)
def selection_set(self, items): def selection_set(self, items):
"""items becomes the new selection.""" """items becomes the new selection."""
self.selection("set", items) self.selection("set", items)
def selection_add(self, items): def selection_add(self, items):
"""Add items to the selection.""" """Add items to the selection."""
self.selection("add", items) self.selection("add", items)
def selection_remove(self, items): def selection_remove(self, items):
"""Remove items from the selection.""" """Remove items from the selection."""
self.selection("remove", items) self.selection("remove", items)
def selection_toggle(self, items): def selection_toggle(self, items):
"""Toggle the selection state of each item in items.""" """Toggle the selection state of each item in items."""
self.selection("toggle", items) self.selection("toggle", items)
def set(self, item, column=None, value=None): def set(self, item, column=None, value=None):
"""With one argument, returns a dictionary of column/value pairs """With one argument, returns a dictionary of column/value pairs
for the specified item. With two arguments, returns the current for the specified item. With two arguments, returns the current
@ -1440,13 +1378,12 @@ class Treeview(Widget):
else: else:
return res return res
def tag_bind(self, tagname, sequence=None, callback=None): def tag_bind(self, tagname, sequence=None, callback=None):
"""Bind a callback for the given event sequence to the tag tagname. """Bind a callback for the given event sequence to the tag tagname.
When an event is delivered to an item, the callbacks for each When an event is delivered to an item, the callbacks for each
of the item's tags option are called.""" of the item's tags option are called."""
self._bind((self._w, "tag", "bind", tagname), sequence, callback, add=0) self._bind((self._w, "tag", "bind", tagname),
sequence, callback, add=0)
def tag_configure(self, tagname, option=None, **kw): def tag_configure(self, tagname, option=None, **kw):
"""Query or modify the options for the specified tagname. """Query or modify the options for the specified tagname.
@ -1458,8 +1395,7 @@ class Treeview(Widget):
if option is not None: if option is not None:
kw[option] = None kw[option] = None
return _val_or_dict(kw, self.tk.call, self._w, "tag", "configure", return _val_or_dict(kw, self.tk.call, self._w, "tag", "configure",
tagname) tagname)
def tag_has(self, tagname, item=None): def tag_has(self, tagname, item=None):
"""If item is specified, returns 1 or 0 depending on whether the """If item is specified, returns 1 or 0 depending on whether the
@ -1469,12 +1405,10 @@ class Treeview(Widget):
* Availability: Tk 8.6""" * Availability: Tk 8.6"""
return self.tk.call(self._w, "tag", "has", tagname, item) return self.tk.call(self._w, "tag", "has", tagname, item)
def xview(self, *args): def xview(self, *args):
"""Query or modify horizontal position of the treeview.""" """Query or modify horizontal position of the treeview."""
return self.tk.call(self._w, "xview", *args) return self.tk.call(self._w, "xview", *args)
def yview(self, *args): def yview(self, *args):
"""Query or modify vertical position of the treeview.""" """Query or modify vertical position of the treeview."""
return self.tk.call(self._w, "yview", *args) return self.tk.call(self._w, "yview", *args)
@ -1515,7 +1449,7 @@ class LabeledScale(Frame, object):
scale_side = 'bottom' if self._label_top else 'top' scale_side = 'bottom' if self._label_top else 'top'
label_side = 'top' if scale_side == 'bottom' else 'bottom' label_side = 'top' if scale_side == 'bottom' else 'bottom'
self.scale.pack(side=scale_side, fill='x') self.scale.pack(side=scale_side, fill='x')
tmp = Label(self).pack(side=label_side) # place holder Label(self).pack(side=label_side) # place holder
self.label.place(anchor='n' if label_side == 'top' else 's') self.label.place(anchor='n' if label_side == 'top' else 's')
# update the label as scale or variable changes # update the label as scale or variable changes
@ -1523,18 +1457,16 @@ class LabeledScale(Frame, object):
self.bind('<Configure>', self._adjust) self.bind('<Configure>', self._adjust)
self.bind('<Map>', self._adjust) self.bind('<Map>', self._adjust)
def destroy(self): def destroy(self):
"""Destroy this widget and possibly its associated variable.""" """Destroy this widget and possibly its associated variable."""
self._variable.trace_vdelete('w', self.__tracecb) self._variable.trace_vdelete('w', self.__tracecb)
del self._variable del self._variable
Frame.destroy(self) Frame.destroy(self)
def _adjust(self, *args): def _adjust(self, *args):
"""Adjust the label position according to the scale.""" """Adjust the label position according to the scale."""
def adjust_label(): def adjust_label():
self.update_idletasks() # "force" scale redraw self.update_idletasks() # "force" scale redraw
x, y = self.scale.coords() x, y = self.scale.coords()
if self._label_top: if self._label_top:
@ -1557,17 +1489,14 @@ class LabeledScale(Frame, object):
self.label['text'] = newval self.label['text'] = newval
self.after_idle(adjust_label) self.after_idle(adjust_label)
def _get_value(self): def _get_value(self):
"""Return current scale value.""" """Return current scale value."""
return self._variable.get() return self._variable.get()
def _set_value(self, val): def _set_value(self, val):
"""Set new scale value.""" """Set new scale value."""
self._variable.set(val) self._variable.set(val)
value = property(_get_value, _set_value) value = property(_get_value, _set_value)
@ -1603,27 +1532,25 @@ class OptionMenu(Menubutton):
self.set_menu(default, *values) self.set_menu(default, *values)
def __getitem__(self, item): def __getitem__(self, item):
if item == 'menu': if item == 'menu':
return self.nametowidget(Menubutton.__getitem__(self, item)) return self.nametowidget(Menubutton.__getitem__(self, item))
return Menubutton.__getitem__(self, item) return Menubutton.__getitem__(self, item)
def set_menu(self, default=None, *values): def set_menu(self, default=None, *values):
"""Build a new menu of radiobuttons with *values and optionally """Build a new menu of radiobuttons with *values and optionally
a default value.""" a default value."""
menu = self['menu'] menu = self['menu']
menu.delete(0, 'end') menu.delete(0, 'end')
for val in values: for val in values:
menu.add_radiobutton(label=val, menu.add_radiobutton(
label=val,
command=tkinter._setit(self._variable, val, self._callback)) command=tkinter._setit(self._variable, val, self._callback))
if default: if default:
self._variable.set(default) self._variable.set(default)
def destroy(self): def destroy(self):
"""Destroy this widget and its associated variable.""" """Destroy this widget and its associated variable."""
del self._variable del self._variable

View file

@ -26,7 +26,6 @@ my %skip = (
pysollib/games/mahjongg/__init__.py pysollib/games/mahjongg/__init__.py
pysollib/games/special/__init__.py pysollib/games/special/__init__.py
pysollib/games/ultra/__init__.py pysollib/games/ultra/__init__.py
pysollib/tile/ttk.py
pysollib/ui/tktile/Canvas2.py pysollib/ui/tktile/Canvas2.py
scripts/all_games.py scripts/all_games.py
./setup.py ./setup.py