Skip to content

Commit 309e2a3

Browse files
authored
Merge pull request #387 from capocchi/version-5.1
Version 5.1
2 parents e43cbec + 5f0e9f6 commit 309e2a3

14 files changed

+2479
-1171
lines changed

devsimpy/AIPrompterDialog.py

Lines changed: 234 additions & 88 deletions
Large diffs are not rendered by default.

devsimpy/CheckerGUI.py

Lines changed: 328 additions & 229 deletions
Large diffs are not rendered by default.

devsimpy/ConnectDialog.py

Lines changed: 162 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
32
'''
43
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
54
# ConnectDialog.py ---
@@ -10,100 +9,180 @@
109
# --------------------------------
1110
# Version 1.0 last modified: 03/15/2020
1211
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
13-
#
14-
# GENERAL NOTES AND REMARKS:
15-
#
16-
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
17-
18-
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19-
#
20-
# GLOBAL VARIABLES AND FUNCTIONS
21-
#
22-
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2312
'''
2413

2514
import wx
2615

2716
_ = wx.GetTranslation
28-
2917
from Utilities import load_and_resize_image
3018

3119
def function(obj, i):
32-
return 'iPort %d'%i if obj[i].__class__.__name__ == "INode" else 'oPort %d'%i
20+
return 'iPort %d' % i if obj[i].__class__.__name__ == "INode" else 'oPort %d' % i
3321

3422
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
3523
#
3624
# CLASSES DEFINITION
3725
#
3826
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
3927

