Skip to content

Commit

Permalink
wxGUI: fix 'SpinCtrl' widget size (#1339)
Browse files Browse the repository at this point in the history
In general, using sizers and not setting size explicitly works best, so I changed the SpinCtrl wrapper to (on gtk) ignore size parameter if it's smaller than the minimum you identified, so that we don't have to remove all the size parameters directly. I removed couple size settings which were greater than the minimum and would likely cause troubles. This should help with getting rid of many Gtk-critical messages.
  • Loading branch information
tmszi committed Apr 18, 2022
1 parent 3925684 commit d7c3b5a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 27 deletions.
2 changes: 0 additions & 2 deletions gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,6 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
txt2 = SpinCtrl(
parent=which_panel,
id=wx.ID_ANY,
size=globalvar.DIALOG_SPIN_SIZE,
min=minValue,
max=maxValue,
)
Expand Down Expand Up @@ -1423,7 +1422,6 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
win = SpinCtrl(
parent=which_panel,
value=p.get("default", ""),
size=globalvar.DIALOG_SPIN_SIZE,
min=minValue,
max=maxValue,
)
Expand Down
11 changes: 3 additions & 8 deletions gui/wxpython/gui_core/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,13 @@ class SpinCtrl(wx.SpinCtrl):
"""Wrapper around wx.SpinCtrl to have more control
over the widget on different platforms"""

gtk3MinSize = 130
gtk3MinSize = 118 # optimal for SpinCtrl default param min=1, max=100

def __init__(self, *args, **kwargs):
args = convertToInt(argsOrKwargs=args)
kwargs = convertToInt(argsOrKwargs=kwargs)
if gtk3:
if "size" in kwargs:
kwargs["size"] = wx.Size(
max(self.gtk3MinSize, kwargs["size"][0]), kwargs["size"][1]
)
else:
kwargs["size"] = wx.Size(self.gtk3MinSize, -1)
if gtk3 and "size" in kwargs and kwargs["size"][0] < self.gtk3MinSize:
del kwargs["size"]

wx.SpinCtrl.__init__(self, *args, **kwargs)

Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/modules/colorrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ def __init__(self, parent, mapType, attributeType, properties, panelWidth=180):
# clear button
self.clearAll = Button(parent, id=wx.ID_ANY, label=_("Clear all"))
# determines how many rules should be added
self.numRules = SpinCtrl(
parent, id=wx.ID_ANY, min=1, max=1e6, initial=1, size=(150, -1)
)
self.numRules = SpinCtrl(parent, id=wx.ID_ANY, min=1, max=1e6, initial=1)
# add rules
self.btnAdd = Button(parent, id=wx.ID_ADD)

Expand Down
8 changes: 2 additions & 6 deletions gui/wxpython/vdigit/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,17 +626,13 @@ def __init__(self, parent, title, nselected, style=wx.DEFAULT_DIALOG_STYLE):

# starting value
txt = StaticText(parent=self, label=_("Starting value"))
self.value = SpinCtrl(
parent=self, id=wx.ID_ANY, size=(150, -1), initial=0, min=-1e6, max=1e6
)
self.value = SpinCtrl(parent=self, id=wx.ID_ANY, initial=0, min=-1e6, max=1e6)
flexSizer.Add(txt, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
flexSizer.Add(self.value, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)

# step
txt = StaticText(parent=self, label=_("Step"))
self.step = SpinCtrl(
parent=self, id=wx.ID_ANY, size=(150, -1), initial=0, min=0, max=1e6
)
self.step = SpinCtrl(parent=self, id=wx.ID_ANY, initial=0, min=0, max=1e6)
flexSizer.Add(txt, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
flexSizer.Add(self.step, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)

Expand Down
11 changes: 4 additions & 7 deletions gui/wxpython/vdigit/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,22 +528,19 @@ def _createAttributesPage(self, notebook):
settings = ((_("Layer"), 1), (_("Category"), 1), (_("Mode"), _("Next to use")))
# layer
text = StaticText(parent=panel, id=wx.ID_ANY, label=_("Layer"))
self.layer = SpinCtrl(
parent=panel, id=wx.ID_ANY, size=(125, -1), min=1, max=1e3
)
self.layer = SpinCtrl(parent=panel, id=wx.ID_ANY, min=1, max=1e3)
self.layer.SetValue(
int(UserSettings.Get(group="vdigit", key="layer", subkey="value"))
)
flexSizer.Add(text, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
flexSizer.Add(
self.layer, proportion=0, flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL
self.layer, proportion=0, flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL
)
# category number
text = StaticText(parent=panel, id=wx.ID_ANY, label=_("Category number"))
self.category = SpinCtrl(
parent=panel,
id=wx.ID_ANY,
size=(125, -1),
initial=UserSettings.Get(group="vdigit", key="category", subkey="value"),
min=-1e9,
max=1e9,
Expand All @@ -557,7 +554,7 @@ def _createAttributesPage(self, notebook):
flexSizer.Add(
self.category,
proportion=0,
flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL,
flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL,
)
# category mode
text = StaticText(parent=panel, id=wx.ID_ANY, label=_("Category mode"))
Expand All @@ -574,7 +571,7 @@ def _createAttributesPage(self, notebook):
flexSizer.Add(
self.categoryMode,
proportion=0,
flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL,
flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL,
)

sizer.Add(flexSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=1)
Expand Down
1 change: 0 additions & 1 deletion gui/wxpython/vnet/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ def _createPointsPage(self):
id=wx.ID_ANY,
min=0,
max=maxValue,
size=(150, -1),
)
self.anSettings["max_dist"].Bind(wx.EVT_SPINCTRL, lambda event: self.MaxDist())
self.anSettings["max_dist"].SetValue(100000) # TODO init val
Expand Down

0 comments on commit d7c3b5a

Please sign in to comment.