20 # |
20 # |
21 #You should have received a copy of the GNU General Public |
21 #You should have received a copy of the GNU General Public |
22 #License along with this library; if not, write to the Free Software |
22 #License along with this library; if not, write to the Free Software |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
25 from wxPython.wx import * |
|
26 import wx |
25 import wx |
27 from types import * |
26 from types import * |
28 |
27 |
29 from Viewer import * |
28 from Viewer import * |
30 |
29 |
346 result = element.TestSegment(event.GetLogicalPosition(dc), True) |
345 result = element.TestSegment(event.GetLogicalPosition(dc), True) |
347 if result and result[1] in [EAST, WEST]: |
346 if result and result[1] in [EAST, WEST]: |
348 element.SetSelectedSegment(result[0]) |
347 element.SetSelectedSegment(result[0]) |
349 else: |
348 else: |
350 element.OnLeftUp(event, dc, self.Scaling) |
349 element.OnLeftUp(event, dc, self.Scaling) |
351 wxCallAfter(self.SetCursor, wxNullCursor) |
350 wx.CallAfter(self.SetCursor, wx.NullCursor) |
352 self.ReleaseMouse() |
351 self.ReleaseMouse() |
353 self.Refresh() |
352 self.Refresh() |
354 event.Skip() |
353 event.Skip() |
355 |
354 |
356 def OnViewerRightUp(self, event): |
355 def OnViewerRightUp(self, event): |
367 if self.IsWire(self.SelectedElement): |
366 if self.IsWire(self.SelectedElement): |
368 self.SelectedElement.SetSelectedSegment(0) |
367 self.SelectedElement.SetSelectedSegment(0) |
369 else: |
368 else: |
370 self.SelectedElement.SetSelected(True) |
369 self.SelectedElement.SetSelected(True) |
371 self.SelectedElement.OnRightUp(event, dc, self.Scaling) |
370 self.SelectedElement.OnRightUp(event, dc, self.Scaling) |
372 wxCallAfter(self.SetCursor, wxNullCursor) |
371 wx.CallAfter(self.SetCursor, wx.NullCursor) |
373 self.ReleaseMouse() |
372 self.ReleaseMouse() |
374 self.Refresh() |
373 self.Refresh() |
375 event.Skip() |
374 event.Skip() |
376 |
375 |
377 def OnViewerLeftDClick(self, event): |
376 def OnViewerLeftDClick(self, event): |
395 |
394 |
396 def OnChar(self, event): |
395 def OnChar(self, event): |
397 if self.GetDrawingMode() == FREEDRAWING_MODE: |
396 if self.GetDrawingMode() == FREEDRAWING_MODE: |
398 Viewer.OnChar(self, event) |
397 Viewer.OnChar(self, event) |
399 else: |
398 else: |
|
399 xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL) |
|
400 xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL) |
|
401 ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) |
400 keycode = event.GetKeyCode() |
402 keycode = event.GetKeyCode() |
401 if keycode == WXK_DELETE and self.SelectedElement: |
403 if keycode == wx.WXK_DELETE and self.SelectedElement: |
402 if self.IsBlock(self.SelectedElement): |
404 if self.IsBlock(self.SelectedElement): |
403 self.SelectedElement.Delete() |
405 self.SelectedElement.Delete() |
404 elif self.IsWire(self.SelectedElement): |
406 elif self.IsWire(self.SelectedElement): |
405 self.DeleteWire(self.SelectedElement) |
407 self.DeleteWire(self.SelectedElement) |
406 elif isinstance(self.SelectedElement, Graphic_Group): |
408 elif isinstance(self.SelectedElement, Graphic_Group): |
412 else: |
414 else: |
413 self.SelectedElement.Delete() |
415 self.SelectedElement.Delete() |
414 self.RefreshBuffer() |
416 self.RefreshBuffer() |
415 self.RefreshScrollBars() |
417 self.RefreshScrollBars() |
416 self.Refresh() |
418 self.Refresh() |
417 elif keycode == WXK_LEFT: |
419 elif keycode == wx.WXK_LEFT: |
418 if event.ControlDown() and event.ShiftDown(): |
420 if event.ControlDown() and event.ShiftDown(): |
419 self.Scroll(0, ypos) |
421 self.Scroll(0, ypos) |
420 elif event.ControlDown(): |
422 elif event.ControlDown(): |
421 self.Scroll(max(0, xpos - 1), ypos) |
423 self.Scroll(max(0, xpos - 1), ypos) |
422 elif keycode == WXK_RIGHT: |
424 elif keycode == wx.WXK_RIGHT: |
423 if event.ControlDown() and event.ShiftDown(): |
425 if event.ControlDown() and event.ShiftDown(): |
424 self.Scroll(xmax, ypos) |
426 self.Scroll(xmax, ypos) |
425 elif event.ControlDown(): |
427 elif event.ControlDown(): |
426 self.Scroll(min(xpos + 1, xmax), ypos) |
428 self.Scroll(min(xpos + 1, xmax), ypos) |
427 elif keycode == WXK_UP: |
429 elif keycode == wx.WXK_UP: |
428 if event.ControlDown() and event.ShiftDown(): |
430 if event.ControlDown() and event.ShiftDown(): |
429 self.Scroll(xpos, 0) |
431 self.Scroll(xpos, 0) |
430 elif event.ControlDown(): |
432 elif event.ControlDown(): |
431 self.Scroll(xpos, max(0, ypos - 1)) |
433 self.Scroll(xpos, max(0, ypos - 1)) |
432 elif keycode == WXK_DOWN: |
434 elif keycode == wx.WXK_DOWN: |
433 if event.ControlDown() and event.ShiftDown(): |
435 if event.ControlDown() and event.ShiftDown(): |
434 self.Scroll(xpos, ymax) |
436 self.Scroll(xpos, ymax) |
435 elif event.ControlDown(): |
437 elif event.ControlDown(): |
436 self.Scroll(xpos, min(ypos + 1, ymax)) |
438 self.Scroll(xpos, min(ypos + 1, ymax)) |
437 event.Skip() |
439 event.Skip() |
451 returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType() |
453 returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType() |
452 if returntype == "BOOL": |
454 if returntype == "BOOL": |
453 varlist.append(self.Controler.GetCurrentElementEditingName()) |
455 varlist.append(self.Controler.GetCurrentElementEditingName()) |
454 dialog.SetVariables(varlist) |
456 dialog.SetVariables(varlist) |
455 dialog.SetValues({"name":"","type":COIL_NORMAL}) |
457 dialog.SetValues({"name":"","type":COIL_NORMAL}) |
456 if dialog.ShowModal() == wxID_OK: |
458 if dialog.ShowModal() == wx.ID_OK: |
457 values = dialog.GetValues() |
459 values = dialog.GetValues() |
458 startx, starty = LD_OFFSET[0], 0 |
460 startx, starty = LD_OFFSET[0], 0 |
459 if len(self.Rungs) > 0: |
461 if len(self.Rungs) > 0: |
460 bbox = self.Rungs[-1].GetBoundingBox() |
462 bbox = self.Rungs[-1].GetBoundingBox() |
461 starty = bbox.y + bbox.height |
463 starty = bbox.y + bbox.height |
537 for var in vars: |
539 for var in vars: |
538 if var["Class"] != "Output" and var["Type"] == "BOOL": |
540 if var["Class"] != "Output" and var["Type"] == "BOOL": |
539 varlist.append(var["Name"]) |
541 varlist.append(var["Name"]) |
540 dialog.SetVariables(varlist) |
542 dialog.SetVariables(varlist) |
541 dialog.SetValues({"name":"","type":CONTACT_NORMAL}) |
543 dialog.SetValues({"name":"","type":CONTACT_NORMAL}) |
542 if dialog.ShowModal() == wxID_OK: |
544 if dialog.ShowModal() == wx.ID_OK: |
543 values = dialog.GetValues() |
545 values = dialog.GetValues() |
544 points = wires[0].GetSelectedSegmentPoints() |
546 points = wires[0].GetSelectedSegmentPoints() |
545 id = self.GetNewId() |
547 id = self.GetNewId() |
546 contact = LD_Contact(self, values["type"], values["name"], id) |
548 contact = LD_Contact(self, values["type"], values["name"], id) |
547 contact.SetPosition(0, points[0].y - (LD_ELEMENT_SIZE[1] + 1) / 2) |
549 contact.SetPosition(0, points[0].y - (LD_ELEMENT_SIZE[1] + 1) / 2) |
610 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
612 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
611 self.RefreshBuffer() |
613 self.RefreshBuffer() |
612 self.RefreshScrollBars() |
614 self.RefreshScrollBars() |
613 self.Refresh() |
615 self.Refresh() |
614 else: |
616 else: |
615 message = wxMessageDialog(self, "You must select the wire where a contact should be added!", "Error", wxOK|wxICON_ERROR) |
617 message = wx.MessageDialog(self, "You must select the wire where a contact should be added!", "Error", wx.OK|wx.ICON_ERROR) |
616 message.ShowModal() |
618 message.ShowModal() |
617 message.Destroy() |
619 message.Destroy() |
618 |
620 |
619 def AddLadderBranch(self): |
621 def AddLadderBranch(self): |
620 blocks = [] |
622 blocks = [] |
761 returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType() |
763 returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType() |
762 if returntype == "BOOL": |
764 if returntype == "BOOL": |
763 varlist.append(self.Controler.GetCurrentElementEditingName()) |
765 varlist.append(self.Controler.GetCurrentElementEditingName()) |
764 dialog.SetVariables(varlist) |
766 dialog.SetVariables(varlist) |
765 dialog.SetValues({"name":"","type":COIL_NORMAL}) |
767 dialog.SetValues({"name":"","type":COIL_NORMAL}) |
766 if dialog.ShowModal() == wxID_OK: |
768 if dialog.ShowModal() == wx.ID_OK: |
767 values = dialog.GetValues() |
769 values = dialog.GetValues() |
768 powerrail = right_elements[0].GetParentBlock() |
770 powerrail = right_elements[0].GetParentBlock() |
769 index = 0 |
771 index = 0 |
770 for right_element in right_elements: |
772 for right_element in right_elements: |
771 index = max(index, powerrail.GetConnectorIndex(right_element)) |
773 index = max(index, powerrail.GetConnectorIndex(right_element)) |
831 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
833 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1) |
832 self.RefreshBuffer() |
834 self.RefreshBuffer() |
833 self.RefreshScrollBars() |
835 self.RefreshScrollBars() |
834 self.Refresh() |
836 self.Refresh() |
835 else: |
837 else: |
836 message = wxMessageDialog(self, "The group of block must be coherent!", "Error", wxOK|wxICON_ERROR) |
838 message = wx.MessageDialog(self, "The group of block must be coherent!", "Error", wx.OK|wx.ICON_ERROR) |
837 message.ShowModal() |
839 message.ShowModal() |
838 message.Destroy() |
840 message.Destroy() |
839 else: |
841 else: |
840 message = wxMessageDialog(self, "You must select the block or group of blocks around which a branch should be added!", "Error", wxOK|wxICON_ERROR) |
842 message = wx.MessageDialog(self, "You must select the block or group of blocks around which a branch should be added!", "Error", wx.OK|wx.ICON_ERROR) |
841 message.ShowModal() |
843 message.ShowModal() |
842 message.Destroy() |
844 message.Destroy() |
843 |
845 |
844 def AddLadderBlock(self): |
846 def AddLadderBlock(self): |
845 message = wxMessageDialog(self, "This option isn't available yet!", "Warning", wxOK|wxICON_EXCLAMATION) |
847 message = wx.MessageDialog(self, "This option isn't available yet!", "Warning", wx.OK|wx.ICON_EXCLAMATION) |
846 message.ShowModal() |
848 message.ShowModal() |
847 message.Destroy() |
849 message.Destroy() |
848 |
850 |
849 #------------------------------------------------------------------------------- |
851 #------------------------------------------------------------------------------- |
850 # Delete element functions |
852 # Delete element functions |
1111 else: |
1113 else: |
1112 offset = start_offset + LD_LINE_SIZE * CalcBranchSize(previous_blocks, blocks) |
1114 offset = start_offset + LD_LINE_SIZE * CalcBranchSize(previous_blocks, blocks) |
1113 if block in block_list: |
1115 if block in block_list: |
1114 wires = wire.EndConnected.GetWires() |
1116 wires = wire.EndConnected.GetWires() |
1115 endmiddlepoint = wires[0][0].StartConnected.GetPosition(False)[0] - LD_WIRE_SIZE |
1117 endmiddlepoint = wires[0][0].StartConnected.GetPosition(False)[0] - LD_WIRE_SIZE |
1116 points = [startpoint, wxPoint(middlepoint, startpoint.y), |
1118 points = [startpoint, wx.Point(middlepoint, startpoint.y), |
1117 wxPoint(middlepoint, startpoint.y + offset), |
1119 wx.Point(middlepoint, startpoint.y + offset), |
1118 wxPoint(endmiddlepoint, startpoint.y + offset), |
1120 wx.Point(endmiddlepoint, startpoint.y + offset), |
1119 wxPoint(endmiddlepoint, endpoint.y), endpoint] |
1121 wx.Point(endmiddlepoint, endpoint.y), endpoint] |
1120 else: |
1122 else: |
1121 if startpoint.y + offset != endpoint.y: |
1123 if startpoint.y + offset != endpoint.y: |
1122 if isinstance(element, LD_PowerRail): |
1124 if isinstance(element, LD_PowerRail): |
1123 diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE |
1125 diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE |
1124 for k in xrange(abs(diff)): |
1126 for k in xrange(abs(diff)): |
1138 else: |
1140 else: |
1139 block.Move(0, startpoint.y + offset - endpoint.y) |
1141 block.Move(0, startpoint.y + offset - endpoint.y) |
1140 self.RefreshPosition(block, False) |
1142 self.RefreshPosition(block, False) |
1141 endpoint = wire.EndConnected.GetPosition(False) |
1143 endpoint = wire.EndConnected.GetPosition(False) |
1142 if not onlyone[i]: |
1144 if not onlyone[i]: |
1143 points = [startpoint, wxPoint(middlepoint, startpoint.y), |
1145 points = [startpoint, wx.Point(middlepoint, startpoint.y), |
1144 wxPoint(middlepoint, endpoint.y), endpoint] |
1146 wx.Point(middlepoint, endpoint.y), endpoint] |
1145 else: |
1147 else: |
1146 points = [startpoint, endpoint] |
1148 points = [startpoint, endpoint] |
1147 wire.SetPoints(points) |
1149 wire.SetPoints(points) |
1148 previous_blocks.append(block) |
1150 previous_blocks.append(block) |
1149 blocks.remove(block) |
1151 blocks.remove(block) |
1179 for var in vars: |
1181 for var in vars: |
1180 if var["Class"] != "Output" and var["Type"] == "BOOL": |
1182 if var["Class"] != "Output" and var["Type"] == "BOOL": |
1181 varlist.append(var["Name"]) |
1183 varlist.append(var["Name"]) |
1182 dialog.SetVariables(varlist) |
1184 dialog.SetVariables(varlist) |
1183 dialog.SetValues({"name":contact.GetName(),"type":contact.GetType()}) |
1185 dialog.SetValues({"name":contact.GetName(),"type":contact.GetType()}) |
1184 if dialog.ShowModal() == wxID_OK: |
1186 if dialog.ShowModal() == wx.ID_OK: |
1185 values = dialog.GetValues() |
1187 values = dialog.GetValues() |
1186 contact.SetName(values["name"]) |
1188 contact.SetName(values["name"]) |
1187 contact.SetType(values["type"]) |
1189 contact.SetType(values["type"]) |
1188 contact.RefreshModel(False) |
1190 contact.RefreshModel(False) |
1189 self.RefreshBuffer() |
1191 self.RefreshBuffer() |
1205 returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType() |
1207 returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType() |
1206 if returntype == "BOOL": |
1208 if returntype == "BOOL": |
1207 varlist.append(self.Controler.GetCurrentElementEditingName()) |
1209 varlist.append(self.Controler.GetCurrentElementEditingName()) |
1208 dialog.SetVariables(varlist) |
1210 dialog.SetVariables(varlist) |
1209 dialog.SetValues({"name":coil.GetName(),"type":coil.GetType()}) |
1211 dialog.SetValues({"name":coil.GetName(),"type":coil.GetType()}) |
1210 if dialog.ShowModal() == wxID_OK: |
1212 if dialog.ShowModal() == wx.ID_OK: |
1211 values = dialog.GetValues() |
1213 values = dialog.GetValues() |
1212 coil.SetName(values["name"]) |
1214 coil.SetName(values["name"]) |
1213 coil.SetType(values["type"]) |
1215 coil.SetType(values["type"]) |
1214 coil.RefreshModel(False) |
1216 coil.RefreshModel(False) |
1215 self.RefreshBuffer() |
1217 self.RefreshBuffer() |