40-
###
41-
class ConnectDialog(wx.Frame):
42-
def __init__(self, parent, id, title, sn="Source", snL=[None,None], tn="Target", tnL=[None,None]):
43-
wx.Frame.__init__(self, parent, id, title, size=(240,200), style= wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU)
44-
45-
# local copy
46-
self.sn = sn
47-
self.tn = tn
48-
self.parent = parent
49-
50-
self._result = [0,0]
51-
52-
L1 = [function(snL,i) for i in range(len(snL))]
53-
L2 = [function(tnL,i) for i in range(len(tnL))]
54-
55-
L1.insert(0,"%s"%_('All'))
56-
L2.insert(0,"%s"%_('All'))
57-
58-
self._label_source = wx.StaticText(self, wx.NewIdRef(), '%s'%self.sn)
59-
self._label_target = wx.StaticText(self, wx.NewIdRef(), '%s'%self.tn)
60-
self._combo_box_sn = wx.ComboBox(self, wx.NewIdRef(), choices = L1, style = wx.CB_DROPDOWN|wx.CB_READONLY)
61-
self._combo_box_tn = wx.ComboBox(self, wx.NewIdRef(), choices = L2, style = wx.CB_DROPDOWN|wx.CB_READONLY)
62-
self._button_disconnect = wx.Button(self, wx.NewIdRef(), _("Disconnect"))
63-
self._button_connect = wx.Button(self, wx.NewIdRef(), _("Connect"))
64-
65-
self._combo_box_sn.SetSelection(0)
66-
self._combo_box_tn.SetSelection(0)
67-
self._combo_box_sn.Enable(len(L1) != 2)
68-
self._combo_box_tn.Enable(len(L2) != 2)
69-
70-
self.__set_properties()
71-
self.__do_layout()
72-
self.__set_events()
73-
74-
def __set_properties(self):
75-
icon = wx.Icon()
76-
icon.CopyFromBitmap(load_and_resize_image("direct_connector.png"))
77-
self.SetIcon(icon)
78-
79-
def __do_layout(self):
80-
grid_sizer_1 = wx.GridSizer(3, 2, 0, 0)
81-
grid_sizer_1.Add(self._label_source, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
82-
grid_sizer_1.Add(self._label_target, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
83-
grid_sizer_1.Add(self._combo_box_sn, 0, wx.EXPAND)
84-
grid_sizer_1.Add(self._combo_box_tn, 0, wx.EXPAND)
85-
grid_sizer_1.Add(self._button_disconnect, 0, wx.EXPAND)
86-
grid_sizer_1.Add(self._button_connect, 0, wx.EXPAND)
87-
self.SetSizer(grid_sizer_1)
88-
grid_sizer_1.Fit(self)
89-
self.Layout()
90-
self.Center()
91-
92-
def __set_events(self):
93-
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox1, self._combo_box_sn)
94-
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox2, self._combo_box_tn)
95-
96-
def EvtComboBox1(self,event):
97-
self._result[0] = event.GetSelection()
98-
99-
def EvtComboBox2(self,event):
100-
self._result[1] = event.GetSelection()
101-
102-
def GetSelectedIndex(self):
103-
return self._result
104-
105-
def GetLabelSource(self):
106-
return self._label_source.GetLabel()
107-
108-
def GetLabelTarget(self):
109-
return self._label_target.GetLabel()
28+
class ConnectDialog(wx.Dialog):
29+
def __init__(self, parent, id, title, sn="Source", snL=[None, None], tn="Target", tnL=[None, None]):
30+
super().__init__(parent, id, title, style=wx.DEFAULT_DIALOG_STYLE)
31+
32+
# local copy
33+
self.sn = sn
34+
self.tn = tn
35+
self.parent = parent
36+
self._result = [0, 0]
37+
38+
# Construire les listes de ports
39+
L1 = [function(snL, i) for i in range(len(snL))]
40+
L2 = [function(tnL, i) for i in range(len(tnL))]
41+
L1.insert(0, "%s" % _('All'))
42+
L2.insert(0, "%s" % _('All'))
43+
44+
self._source_list = L1
45+
self._target_list = L2
46+
47+
self.__init_ui()
48+
self.__set_properties()
49+
self.__set_events()
50+
51+
self.Center()
52+
53+
def __init_ui(self):
54+
"""Initialize the user interface"""
55+
56+
# Taille minimale confortable
57+
self.SetMinSize((400, 220))
58+
59+
panel = wx.Panel(self)
60+
panel.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))
61+
62+
main_sizer = wx.BoxSizer(wx.VERTICAL)
63+
64+
# --- Section Ports ---
65+
ports_box = wx.StaticBoxSizer(wx.VERTICAL, panel, _("Port Connection"))
66+
67+
ports_grid = wx.FlexGridSizer(rows=2, cols=2, vgap=10, hgap=15)
68+
ports_grid.AddGrowableCol(0, 1)
69+
ports_grid.AddGrowableCol(1, 1)
70+
71+
# Source
72+
source_label = wx.StaticText(panel, wx.NewIdRef(), _('Source: %s') % self.sn)
73+
font = source_label.GetFont()
74+
font.SetWeight(wx.FONTWEIGHT_BOLD)
75+
source_label.SetFont(font)
76+
ports_grid.Add(source_label, flag=wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
77+
78+
# Target
79+
target_label = wx.StaticText(panel, wx.NewIdRef(), _('Target: %s') % self.tn)
80+
target_label.SetFont(font)
81+
ports_grid.Add(target_label, flag=wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
82+
83+
# ComboBox Source
84+
self._combo_box_sn = wx.ComboBox(
85+
panel,
86+
wx.NewIdRef(),
87+
choices=self._source_list,
88+
style=wx.CB_DROPDOWN | wx.CB_READONLY
89+
)
90+
self._combo_box_sn.SetSelection(0)
91+
self._combo_box_sn.Enable(len(self._source_list) != 2)
92+
self._combo_box_sn.SetToolTip(_("Select source port to connect"))
93+
ports_grid.Add(self._combo_box_sn, flag=wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)
94+
95+
# ComboBox Target
96+
self._combo_box_tn = wx.ComboBox(
97+
panel,
98+
wx.NewIdRef(),
99+
choices=self._target_list,
100+
style=wx.CB_DROPDOWN | wx.CB_READONLY
101+
)
102+
self._combo_box_tn.SetSelection(0)
103+
self._combo_box_tn.Enable(len(self._target_list) != 2)
104+
self._combo_box_tn.SetToolTip(_("Select target port to connect"))
105+
ports_grid.Add(self._combo_box_tn, flag=wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)
106+
107+
ports_box.Add(ports_grid, flag=wx.ALL|wx.EXPAND, border=10)
108+
main_sizer.Add(ports_box, flag=wx.ALL|wx.EXPAND, border=15)
109+
110+
# --- Info Text ---
111+
if not self._combo_box_sn.IsEnabled() and not self._combo_box_tn.IsEnabled():
112+
info_text = wx.StaticText(panel, label=_("Only one port available on each side"))
113+
elif not self._combo_box_sn.IsEnabled():
114+
info_text = wx.StaticText(panel, label=_("Only one source port available"))
115+
elif not self._combo_box_tn.IsEnabled():
116+
info_text = wx.StaticText(panel, label=_("Only one target port available"))
117+
else:
118+
info_text = wx.StaticText(panel, label=_("Select ports to connect or disconnect"))
119+
120+
info_text.SetForegroundColour(wx.Colour(100, 100, 100))
121+
font_info = info_text.GetFont()
122+
font_info.SetPointSize(font_info.GetPointSize() - 1)
123+
info_text.SetFont(font_info)
124+
main_sizer.Add(info_text, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER, border=15)
125+
126+
# --- Buttons ---
127+
button_sizer = wx.BoxSizer(wx.HORIZONTAL)
128+
129+
self._button_disconnect = wx.Button(panel, wx.NewIdRef(), _("Disconnect"), size=(120, 32))
130+
self._button_disconnect.SetToolTip(_("Disconnect the selected ports"))
131+
button_sizer.Add(self._button_disconnect)
132+
133+
self._button_connect = wx.Button(panel, wx.NewIdRef(), _("Connect"), size=(120, 32))
134+
self._button_connect.SetDefault()
135+
self._button_connect.SetToolTip(_("Connect the selected ports"))
136+
button_sizer.Add(self._button_connect, flag=wx.LEFT, border=5)
137+
138+
main_sizer.Add(button_sizer, flag=wx.ALL|wx.ALIGN_RIGHT, border=15)
139+
140+
panel.SetSizer(main_sizer)
141+
142+
# Ajuster la taille
143+
main_sizer.SetSizeHints(self)
144+
panel.Layout()
145+
self.Fit()
146+
147+
def __set_properties(self):
148+
"""Set window properties"""
149+
icon = wx.Icon()
150+
icon.CopyFromBitmap(load_and_resize_image("direct_connector.png"))
151+
self.SetIcon(icon)
152+
153+
def __set_events(self):
154+
"""Bind events"""
155+
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox1, self._combo_box_sn)
156+
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox2, self._combo_box_tn)
157+
self.Bind(wx.EVT_BUTTON, self.OnConnect, self._button_connect)
158+
self.Bind(wx.EVT_BUTTON, self.OnDisconnect, self._button_disconnect)
159+
160+
def EvtComboBox1(self, event):
161+
"""Handle source combobox selection"""
162+
self._result[0] = event.GetSelection()
163+
164+
def EvtComboBox2(self, event):
165+
"""Handle target combobox selection"""
166+
self._result[1] = event.GetSelection()
167+
168+
def OnConnect(self, event):
169+
"""Handle Connect button click"""
170+
# Vous pouvez ajouter une logique de validation ici
171+
self.EndModal(wx.ID_OK)
172+
173+
def OnDisconnect(self, event):
174+
"""Handle Disconnect button click"""
175+
# Vous pouvez ajouter une logique de déconnexion ici
176+
self.EndModal(wx.ID_CANCEL)
177+
178+
def GetSelectedIndex(self):
179+
"""Return the selected indices"""
180+
return self._result
181+
182+
def GetLabelSource(self):
183+
"""Return the source label"""
184+
return self.sn
185+
186+
def GetLabelTarget(self):
187+
"""Return the target label"""
188+
return self.tn

0 commit comments

Comments
 (0)