Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions AttributeEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ def __init__(self, parent, id, model):

###
def __do_layout(self):
"""
"""
sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
sizer_1.Add(self._sb_input, 0, wx.ADJUST_MINSIZE, 0)
sizer_1.Add(self._sb_output, 0, wx.ADJUST_MINSIZE, 0)
Expand All @@ -252,30 +254,42 @@ def __do_layout(self):

###
def __set_binding(self):
"""
"""
self._sb_input.Bind(wx.EVT_TEXT, self.OnInput)
self._sb_output.Bind(wx.EVT_TEXT, self.OnOuput)
self.Bind(wx.EVT_CLOSE, self.OnClose)

@Post_Undo
def OnInput(self, event):
"""
"""
self.__state['input'] = self._sb_input.GetValue()
self.notify()

@Post_Undo
def OnOuput(self, event):
"""
"""
self.__state['output'] = self._sb_output.GetValue()
self.notify()

###
def GetState(self):
"""
"""
return self.__state

###
def Undo(self):
"""
"""
self.canvas.Undo()

###
def OnClose(self, event):
"""
"""
self.Destroy()
event.Skip()

Expand Down
2 changes: 1 addition & 1 deletion Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def Load(filename, label):
else:
### mandatory due to the LoadFile call before
m.label = label

print(filename,m)
return AMDComponent.ChekFilename(filename, m)

@staticmethod
Expand Down
141 changes: 102 additions & 39 deletions Container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2780,8 +2780,20 @@ def select(self, item=None):

item.OnSelect(None)
if isinstance(item, Connectable):
self.nodes.extend([INode(item, n, self) for n in range(item.input)])
self.nodes.extend([ONode(item, n, self) for n in range(item.output)])
for n in range(item.input):
if n in item.getInputLabels():
self.nodes.append(INode(item, n, self, item.getInputLabel(n)))
else:
self.nodes.append(INode(item, n, self))

for n in range(item.output):
if n in item.getOutputLabels():
self.nodes.append(ONode(item, n, self, item.getOutputLabel(n)))
else:
self.nodes.append(ONode(item, n, self))

# self.nodes.extend([INode(item, n, self) for n in range(item.input)])
# self.nodes.extend([ONode(item, n, self) for n in range(item.output)])
if isinstance(item, Resizeable):
self.nodes.extend([ResizeableNode(item, n, self) for n in range(len(item.x))])

Expand Down Expand Up @@ -3203,7 +3215,6 @@ class ConnectionShape(LinesShape, Resizeable, Selectable, Structurable):
""" ConnectionShape class
"""


def __init__(self):
""" Constructor
"""
Expand All @@ -3221,8 +3232,6 @@ def __init__(self):
def __setstate__(self, state):
""" Restore state from the unpickled state values.
"""


####################################" Just for old model
if 'touch_list' not in state: state['touch_list'] = []
if 'font' not in state: state['font'] = [FONT_SIZE, 74, 93, 700, u'Arial']
Expand All @@ -3231,19 +3240,28 @@ def __setstate__(self, state):
self.__dict__.update(state)

def setInput(self, item, index):
"""
"""
self.input = (item, index)

def setOutput(self, item, index):
"""
"""
self.output = (item, index)

def getInput(self):
"""
"""
return self.input

def getOutput(self):
"""
"""
return self.output

def draw(self, dc):

"""
"""
if self.input:
self.x[0], self.y[0] = self.input[0].getPortXY('output', self.input[1])

Expand Down Expand Up @@ -3431,6 +3449,8 @@ def OnProperties(self, event):
f.Show()

