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
4 changes: 0 additions & 4 deletions Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def GetClass(elem):
# else:
# DomainClass = clsmembers[os.path.basename(elem).split('.')[0]]
# sys.stderr.write(_("Class unknown..."))
# print(DomainClass)
# return None

### return only the class that inherite of DomainBehavoir or DomainStructure which are present in the clsmembers dict
Expand Down Expand Up @@ -373,7 +372,6 @@ def Rename(filename:str, new_name:str)->bool:

if temp_file:

#print("Replace %s by %s into %s"%(old_name, new_name, new_temp_file))
### replace in new_temp_file file
replaceAll(new_temp_file, old_name, new_name)

Expand Down Expand Up @@ -844,7 +842,6 @@ def OnEditor(self, event):
# loading file in DEVSimPy editor windows (self.text)
try:


editorFrame = Editor.GetEditor(None, wx.NewIdRef(), ''.join([name,' - ',model_path]), obj=self, file_type='block')

# if zipfile.is_zipfile(model_path):
Expand Down Expand Up @@ -975,7 +972,6 @@ def GetModule(filename):
# import pkgutil
# search_path = [dir_name] # set to None to see all modules importable from sys.path
# all_modules = [x[1] for x in pkgutil.iter_modules(path=search_path)]
# print(all_modules)
else:
sys.stdout.write("Import error 0: " + " module not found")
module = None
Expand Down
114 changes: 63 additions & 51 deletions Container.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,10 @@ def OnSimulation(self, event):
### Check if models have the same label
L = diagram.GetLabelList([])
if len(L)!=len(set(L)):
model_with_same_label = [k for k,v in Counter(L).items() if v>1]
model_with_same_label = [f"-{k}" for k,v in Counter(L).items() if v>1]
txt = "\n".join(model_with_same_label)
wx.MessageBox(_("It seems that the flowwing models have same label:\n \
- %s \n\
wx.MessageBox(_("It seems that the following models have a same label:\n\
%s\n\
\nIf you plan to use Flat simulation algorithm, all model must have a unique label.")%txt, _("Simulation Manager"))

### set the name of diagram
Expand Down Expand Up @@ -1543,6 +1543,7 @@ def __init__(self,\
Subject.__init__(self)

self.SetBackgroundColour(wx.WHITE)
self.SetBackgroundStyle(wx.BG_STYLE_PAINT)

self.name = name
self.parent = parent
Expand Down Expand Up @@ -1573,6 +1574,7 @@ def __init__(self,\

### improve drawing with not condsidering the resizeable node when connect blocks
self.resizeable_nedeed = True
self.refresh_need = True

### attach canvas to notebook 1 (for update)
try:
Expand Down Expand Up @@ -1770,10 +1772,11 @@ def DoDrawing(self, dc):

shapes = self.diagram.shapes
nodes = self.nodes

### resizeable node not nedeed for connection process (dragging mouse with left button pressed - see when self.resizeable_nedeed is False)
if not self.resizeable_nedeed:
nodes = [n for n in nodes if not isinstance(n,ResizeableNode)]
items = shapes + nodes
items = iter(shapes + nodes)

for item in items:
try:
Expand Down Expand Up @@ -1813,13 +1816,15 @@ def OnPaint(self, event):
backBrush = wx.Brush(backColour, wx.BRUSHSTYLE_SOLID)
pdc.SetBackground(backBrush)
pdc.Clear()

### to insure the correct redraw when window is scolling
### http://markmail.org/thread/hytqkxhpdopwbbro#query:+page:1+mid:635dvk6ntxsky4my+state:results
self.PrepareDC(pdc)

self.DoDrawing(pdc)

del pdc

@Post_Undo
def OnLock(self, event):
"""
Expand Down Expand Up @@ -1861,7 +1866,7 @@ def OnRightDown(self, event):
menu.Destroy()

### Refresh canvas
self.Refresh()
# self.Refresh()

### Focus on canvas
#wx.CallAfter(self.SetFocus)
Expand Down Expand Up @@ -2383,7 +2388,9 @@ def OnLeftDown(self,event):
self.CaptureMouse()
self.overlay = wx.Overlay()
if isinstance(event,wx.MouseEvent):
self.selectionStart = event.Position
# point = event.GetPosition()
point = self.getEventCoordinates(event)
self.selectionStart = point

else:

Expand Down Expand Up @@ -2417,7 +2424,7 @@ def OnLeftDown(self,event):
self.__state['canvas'] = self
self.notify()

self.Refresh()
# self.Refresh()

###
@Post_Undo
Expand Down Expand Up @@ -2500,7 +2507,7 @@ def OnLeftUp(self, event):
### dont avoid the link
remove = False

except AttributeError:
except Exception:
### TODO: I dont now why !!!
pass

Expand All @@ -2521,35 +2528,39 @@ def OnLeftUp(self, event):
except:
sys.stdout.write(_("Error in Release Mouse!"))
else:
self.permRect = None
if isinstance(event,wx.MouseEvent):
if wx.VERSION_STRING < '4.0':
self.permRect = wx.RectPP(self.selectionStart, event.Position)
else:
self.permRect = wx.Rect(self.selectionStart, event.Position)

self.selectionStart = None
self.overlay.Reset()

self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
point = self.getEventCoordinates(event)
if self.selectionStart != point:
self.permRect = wx.Rect(self.selectionStart, point)

## gestion des shapes qui sont dans le rectangle permRect
for s in self.diagram.GetShapeList():
x = s.x[0]*self.scalex
y = s.y[0]*self.scaley
w = (s.x[1]-s.x[0])*self.scalex
h = (s.y[1]-s.y[0])*self.scaley

recS = wx.Rect(x,y,w,h)

# si les deux rectangles se chevauche
try:
bool = self.permRect.ContainsRect(recS) if wx.VERSION_STRING < '4.0' else self.permRect.Contains(recS)
if bool:
self.select(s)
except AttributeError as info:
if self.permRect:
raise AttributeError(_("use >= wx-2.8-gtk-unicode library: %s")%info)
#clear out any existing drawing
if self.permRect:

self.selectionStart = None
self.overlay.Reset()

self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))

## gestion des shapes qui sont dans le rectangle permRect
for s in self.diagram.GetShapeList():
x,y = self.getScalledCoordinates(s.x[0],s.y[0])
# x = s.x[0]*self.scalex
# y = s.y[0]*self.scaley
w = (s.x[1]-s.x[0])*self.scalex
h = (s.y[1]-s.y[0])*self.scaley

recS = wx.Rect(x,y,w,h)

# print(s,x,y,w,h,self.permRect.Contains(recS))

# si les deux rectangles se chevauche
try:
if self.permRect.Contains(recS):
self.select(s)
except AttributeError as info:
if self.permRect:
raise AttributeError(_("use >= wx-2.8-gtk-unicode library: %s")%info)
#clear out any existing drawing
else:
### shape is None and we remove the connectionShape
for item in [s for s in self.select() if isinstance(s, ConnectionShape)]:
Expand Down Expand Up @@ -2674,7 +2685,8 @@ def ShowQuickAttributeEditor(self, selectedShape:list)->None:
def OnIdle(self,event):
"""
"""
self.Refresh(False)
if self.refresh_need:
self.Refresh(False)

###
def OnMotion(self, event):
Expand All @@ -2686,10 +2698,14 @@ def OnMotion(self, event):

sc = self.getSelectedShapes()

self.refresh_need = True
self.resizeable_nedeed = True

if event.Dragging() and event.LeftIsDown():

self.diagram.modify = False



if len(sc) == 0:
# User is dragging the mouse, check if
# left button is down
Expand All @@ -2707,11 +2723,14 @@ def OnMotion(self, event):
ctx.SetBrush(wx.Brush(wx.Colour(229,229,229,80)))

try:
ctx.DrawRectangle(*wx.Rect(self.selectionStart, event.Position))
ctx.DrawRectangle(*wx.Rect(self.selectionStart, event.GetPosition()))
except TypeError:
pass

del odc

### no need to refresh in order to qhpw the rectangle
self.refresh_need = False
# else:
# self.Refresh(False)
else:
Expand All @@ -2726,16 +2745,14 @@ def OnMotion(self, event):

for s in sc:
s.move(x,y)

self.resizeable_nedeed = True

### change cursor when resizing model
if isinstance(s, ResizeableNode) and cursor != wx.StockCursor(wx.CURSOR_SIZING):
cursor = wx.StockCursor(wx.CURSOR_SIZING)

### change cursor when connectionShape hit a node
elif isinstance(s, ConnectionShape):
self.resizeable_nedeed = False

### dot trace to prepare connection
if len(s.pen)>2:
s.pen[2]= wx.PENSTYLE_DOT
Expand All @@ -2746,6 +2763,8 @@ def OnMotion(self, event):
for node in [n for n in self.nodes if isinstance(n, ConnectableNode) and n.HitTest(point[0], point[1])]:
if cursor != wx.StockCursor(wx.CURSOR_CROSS):
cursor = wx.StockCursor(wx.CURSOR_CROSS)

self.resizeable_nedeed = False

### update the cursor
self.SetCursor(cursor)
Expand Down Expand Up @@ -2901,7 +2920,7 @@ def select(self, item=None):
if item.output:
block, n = item.output
self.nodes.append(INode(block, n, self, block.getInputLabel(n)))
# print(item.input, item.output)


if isinstance(item, Resizeable):
self.nodes.extend([ResizeableNode(item, n, self) for n in range(len(item.x))])
Expand Down Expand Up @@ -4541,13 +4560,6 @@ def OnRightDown(self, event):
### destroy menu local variable
menu.Destroy()

# def OnLeftDClick(self, event):
# if isinstance(self.item, ConnectionShape):
# # print(self.item.getInput(), self.item.getOutput())
# pass

# return super().OnLeftDClick(event)

def HitTest(self,x,y):
""" Collision detection method.
"""
Expand Down
1 change: 0 additions & 1 deletion Decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def wrapper(*args, **kw):
sortby = 'cumulative'
ps = pstats.Stats(pr).sort_stats(sortby)
ps.dump_stats(prof_name)
#print(s.getvalue())

else:
r = func(*args, **kw)
Expand Down
28 changes: 20 additions & 8 deletions Editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def DoSaveFile(self, code):
self.parent.toolbar.EnableTool(self.parent.save.GetId(), False)

### status bar notification
self.parent.Notification(False, _('%s saved') % fic_filename, '', '')
self.parent.Notification(False, _('%s saved') % fic_filename.replace("*",""), '', '')

### NOTE: EditionNotebook :: @WriteFile => Write with correct encode
@staticmethod
Expand Down Expand Up @@ -1732,7 +1732,7 @@ def GetStatusBar(self):
"""
sb = self.CreateStatusBar()
sb.SetFieldsCount(3)
sb.SetStatusWidths([-5, -3, -1])
sb.SetStatusWidths([-2, -2, -5])
return sb

### NOTE: Editor :: ToggleStatusBar => Event for show or hide status bar
Expand Down Expand Up @@ -1923,7 +1923,7 @@ def __init__(self, parent, id, title, block):
### choices object is ordderd dict to associate handlers
if self.cb:
if not self.cb.isCMD():
self._choices = collections.OrderedDict([(_('New peek'),self.OnPeek),
self._choices = collections.OrderedDict([(_('New peek'),self.OnPeek), (_('New all peek'),self.OnAllPeek),
(_('New poke'),self.OnPoke), (_('New hold in state'),self.OnInsertHoldInState), (_('New passivate in state'),self.OnInsertPassivateInState),
(_('New passivate state'),self.OnInsertPassivateState), (_('New Phase test'),self.OnInsertPhaseIs), (_('New debugger stdout'),self.OnInsertDebug),
(_('Get state'),self.OnInsertGetState), (_('Get sigma'),self.OnInsertGetSigma), (_('Get message value'),self.OnInsertGetMsgValue)])
Expand Down Expand Up @@ -1956,8 +1956,8 @@ def OnPeek(self, *args)->None:
def OnPoke(self, *args)->None:
"""Insert the poke statement.
"""
sins = list(map(str, list(range(self.cb.input if hasattr(self.cb, 'output') else 10))))
dlg = wx.SingleChoiceDialog(self, _('Port number'), _('Which port?'), sins, wx.CHOICEDLG_STYLE)
souts = list(map(str, list(range(self.cb.output if hasattr(self.cb, 'output') else 10))))
dlg = wx.SingleChoiceDialog(self, _('Port number'), _('Which port?'), souts, wx.CHOICEDLG_STYLE)
port = dlg.GetStringSelection() if dlg.ShowModal() == wx.ID_OK else None
dlg.Destroy()

Expand All @@ -1966,6 +1966,20 @@ def OnPoke(self, *args)->None:
cp.AddText("return self.poke(self.OPorts[%d], Message(<>, self.timeNext))"%int(port))
self.Notification(True, _('%s modified' % (os.path.basename(cp.GetFilename()))), '', '')

def OnAllPeek(self, *args):
""" Insert the loop to peek all input ports.
"""

txt = """
for p in self.IPorts:
msg = self.peek(p, *args)
if msg:
v = self.getMsgValue(msg)
"""
cp = self.nb.GetCurrentPage()
cp.AddText(txt)
self.Notification(True, _('%s modified' % (os.path.basename(cp.GetFilename()))), '', '')

def OnCombo(self, event):
""" Combobox for the text insert function.
"""
Expand Down Expand Up @@ -2462,7 +2476,7 @@ def __init__(self, parent, id, title, block):

EditorPanel.__init__(self, parent, id, title)
BlockBase.__init__(self, parent, id, title, block)

#if not parent:
#self.SetIcon(self.MakeIcon(wx.Image(os.path.join(ICON_PATH_16_16, 'pythonFile.png'), wx.BITMAP_TYPE_PNG)))
#self.ConfigureGUI()
Expand All @@ -2477,8 +2491,6 @@ def ConfigureTB(self):
#tb = self.GetToolBar()
self.toolbar.InsertSeparator(self.toolbar.GetToolsCount())



### combo to insert tips text
cbID = wx.NewIdRef()
self.toolbar.AddControl(wx.ComboBox(self.toolbar, cbID, _("Choose to insert in place"), choices=self.getChoices(),size=(160,-1), style=wx.CB_DROPDOWN))
Expand Down
5 changes: 3 additions & 2 deletions Menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,9 @@ def __init__(self, shape, event):
Rename_menu = AppendItem(rename)

self.AppendSeparator()
# pour tout les model sur le canvas, rangés par ordre alphabetique, ormis les connection et le model que l'on veut connecter (la source)
for label,item in sorted([(a.label,a) for a in self.__canvas.GetDiagram().GetShapeList() if a != shape and not isinstance(a, Container.ConnectionShape)]):

# pour tout les models sur le canvas, rangés par ordre alphabetique, ormis les connections et le modele que l'on veut connecter (la source)
for label,item in sorted([(a.label,a) for a in self.__canvas.GetDiagram().GetShapeList() if a != shape and not isinstance(a, Container.ConnectionShape)], key = lambda x: x[0]):
# avoid connections like: iPort->iPort, oPort->oPort
if (isinstance(shape, Container.iPort) and not isinstance(item, Container.iPort)) or (isinstance(shape, Container.oPort) and not isinstance(item, Container.oPort)) or isinstance(shape, Container.Block):
new_item = wx.MenuItem(connectable_subMenu, wx.NewIdRef(), label)
Expand Down
1 change: 0 additions & 1 deletion Mixins/Connectable.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def addOutputLabels(self, port:int, label:str)->None:
""" add a label to the output port
"""
self._output_labels[port] = label
print(self._output_labels)

###
def getPortXY(self, type:str, num)->tuple:
Expand Down
Loading