Skip to content

Commit

Permalink
Do not expand settings spinners, combo boxes and dropdown lists.
Browse files Browse the repository at this point in the history
When expanded they looked unnatural, required long mouse moves to
operate their buttons if noticed at all.
Move Cancel, OK to the center.
Added logic to size spinners depending on contents, but some
platform/toolkit versions cause problems. GTK 3.0 makes controls too
wide, 3.1 is much better.
  • Loading branch information
volconst committed Aug 2, 2020
1 parent 46485fd commit 5d42c19
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
5 changes: 3 additions & 2 deletions printrun/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ def __init__(self, pronterface):
label.SetFont(font)
grid.Add(label, pos = (current_row, 0),
flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
expand = 0 if isinstance(widget, (wx.SpinCtrlDouble, wx.Choice, wx.ComboBox)) else wx.EXPAND
grid.Add(widget, pos = (current_row, 1),
flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
flag = wx.ALIGN_CENTER_VERTICAL | expand)
if hasattr(label, "set_default"):
label.Bind(wx.EVT_MOUSE_EVENTS, label.set_default)
if hasattr(widget, "Bind"):
Expand All @@ -174,7 +175,7 @@ def __init__(self, pronterface):
panel.SetSizer(sbox)
topsizer = wx.BoxSizer(wx.VERTICAL)
topsizer.Add(panel, 1, wx.ALL | wx.EXPAND)
topsizer.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL), 0, wx.ALIGN_RIGHT)
topsizer.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL), 0, wx.ALIGN_CENTER)
self.SetSizerAndFit(topsizer)
self.SetMinSize(self.GetSize())

Expand Down
50 changes: 37 additions & 13 deletions printrun/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,12 @@ def get_specific_widget(self, parent):
class SpinSetting(wxSetting):

def __init__(self, name, default, min, max, label = None, help = None, group = None, increment = 0.1):
super(SpinSetting, self).__init__(name, default, label, help, group)
super().__init__(name, default, label, help, group)
self.min = min
self.max = max
self.increment = increment

def get_specific_widget(self, parent):
from wx.lib.agw.floatspin import FloatSpin
import wx
self.widget = wx.SpinCtrlDouble(parent, -1, min = self.min, max = self.max)
self.widget.SetDigits(0)
Expand All @@ -188,13 +187,37 @@ def get_specific_widget(self, parent):
self.widget.GetValue = lambda: int(orig())
return self.widget

def MySpin(parent, digits, *args, **kw):
# in GTK 3.[01], spinner is not large enough to fit text
# Could be a class, but use function to avoid load errors if wx
# not installed
# If native wx.SpinCtrlDouble has problems in different platforms
# try agw
# from wx.lib.agw.floatspin import FloatSpin
import wx
sp = wx.SpinCtrlDouble(parent, *args, **kw)
# sp = FloatSpin(parent)
sp.SetDigits(digits)
# sp.SetValue(kw['initial'])
def fitValue(ev):
text = '%%.%df'% digits % sp.Max
# native wx.SpinCtrlDouble does not return good size
# in GTK 3.0
tex = sp.GetTextExtent(text)
tsz = sp.GetSizeFromTextSize(tex.x)

if sp.MinSize.x < tsz.x:
# print('fitValue', getattr(sp, 'setting', None), sp.Value, sp.Digits, tsz.x)
sp.MinSize = tsz
# sp.Size = tsz
# sp.Bind(wx.EVT_TEXT, fitValue)
fitValue(None)
return sp

class FloatSpinSetting(SpinSetting):

def get_specific_widget(self, parent):
from wx.lib.agw.floatspin import FloatSpin
import wx
self.widget = wx.SpinCtrlDouble(parent, -1, initial = self.value, min = self.min, max = self.max, inc = self.increment)
self.widget.SetDigits(2)
self.widget = MySpin(parent, 2, initial = self.value, min = self.min, max = self.max, inc = self.increment)
return self.widget

class BooleanSetting(wxSetting):
Expand Down Expand Up @@ -256,10 +279,11 @@ def get_widget(self, parent):
build_dimensions = parse_build_dimensions(self.value)
self.widgets = []
def w(val, m, M):
self.widgets.append(wx.SpinCtrlDouble(parent, -1, initial = val, min = m, max = M))
self.widgets[-1].SetDigits(2)
addlabel = lambda name, pos: self.widget.Add(wx.StaticText(parent, -1, name), pos = pos, flag = wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border = 5)
addwidget = lambda *pos: self.widget.Add(self.widgets[-1], pos = pos, flag = wx.RIGHT, border = 5)
self.widgets.append(MySpin(parent, 2, initial = val, min = m, max = M))
def addlabel(name, pos):
self.widget.Add(wx.StaticText(parent, -1, name), pos = pos, flag = wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border = 5)
def addwidget(*pos):
self.widget.Add(self.widgets[-1], pos = pos, flag = wx.RIGHT | wx.EXPAND, border = 5)
self.widget = wx.GridBagSizer()
addlabel(_("Width"), (0, 0))
w(build_dimensions[0], 0, 2000)
Expand All @@ -281,13 +305,13 @@ def w(val, m, M):
addwidget(1, 5)
addlabel(_("X home pos."), (2, 0))
w(build_dimensions[6], -2000, 2000)
self.widget.Add(self.widgets[-1], pos = (2, 1))
addwidget(2, 1)
addlabel(_("Y home pos."), (2, 2))
w(build_dimensions[7], -2000, 2000)
self.widget.Add(self.widgets[-1], pos = (2, 3))
addwidget(2, 3)
addlabel(_("Z home pos."), (2, 4))
w(build_dimensions[8], -2000, 2000)
self.widget.Add(self.widgets[-1], pos = (2, 5))
addwidget(2, 5)
return self.widget

def update(self):
Expand Down

0 comments on commit 5d42c19

Please sign in to comment.