def OnPluginsManager(self, event):
"""
"""
canvas = event.GetEventObject()
f = PluginsGUI.ModelPluginsManager( parent=canvas.GetParent(),
id=wx.NewIdRef(),
Expand Down Expand Up @@ -3534,6 +3554,12 @@ def update(self, concret_subject = None):
i = diagram.priority_list.index(old_label)
diagram.priority_list[i] = new_label

### clear custom port labels if their number change
# if prop == 'input':
# self.setInputLabels({})
# if prop == 'output':
# self.setOutputLabels({})

### clear manager : direct update only for image_path propertie
if val not in ('',[],{}) or (prop == 'image_path' and val == ""):
canvas = concret_subject.canvas
Expand Down Expand Up @@ -3790,15 +3816,16 @@ def __setstate__(self, state):
if 'label_pos' not in state: state['label_pos'] = 'center'
if 'input_direction' not in state: state['input_direction'] = 'ouest'
if 'output_direction' not in state: state['output_direction'] = 'est'
##############################################
if '_input_labels' not in state: state['_input_labels'] = {}
if '_output_labels' not in state: state['_output_labels'] = {}
##############################################

self.__dict__.update(state)
if new_class:
self.__class__ = new_class

###
def __getstate__(self):
"""
"""
"""Return state values to be pickled."""
return Achievable.__getstate__(self)

Expand All @@ -3808,7 +3835,7 @@ def __getattr__(self, name):
"""
if name == 'dump_attributes':
#return ['model_path', 'python_path', 'args'] + self.GetAttributes()
return ['args'] + self.GetAttributes()
return ['args'] + Connectable.DUMP_ATTR + self.GetAttributes()
#=======================================================================
elif name == 'dump_abstr_attributes':
### Atomic model has no abstract attributes
Expand All @@ -3817,9 +3844,9 @@ def __getattr__(self, name):
else:
raise AttributeError(name)


def draw(self, dc):

"""
"""
if self.selected:
### inform about the nature of the block using icon
name = 'atomic3.png' if self.model_path != "" else 'pythonFile.png' if self.python_path.endswith('.py') else 'pyc.png'
Expand All @@ -3832,7 +3859,6 @@ def draw(self, dc):
def OnLeftDClick(self, event):
""" On left double click event has been invoked.
"""

self.OnProperties(event)
event.Skip()

Expand Down Expand Up @@ -3994,6 +4020,8 @@ def __setstate__(self, state):
if 'label_pos' not in state:state['label_pos'] = 'center'
if 'input_direction' not in state: state['input_direction'] = 'ouest'
if 'output_direction' not in state: state['output_direction'] = 'est'
if '_input_labels' not in state: state['_intput_labels'] = {}
if '_output_labels' not in state: state['_output_labels'] = {}
#####################################

self.__dict__.update(state)
Expand All @@ -4009,17 +4037,17 @@ def __getattr__(self, name):

if name == 'dump_attributes':
#return ['shapes', 'priority_list', 'constants_dico', 'model_path', 'python_path','args'] + self.GetAttributes()
return ['shapes', 'priority_list', 'constants_dico','args'] + self.GetAttributes()
return ['shapes', 'priority_list', 'constants_dico','args'] + Connectable.DUMP_ATTR +self.GetAttributes()
#=======================================================================
elif name == 'dump_abstr_attributes':
return Abstractable.DUMP_ATTR if hasattr(self, 'layers') and hasattr(self, 'current_level') else []
#======================================================================
else:
raise AttributeError(name)


def draw(self, dc):

"""
"""
if self.selected:
### inform about the nature of the block using icon
img = wx.Bitmap(os.path.join(ICON_PATH_16_16, 'coupled3.png'), wx.BITMAP_TYPE_ANY)
Expand Down Expand Up @@ -4100,25 +4128,6 @@ def OnLeftDown(self, event):
self.cf.deselect(self.item)
event.Skip()

def OnRightDown(self, event):
""" Left Down click has been invoked
"""
### dialog to ask new port label

old_label = self.label

d = wx.TextEntryDialog(None, _('New Label'), value = old_label, style=wx.OK)
d.ShowModal()

### new label
new_label = d.GetValue()

### only if new and old label are different
if new_label != old_label:
self.label = new_label

event.Skip()

def HitTest(self,x,y):
""" Collision detection method.
"""
Expand All @@ -4138,12 +4147,12 @@ class INode(ConnectableNode):
""" INode(item, index, cf)
"""

def __init__(self, item, index, cf):
def __init__(self, item, index, cf, label=None):
""" Constructor.
"""
ConnectableNode.__init__(self, item, index, cf)

self.label = f"in{self.index}"
self.label = f"in{self.index}" if not label else label

def move(self, x, y):
""" Move method.
Expand All @@ -4156,6 +4165,38 @@ def move(self, x, y):
self.cf.showOutputs()
self.cf.select(ci)

def OnRightDown(self, event):
""" Left Down click has been invoked
"""
### dialog to ask new port label

menu = Menu.NodePopupMenu(self)
### Show popup_menu
canvas = event.GetEventObject()
canvas.PopupMenu(menu, event.GetPosition())
### destroy menu local variable
menu.Destroy()

event.Skip()

def OnEditLabel(self, event):
""" Function called by the OnRightDown call event function
"""
### old label
old_label = self.label

### ask tne new label
d = wx.TextEntryDialog(None, _('New Input Label'), value = old_label, style=wx.OK)
d.ShowModal()

### new label
new_label = d.GetValue()

### only if new and old label are different
if new_label != old_label:
self.label = new_label
self.item.addInputLabels(self.index, self.label)

def leftUp(self, items):
""" Left up action has been invocked.
"""
Expand Down Expand Up @@ -4211,12 +4252,12 @@ class ONode(ConnectableNode):
""" ONode(item, index, cf)
"""

def __init__(self, item, index, cf):
def __init__(self, item, index, cf, label=None):
""" Constructor.
"""
ConnectableNode.__init__(self, item, index, cf)

self.label = "out%d"%self.index
self.label = "out%d"%self.index if not label else label

def move(self, x, y):
""" Moving method.
Expand All @@ -4229,6 +4270,26 @@ def move(self, x, y):
self.cf.showInputs()
self.cf.select(ci)

def OnRightDown(self, event):
""" Left Down click has been invoked
"""
### dialog to ask new port label

old_label = self.label

d = wx.TextEntryDialog(None, _('New Output Label'), value = old_label, style=wx.OK)
d.ShowModal()

### new label
new_label = d.GetValue()

### only if new and old label are different
if new_label != old_label:
self.label = new_label
self.item.addOutputLabels(self.index, self.label)

event.Skip()

def leftUp(self, items):
""" Left up action has been invocked
"""
Expand Down Expand Up @@ -4379,6 +4440,8 @@ def __setstate__(self, state):
state['attributes'].insert(1,'label_pos')
if 'output_direction' not in state: state['output_direction'] ="est"
if 'input_direction' not in state: state['input_direction'] = "ouest"
if '_input_labels' not in state: state['_input_labels'] = {}
if '_output_labels' not in state: state['_output_labels'] = {}
##############################################

self.__dict__.update(state)
Expand Down
19 changes: 19 additions & 0 deletions Menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,25 @@ def __init__(self, parent):

### Bind is not necessary because ID_EXIT_DAIGRAM and ID_DETACH_DIAGRAM are already binded

class NodePopupMenu(wx.Menu):
""" Node popup menu
"""

def __init__(self, parent):
""" Constructor.
"""
wx.Menu.__init__(self)

edit = wx.MenuItem(self, -1, _('Edit'), _('Edit label'))

edit.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH_16_16,'edit.png')))

AppendItem = self.AppendItem if wx.VERSION_STRING < '4.0' else self.Append

AppendItem(edit)

### bind event with new OnDeletePage
self.Bind(wx.EVT_MENU, parent.OnEditLabel, edit)
class PropertiesCtrlPopupMenu(wx.Menu):
""" PropertiesCtrl popup menu.
"""
Expand Down
Loading