Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxGUI/gmodeler: dialogs code refactoring #3816

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 44 additions & 33 deletions gui/wxpython/gmodeler/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,10 @@ def __init__(self, parent, shape, title=_("Data properties")):
self.parent = parent
self.shape = shape

label, etype = self._getLabel()
self.etype = etype
label, self.etype = self._getLabel()
SimpleDialog.__init__(self, parent, title)

self.element = Select(
parent=self.panel,
type=self.shape.GetPrompt(),
validator=SimpleValidator(callback=self.ValidatorCallback),
)
if shape.GetValue():
self.element.SetValue(shape.GetValue())
self.element = self._createElementControl(shape)

self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOK)
self.Bind(wx.EVT_BUTTON, self.OnCancel, self.btnCancel)
Expand All @@ -86,6 +79,18 @@ def __init__(self, parent, shape, title=_("Data properties")):
self._layout()
self.SetMinSize(self.GetSize())

def _createElementControl(self, shape):
"""Create Select element and set its value."""
element = Select(
parent=self.panel,
type=self.shape.GetPrompt(),
validator=SimpleValidator(callback=self.ValidatorCallback),
)
if shape.GetValue():
element.SetValue(shape.GetValue())

return element

def _getLabel(self):
etype = False
prompt = self.shape.GetPrompt()
Expand Down Expand Up @@ -549,6 +554,11 @@ def GetCondition(self):
"""Get loop condition"""
return self.condText.GetValue()

def SetSizes(self):
"""Set default and minimal size."""
self.SetMinSize(self.GetSize())
self.SetSize((500, 400))


class ModelLoopDialog(ModelItemDialog):
"""Loop properties dialog"""
Expand All @@ -573,8 +583,7 @@ def __init__(
self.btnSeries.Bind(wx.EVT_BUTTON, self.OnSeries)

self._layout()
self.SetMinSize(self.GetSize())
self.SetSize((500, 400))
self.SetSizes()

def _layout(self):
"""Do layout"""
Expand Down Expand Up @@ -664,8 +673,7 @@ def __init__(
self.itemListElse.Populate(self.parent.GetModel().GetItems())

self._layout()
self.SetMinSize(self.GetSize())
self.SetSize((500, 400))
self.SetSizes()

def _layout(self):
"""Do layout"""
Expand Down Expand Up @@ -745,21 +753,27 @@ def __init__(
listmix.ListCtrlAutoWidthMixin.__init__(self)
listmix.TextEditMixin.__init__(self)

i = 0
for col in columns:
self.InsertColumn(i, col)
self.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER)
i += 1
self.InsertColumns(columns)

self.itemDataMap = {} # requested by sorter
self.itemCount = 0

self.BindButtons()

def BindButtons(self):
"""Bind signals to buttons."""
self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnBeginEdit)
self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEndEdit)
self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightUp) # wxMSW
self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp) # wxGTK

def InsertColumns(self, columns):
"""INsert columns and set their width."""
for i, col in enumerate(columns):
self.InsertColumn(i, col)
self.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER)

def OnBeginEdit(self, event):
"""Editing of item started"""
column = event.GetColumn()
Expand Down Expand Up @@ -799,7 +813,7 @@ def GetData(self):

def Populate(self, data):
"""Populate the list"""
self.itemDataMap = {}
self.DeleteAllItems()
i = 0
for name, values in data.items():
self.itemDataMap[i] = [
Expand All @@ -808,20 +822,16 @@ def Populate(self, data):
values.get("value", ""),
values.get("description", ""),
]
i += 1

self.itemCount = len(self.itemDataMap.keys())
self.DeleteAllItems()
i = 0
for name, vtype, value, desc in self.itemDataMap.values():
index = self.InsertItem(i, name)
self.SetItem(index, 0, name)
self.SetItem(index, 1, vtype)
self.SetItem(index, 2, value)
self.SetItem(index, 3, desc)
self.SetItem(index, 1, values["type"])
self.SetItem(index, 2, values.get("value", ""))
self.SetItem(index, 3, values.get("description", ""))
self.SetItemData(index, i)
i += 1

self.itemCount = len(data)

def Append(self, name, vtype, value, desc):
"""Append new item to the list

Expand Down Expand Up @@ -1140,11 +1150,12 @@ def OnBeginEdit(self, event):

def OnCheckItem(self, index, flag):
"""Item checked/unchecked"""
name = self.GetLabel()
if name == "IfBlockList" and self.window:
self.window.OnCheckItemIf(index, flag)
elif name == "ElseBlockList" and self.window:
self.window.OnCheckItemElse(index, flag)
if self.window:
name = self.GetLabel()
if name == "IfBlockList":
self.window.OnCheckItemIf(index, flag)
elif name == "ElseBlockList":
self.window.OnCheckItemElse(index, flag)

def GetItems(self):
"""Get list of selected actions"""
Expand Down
Loading