Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
accurate config types
Browse files Browse the repository at this point in the history
i ended up writing and using this script

    import itertools
    import sys

    import pythotk as tk

    names = ('.asd' + str(i) for i in itertools.count())

    for command  in sys.argv[1:]:
        for option in ['-width', '-height']:
            try:
                tk.tcl_call(None, command, next(names), option, '1i')
                print(command, option, "screen distance")
            except tk.TclError as e1:
                try:
                    tk.tcl_call(None, command, next(names), option, 1)
                    print(command, option, 'integer')
                except tk.TclError as e2:
                    print(command, option, 'WUT???', e1, e2)
  • Loading branch information
Akuli committed Sep 10, 2018
1 parent 161967d commit cf6b41b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pythotk/_widgets/base.py
Expand Up @@ -203,12 +203,14 @@ def __init__(self, parent, **kwargs):
self.state = None

def _init_config(self):
# width and height aren't here because they are integers for some
# widgets and ScreenDistances for others... and sometimes the manual
# pages don't say which, so i have checked them by hand
self.config._types.update({
# ttk_widget(3tk)
'class': str,
'cursor': str,
'style': str,
'width': tk.ScreenDistance,

# options(3tk)
'activebackground': tk.Color,
Expand Down Expand Up @@ -259,7 +261,6 @@ def _init_config(self):
'takefocus': str, # this one is harder to do right than you think

# other stuff that many things seem to have
'height': tk.ScreenDistance, # FIXME: some widgets have int height
'padding': tk.ScreenDistance,
'state': str,
})
Expand Down
13 changes: 13 additions & 0 deletions pythotk/_widgets/misc.py
Expand Up @@ -38,6 +38,7 @@ def _init_config(self):
super()._init_config()
self.config._types.update({
'default': str,
'width': tk.ScreenDistance,
})
self.config._special['command'] = self._create_click_command

Expand Down Expand Up @@ -103,6 +104,7 @@ def _init_config(self):
'onvalue': bool,
'offvalue': bool,
'variable': tk.BooleanVar,
'width': tk.ScreenDistance,
})
self.config._special['command'] = self._create_check_command

Expand Down Expand Up @@ -244,6 +246,7 @@ class Combobox(Entry):
def _init_config(self):
super()._init_config()
self.config._types.update({
'height': int,
'values': [str],
})

Expand All @@ -261,7 +264,9 @@ class Frame(ChildMixin, Widget):
def _init_config(self):
super()._init_config()
self.config._types.update({
'height': tk.ScreenDistance,
'padding': tk.ScreenDistance,
'width': tk.ScreenDistance,
})


Expand All @@ -280,6 +285,12 @@ class Label(ChildMixin, Widget):
def __init__(self, parent, text='', **kwargs):
super().__init__(parent, text=text, **kwargs)

def _init_config(self):
super()._init_config()
self.config._types.update({
'width': tk.ScreenDistance,
})

def _repr_parts(self):
return ['text=' + repr(self.config['text'])]

Expand All @@ -300,8 +311,10 @@ def __init__(self, parent, text='', **kwargs):
def _init_config(self):
super()._init_config()
self.config._types.update({
'height': tk.ScreenDistance,
'labelanchor': str,
'labelwidget': Widget,
'width': tk.ScreenDistance,
})

def _repr_parts(self):
Expand Down
7 changes: 7 additions & 0 deletions pythotk/_widgets/notebook.py
Expand Up @@ -159,6 +159,13 @@ def __init__(self, parent, **kwargs):
# collected when the widgets are garbage collected
self._tab_objects = weakref.WeakKeyDictionary()

def _init_config(self):
super()._init_config()
self.config._types.update({
'width': int,
'height': int,
})

def _get_tab_of_widget(self, widget):
try:
return self._tab_objects[widget]
Expand Down
3 changes: 3 additions & 0 deletions pythotk/_widgets/text.py
Expand Up @@ -256,6 +256,8 @@ def _init_config(self):
'autoseparators': bool,
'blockcursor': bool,
'endline': int,
# undocumented: height can also be a screen distance??
# probably a bug
'height': int,
'inactiveselectbackground': tk.Color,
'insertunfocussed': str,
Expand All @@ -268,6 +270,7 @@ def _init_config(self):
'tabs': [str],
'tabstyle': str,
'undo': bool,
'width': int,
'wrap': str,
})

Expand Down
2 changes: 2 additions & 0 deletions pythotk/_widgets/windows.py
Expand Up @@ -184,10 +184,12 @@ def _init_config(self):
self.config._types.update({
'colormap': str, # 'new' or a widget name, didn't bother
'container': bool,
'height': tk.ScreenDistance,
'menu': tk.Menu,
'screen': str,
'use': int,
'visual': str, # didn't bother
'width': tk.ScreenDistance,
})

def _get_wm_widget(self):
Expand Down

0 comments on commit cf6b41b

Please sign in to comment.