def saveToFile(self, fn): pb = ProtoBoard(self.cols, self.rows) dsc = self.tcDesc.GetValue().strip() if dsc == "": pb.setDescription(None) else: pb.setDescription(dsc) pb.clearTraces() pb.clearSkips() for s in self.segments: s.addSegment(pb) try: fp = open(fn, "w") fp.write(pb.getXml(includeDescription=True)) fp.write("\n") fp.close() except: dlg = wx.MessageDialog(self, 'Error writing to file ' + fn, 'Save Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return False self.setModified(False) dlg = wx.MessageDialog(self, 'Proto Board template saved to ' + fn, 'Saved', wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() return True
def singleperf(cols,rows): pb = ProtoBoard(cols,rows) for r in range(rows): for c in range(cols): pb.addHTrace(c, c, r) return pb, "single_perf_%d_%d.pb" % (cols,rows)
def singleperf(cols, rows): pb = ProtoBoard(cols, rows) for r in range(rows): for c in range(cols): pb.addHTrace(c, c, r) return pb, "single_perf_%d_%d.pb" % (cols, rows)
def doubleperfv(cols, rows): pb = ProtoBoard(cols,rows) for c in range(cols): for r in range(0, rows-1, 2): pb.addVTrace(c, r, r+1) if rows % 2 == 1: for c in range(cols): pb.addVTrace(c, rows-1, rows-1) return pb, "double_perf_%d_%d_v.pb" % (cols,rows)
def doubleperfh(cols, rows): pb = ProtoBoard(cols,rows) for r in range(rows): for c in range(0, cols-1, 2): pb.addHTrace(c, c+1, r) if cols % 2 == 1: for r in range(rows): pb.addHTrace(cols-1, cols-1, r) return pb, "double_perf_%d_%d_h.pb" % (cols,rows)
def sfbreadboardminih(): pb = ProtoBoard(17, 12) for c in range(17): pb.addVTrace(c, 0, 4) pb.addVTrace(c, 7, 11) pb.addHSkip(5) pb.addHSkip(6) return pb, "sf_breadboard_mini_h.pb"
def bpssb300v(): pb = ProtoBoard(12, 30) for r in range(30): pb.addHTrace(0, 4, r) pb.addHTrace(7, 11, r) pb.addVTrace(5, 0, 29) pb.addVTrace(6, 0, 29) return pb, "bps_sb300_v.pb"
def bpssb300h(): pb = ProtoBoard(30, 12) for c in range(30): pb.addVTrace(c, 0, 4) pb.addVTrace(c, 7, 11) pb.addHTrace(0, 29, 5) pb.addHTrace(0, 29, 6) return pb, "bps_sb300_h.pb"
def sfbreadboardminiv(): pb = ProtoBoard(12, 17) for r in range(17): pb.addHTrace(0, 4, r) pb.addHTrace(7, 11, r) pb.addVSkip(5) pb.addVSkip(6) return pb, "sf_breadboard_mini_v.pb"
def createProtoBoard(self): self.pb = ProtoBoard(self.cols, self.rows) self.updateProtoBoard(False) if not self.pbPrev is None: try: self.prevPosition = self.pbPrev.GetPosition() self.pbPrev.Destroy() except wx.PyDeadObjectError: self.pbPrev = None self.prevPosition = [-1, -1] self.pbPrev = ProtoBoardPreview(self.parent, self.pb, self.prevPosition, self.settings) self.pbPrev.Show() if len(self.segments) > 0: s = self.segments[-1] self.hiLightPos(s.getFirstPos())
def bpssb300v(): pb = ProtoBoard(12, 30) for r in range(30): pb.addHTrace(0, 4, r) pb.addHTrace(7, 11, r) pb.addVTrace(5, 0, 29) pb.addVTrace(6, 0, 29) return pb, "bps_sb300_v.pb"
def sfbreadboardminiv(): pb = ProtoBoard(12, 17) for r in range(17): pb.addHTrace(0, 4, r) pb.addHTrace(7, 11, r) pb.addVSkip(5) pb.addVSkip(6) return pb, "sf_breadboard_mini_v.pb"
def bpssb300h(): pb = ProtoBoard(30, 12) for c in range(30): pb.addVTrace(c, 0, 4) pb.addVTrace(c, 7, 11) pb.addHTrace(0, 29, 5) pb.addHTrace(0, 29, 6) return pb, "bps_sb300_h.pb"
def sfbreadboardminih(): pb = ProtoBoard(17, 12) for c in range(17): pb.addVTrace(c, 0, 4) pb.addVTrace(c, 7, 11) pb.addHSkip(5) pb.addHSkip(6) return pb, "sf_breadboard_mini_h.pb"
def onOk(self, evt): r = self.scRows.GetValue() c = self.scCols.GetValue() vertical = self.cbVert.IsChecked() if self.cbFull.IsChecked(): if vertical: tl = r else: tl = c else: tl = self.scTraces.GetValue() self.pb = ProtoBoard(c, r) if vertical: if tl > r: tl = r for i in range(c): for j in range(0, r-tl+1, tl): self.pb.addVTrace(i, j, j+tl-1) nl = r % tl if nl != 0: for i in range(c): self.pb.addVTrace(i, r-nl, r-1) else: if tl > c: tl = c for i in range(r): for j in range(0, c-tl+1, tl): self.pb.addHTrace(j, j+tl-1, i) nl = c % tl if nl != 0: for i in range(r): self.pb.addHTrace(c-nl, c-1, i) self.EndModal(wx.ID_OK)
def createProtoBoard(self): self.pb = ProtoBoard(self.cols, self.rows) self.updateProtoBoard(False) if not self.pbPrev is None: try: self.prevPosition = self.pbPrev.GetPosition() self.pbPrev.Destroy() except wx.PyDeadObjectError: self.pbPrev = None self.prevPosition = [-1, -1] self.pbPrev = ProtoBoardPreview(self.parent, self.pb, self.prevPosition, self.settings) self.pbPrev.Show() if len(self.segments) > 0: s = self.segments[-1] self.hiLightPos(s.getFirstPos())
def doubleperfv(cols, rows): pb = ProtoBoard(cols, rows) for c in range(cols): for r in range(0, rows - 1, 2): pb.addVTrace(c, r, r + 1) if rows % 2 == 1: for c in range(cols): pb.addVTrace(c, rows - 1, rows - 1) return pb, "double_perf_%d_%d_v.pb" % (cols, rows)
def doubleperfh(cols, rows): pb = ProtoBoard(cols, rows) for r in range(rows): for c in range(0, cols - 1, 2): pb.addHTrace(c, c + 1, r) if cols % 2 == 1: for r in range(rows): pb.addHTrace(cols - 1, cols - 1, r) return pb, "double_perf_%d_%d_h.pb" % (cols, rows)
class NewTempDialog(wx.Dialog): def __init__(self, parent): self.parent = parent self.settings = parent.settings self.images = parent.settings.images self.stype = STYPE_HTRACE self.segments = [] self.selectedSegment = wx.NOT_FOUND self.cols = 5 self.rows = 5 self.modified = False self.fileName = None self.pbPrev = None self.prevPosition = [-1, -1] wx.CallAfter(self.createProtoBoard) title = "New Proto-board template" wx.Dialog.__init__(self, parent, wx.ID_ANY, title, size=(100, 100)) self.SetBackgroundColour("white") self.Bind(wx.EVT_CLOSE, self.onClose) t1 = wx.StaticText(self, wx.ID_ANY, "Columns:") self.scCols = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scCols.SetRange(5, 100) self.scCols.SetValue(self.cols) self.Bind(wx.EVT_SPINCTRL, self.onSpinCol, self.scCols) t2 = wx.StaticText(self, wx.ID_ANY, "Rows:") self.scRows = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scRows.SetRange(5, 100) self.scRows.SetValue(self.rows) self.Bind(wx.EVT_SPINCTRL, self.onSpinRow, self.scRows) isizer = wx.FlexGridSizer(cols=4, hgap=6, vgap=6) isizer.AddMany([t1, self.scCols, t2, self.scRows]) box = wx.StaticBox(self, -1, "Item") szItems = wx.StaticBoxSizer(box, wx.VERTICAL) self.rbHTrace = wx.RadioButton(self, wx.ID_ANY, "Horizontal Trace", style=wx.RB_GROUP) self.rbVTrace = wx.RadioButton(self, wx.ID_ANY, "Vertical Trace") self.rbHSkip = wx.RadioButton(self, wx.ID_ANY, "Row without holes") self.rbVSkip = wx.RadioButton(self, wx.ID_ANY, "Column without holes") self.Bind(wx.EVT_RADIOBUTTON, self.onHTrace, self.rbHTrace) self.Bind(wx.EVT_RADIOBUTTON, self.onVTrace, self.rbVTrace) self.Bind(wx.EVT_RADIOBUTTON, self.onHSkip, self.rbHSkip) self.Bind(wx.EVT_RADIOBUTTON, self.onVSkip, self.rbVSkip) szItems.AddSpacer((10, 10)) szItems.Add(self.rbHTrace) szItems.AddSpacer((10, 10)) szItems.Add(self.rbVTrace) szItems.AddSpacer((10, 10)) szItems.Add(self.rbHSkip) szItems.AddSpacer((10, 10)) szItems.Add(self.rbVSkip) szItems.AddSpacer((10, 10)) t1 = wx.StaticText(self, wx.ID_ANY, "Point A") self.scAX = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scAX.SetRange(0, self.cols - 1) self.scAX.SetValue(0) self.scAY = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scAY.SetRange(0, self.rows - 1) self.scAY.SetValue(0) t2 = wx.StaticText(self, wx.ID_ANY, "Point B") self.scBX = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scBX.SetRange(0, self.cols - 1) self.scBX.SetValue(0) self.scBY = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scBY.SetRange(0, self.rows - 1) self.scBY.SetValue(0) szData = wx.FlexGridSizer(cols=3, hgap=6, vgap=6) szData.AddMany([t1, self.scAX, self.scAY, t2, self.scBX, self.scBY]) box = wx.StaticBox(self, -1, "Positions") szDataBox = wx.StaticBoxSizer(box, wx.VERTICAL) szDataBox.Add(szData) szDataBox.AddSpacer((10, 10)) self.cbRepeat = wx.CheckBox(self, wx.ID_ANY, "Repeat across row/column") szDataBox.Add(self.cbRepeat) self.cbRepeat.SetValue(False) hsz = wx.BoxSizer(wx.HORIZONTAL) hsz.Add(szItems) hsz.AddSpacer((20, 20)) hsz.Add(szDataBox) sizer = wx.BoxSizer(wx.VERTICAL) sizer.AddSpacer((20, 20)) sizer.Add(isizer) sizer.AddSpacer((20, 20)) sizer.Add(hsz) sizer.AddSpacer((20, 20)) hsizer = wx.BoxSizer(wx.HORIZONTAL) hsizer.AddSpacer((20, 20)) hsizer.Add(sizer) hsizer.AddSpacer((20, 20)) self.lbSegments = wx.ListBox(self, wx.ID_ANY, size=(200, 200), choices=[]) self.setSegmentList() self.lbSegments.Bind(wx.EVT_LISTBOX, self.onSegmentSelect) hsizer.Add(self.lbSegments, 1, wx.ALL, 20) hsizer.AddSpacer((20, 20)) dbSizer = wx.BoxSizer(wx.VERTICAL) dbSizer.Add(hsizer) dscSizer = wx.BoxSizer(wx.HORIZONTAL) dscSizer.AddSpacer((20, 10)) dscSizer.Add(wx.StaticText(self, wx.ID_ANY, "Description: ")) dscSizer.AddSpacer((5, 5)) self.tcDesc = wx.TextCtrl(self, wx.ID_ANY, "", size=(500, -1)) dscSizer.Add(self.tcDesc) dbSizer.Add(dscSizer) dbSizer.AddSpacer((10, 10)) tbSizer = wx.BoxSizer(wx.HORIZONTAL) tbSizer.AddSpacer((20, 20)) self.bAdd = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngAdd, size=TBDIM) self.bAdd.SetToolTipString("Add a new item to the template") self.Bind(wx.EVT_BUTTON, self.onAdd, self.bAdd) tbSizer.Add(self.bAdd) tbSizer.AddSpacer((5, 5)) self.bDel = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngDelete, size=TBDIM) self.bDel.SetToolTipString("Delete an item from the template") self.Bind(wx.EVT_BUTTON, self.onDel, self.bDel) tbSizer.Add(self.bDel) tbSizer.AddSpacer((20, 10)) self.bPrev = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngView, size=TBDIM) self.bPrev.SetToolTipString("Display preview window") self.Bind(wx.EVT_BUTTON, self.onPreview, self.bPrev) tbSizer.Add(self.bPrev) tbSizer.AddSpacer((20, 20)) self.bNew = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngNewtempfile, size=TBDIM) self.bNew.SetToolTipString("Create a new Template File") self.Bind(wx.EVT_BUTTON, self.onNew, self.bNew) tbSizer.Add(self.bNew) tbSizer.AddSpacer((5, 5)) self.bLoad = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngOpen, size=TBDIM) self.bLoad.SetToolTipString("Load a Template File") self.Bind(wx.EVT_BUTTON, self.onLoad, self.bLoad) tbSizer.Add(self.bLoad) tbSizer.AddSpacer((5, 5)) self.bSave = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngSave, size=TBDIM) self.bSave.SetToolTipString("Save Template") self.Bind(wx.EVT_BUTTON, self.onSave, self.bSave) tbSizer.Add(self.bSave) tbSizer.AddSpacer((5, 5)) self.bSaveAs = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngSaveas, size=TBDIM) self.bSaveAs.SetToolTipString("Save Template As A New File") self.Bind(wx.EVT_BUTTON, self.onSaveAs, self.bSaveAs) tbSizer.Add(self.bSaveAs) tbSizer.AddSpacer((50, 10)) self.bExit = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngExit, size=TBDIM) self.bExit.SetToolTipString("Exit") self.Bind(wx.EVT_BUTTON, self.onClose, self.bExit) tbSizer.Add(self.bExit) tbSizer.AddSpacer((10, 10)) dbSizer.Add(tbSizer) dbSizer.AddSpacer((20, 20)) self.SetSizer(dbSizer) self.Fit() self.rbHTrace.SetValue(1) self.onHTrace(None) def updateTitle(self): if self.fileName is None: self.SetTitle("New Proto-board template") else: self.SetTitle("Proto-board template file: %s" % self.fileName) def onNew(self, evt): if self.modified: if not self.abandonChanges(): return self.stype = STYPE_HTRACE self.segments = [] self.selectedSegment = wx.NOT_FOUND self.cols = 5 self.rows = 5 self.modified = False self.fileName = None self.createProtoBoard() self.tcDesc.SetValue("") self.scRows.SetValue(self.rows) self.scCols.SetValue(self.cols) self.scAX.SetRange(0, self.cols - 1) self.scAX.SetValue(0) self.scBX.SetRange(0, self.cols - 1) self.scBX.SetValue(0) self.scAY.SetRange(0, self.rows - 1) self.scAY.SetValue(0) self.scBY.SetRange(0, self.rows - 1) self.scBY.SetValue(0) self.setSegmentList() self.rbHTrace.SetValue(True) self.setHTrace() self.updateTitle() def onLoad(self, evt): if self.modified: if not self.abandonChanges(): return dlg = wx.FileDialog(self, message="Choose a proto-board template...", defaultDir=self.settings.templDir, defaultFile="", wildcard=wildcard, style=wx.OPEN) rc = dlg.ShowModal() if rc == wx.ID_OK: path = dlg.GetPath() dlg.Destroy() if rc != wx.ID_OK: return pb = self.parent.loadBoard(path) if pb is None: dlg = wx.MessageDialog( self, 'Error loading proto-board template file: ' + path, 'Load Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return self.fileName = path self.updateTitle() dsc = pb.getDescription() if dsc is None: self.tcDesc.SetValue("") else: self.tcDesc.SetValue(dsc) self.cols, self.rows = pb.getSize() self.scRows.SetValue(self.rows) self.scCols.SetValue(self.cols) self.scAX.SetRange(0, self.cols - 1) self.scBX.SetRange(0, self.cols - 1) self.scAY.SetRange(0, self.rows - 1) self.scBY.SetRange(0, self.rows - 1) self.segments = [] ht = pb.getHTraces() for t in ht: self.addSegment(Segment(STYPE_HTRACE, t[0], t[1], t[2])) vt = pb.getVTraces() for t in vt: self.addSegment(Segment(STYPE_VTRACE, t[0], t[1], t[2])) hs, vs = pb.getSkips() for s in hs: self.addSegment(Segment(STYPE_HSKIP, s, None, None)) for s in vs: self.addSegment(Segment(STYPE_VSKIP, s, None, None)) self.setSegmentList() self.createProtoBoard() self.setModified(False) def setModified(self, flag=True): self.modified = flag def abandonChanges(self): if self.modified: dlg = wx.MessageDialog( self, 'Are you sure you want to exit?\nPending changes will be lost', 'Changes pending', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) rc = dlg.ShowModal() dlg.Destroy() if rc == wx.ID_NO: return False return True def onSave(self, evt): if self.fileName is None: self.onSaveAs(None) return self.saveToFile(self.fileName) def onSaveAs(self, evt): dfn = "" if not self.fileName is None: dfn = self.fileName dlg = wx.FileDialog(self, message="Save proto board template as ...", defaultDir=os.getcwd(), defaultFile=dfn, wildcard=wildcard, style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) rc = dlg.ShowModal() if rc == wx.ID_OK: path = dlg.GetPath() dlg.Destroy() if rc != wx.ID_OK: return if self.saveToFile(path): self.fileName = path self.updateTitle() def saveToFile(self, fn): pb = ProtoBoard(self.cols, self.rows) dsc = self.tcDesc.GetValue().strip() if dsc == "": pb.setDescription(None) else: pb.setDescription(dsc) pb.clearTraces() pb.clearSkips() for s in self.segments: s.addSegment(pb) try: fp = open(fn, "w") fp.write(pb.getXml(includeDescription=True)) fp.write("\n") fp.close() except: dlg = wx.MessageDialog(self, 'Error writing to file ' + fn, 'Save Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return False self.setModified(False) dlg = wx.MessageDialog(self, 'Proto Board template saved to ' + fn, 'Saved', wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() return True def onPreview(self, evt): self.createProtoBoard() def createProtoBoard(self): self.pb = ProtoBoard(self.cols, self.rows) self.updateProtoBoard(False) if not self.pbPrev is None: try: self.prevPosition = self.pbPrev.GetPosition() self.pbPrev.Destroy() except wx.PyDeadObjectError: self.pbPrev = None self.prevPosition = [-1, -1] self.pbPrev = ProtoBoardPreview(self.parent, self.pb, self.prevPosition, self.settings) self.pbPrev.Show() if len(self.segments) > 0: s = self.segments[-1] self.hiLightPos(s.getFirstPos()) def hiLightPos(self, pos): if self.pbPrev is None: return self.pbPrev.setHiLightedPos(pos) def updateProtoBoard(self, refresh=True): self.pb.clearTraces() self.pb.clearSkips() for s in self.segments: s.addSegment(self.pb) if refresh: if not self.pbPrev is None: try: self.pbPrev.refresh() except wx.PyDeadObjectError: self.pbPrev = None def onSpinRow(self, evt): self.setModified() nr = self.scRows.GetValue() self.scAY.SetRange(0, nr - 1) self.scBY.SetRange(0, nr - 1) self.rows = nr self.limitSegments() self.createProtoBoard() def onSpinCol(self, evt): self.setModified() nc = self.scCols.GetValue() self.scAX.SetRange(0, nc - 1) self.scBX.SetRange(0, nc - 1) self.cols = nc self.limitSegments() self.createProtoBoard() def setSegmentList(self): self.lbSegments.Set([s.getStr() for s in self.segments]) def onSegmentSelect(self, evt): self.selectedSegment = self.lbSegments.GetSelection() if self.selectedSegment is None: self.hiLightPos(None) return if self.selectedSegment == wx.NOT_FOUND: self.hiLightPos(None) return if self.selectedSegment < 0 or self.selectedSegment >= len( self.segments): self.hiLightPos(None) return pos = self.segments[self.selectedSegment].getFirstPos() self.hiLightPos(pos) def limitSegments(self): delSeg = [] for sx in range(len(self.segments)): deleteSeg, chg = self.segments[sx].limitValues( self.cols, self.rows) if deleteSeg: delSeg.append(sx) if deleteSeg or chg: self.setModified() for sx in delSeg[::-1]: del self.segments[sx] self.setSegmentList() def onAdd(self, evt): self.setModified() rpt = self.cbRepeat.GetValue() if self.stype == STYPE_HTRACE: ax = self.scAX.GetValue() ay = self.scAY.GetValue() bx = self.scBX.GetValue() by = self.scBY.GetValue() tlen = bx - ax + 1 if ax > bx: t = ax ax = bx bx = t if ay > by: t = ay ay = by by = t if rpt: while True: for r in range(ay, by + 1): self.addSegment(Segment(self.stype, ax, bx, r)) ax += tlen bx += tlen if bx >= self.cols: break else: for r in range(ay, by + 1): self.addSegment(Segment(self.stype, ax, bx, r)) elif self.stype == STYPE_VTRACE: ax = self.scAX.GetValue() ay = self.scAY.GetValue() bx = self.scBX.GetValue() by = self.scBY.GetValue() tlen = by - ay + 1 if ax > bx: t = ax ax = bx bx = t if ay > by: t = ay ay = by by = t if rpt: while True: for c in range(ax, bx + 1): self.addSegment(Segment(self.stype, c, ay, by)) ay += tlen by += tlen if by >= self.rows: break else: for c in range(ax, bx + 1): self.addSegment(Segment(self.stype, c, ay, by)) elif self.stype == STYPE_HSKIP: self.addSegment( Segment(self.stype, self.scAY.GetValue(), None, None)) elif self.stype == STYPE_VSKIP: self.addSegment( Segment(self.stype, self.scAX.GetValue(), None, None)) self.setSegmentList() self.selectedSegment = len(self.segments) - 1 self.lbSegments.SetSelection(self.selectedSegment) self.updateProtoBoard() def addSegment(self, seg): for s in self.segments: if s.getValues() == seg.getValues(): return False self.segments.append(seg) return True def onDel(self, evt): if self.selectedSegment is None: return if self.selectedSegment == wx.NOT_FOUND: return if self.selectedSegment < 0: return if self.selectedSegment >= len(self.segments): return self.setModified() del self.segments[self.selectedSegment] self.setSegmentList() if self.selectedSegment >= len(self.segments): self.selectedSegment = len(self.segments) - 1 if self.selectedSegment < 0: self.selectedSegment = wx.NOT_FOUND else: self.lbSegments.SetSelection(self.selectedSegment) else: self.lbSegments.SetSelection(self.selectedSegment) self.updateProtoBoard() def onHTrace(self, evt): self.setHTrace() def setHTrace(self): self.stype = STYPE_HTRACE self.scAX.Enable(True) self.scAY.Enable(True) self.scBX.Enable(True) self.scBY.Enable(True) def onVTrace(self, evt): self.stype = STYPE_VTRACE self.scAX.Enable(True) self.scAY.Enable(True) self.scBX.Enable(True) self.scBY.Enable(True) def onHSkip(self, evt): self.stype = STYPE_HSKIP self.scAX.Enable(False) self.scAY.Enable(True) self.scBX.Enable(False) self.scBY.Enable(False) def onVSkip(self, evt): self.stype = STYPE_VSKIP self.scAX.Enable(True) self.scAY.Enable(False) self.scBX.Enable(False) self.scBY.Enable(False) def onClose(self, evt): if self.modified: if not self.abandonChanges(): return if not self.pbPrev is None: try: self.pbPrev.Destroy() except wx.PyDeadObjectError: self.pbPrev = None self.EndModal(wx.ID_OK)
def adapermaprotov(n): pb = ProtoBoard(18, n) for r in range(n): pb.addHTrace(3, 7, r) pb.addHTrace(10, 14, r) pb.addVSkip(2) pb.addVSkip(8) pb.addVSkip(9) pb.addVSkip(15) pb.addVTrace(0, 0, n-1) pb.addVTrace(1, 0, n-1) pb.addVTrace(16, 0, n-1) pb.addVTrace(17, 0, n-1) return pb, "ada_permaproto_%d_v.pb" % n
class NewTempDialog(wx.Dialog): def __init__(self, parent): self.parent = parent self.settings = parent.settings self.images = parent.settings.images self.stype = STYPE_HTRACE self.segments = [] self.selectedSegment = wx.NOT_FOUND self.cols = 5 self.rows = 5 self.modified = False self.fileName = None self.pbPrev = None self.prevPosition = [-1, -1] wx.CallAfter(self.createProtoBoard) title = "New Proto-board template" wx.Dialog.__init__(self, parent, wx.ID_ANY, title, size=(100, 100)) self.SetBackgroundColour("white") self.Bind(wx.EVT_CLOSE, self.onClose) t1 = wx.StaticText(self, wx.ID_ANY, "Columns:") self.scCols = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scCols.SetRange(5,100) self.scCols.SetValue(self.cols) self.Bind(wx.EVT_SPINCTRL, self.onSpinCol, self.scCols) t2 = wx.StaticText(self, wx.ID_ANY, "Rows:") self.scRows = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scRows.SetRange(5,100) self.scRows.SetValue(self.rows) self.Bind(wx.EVT_SPINCTRL, self.onSpinRow, self.scRows) isizer = wx.FlexGridSizer(cols=4, hgap=6, vgap=6) isizer.AddMany([ t1, self.scCols, t2, self.scRows ]) box = wx.StaticBox(self, -1, "Item") szItems = wx.StaticBoxSizer(box, wx.VERTICAL) self.rbHTrace = wx.RadioButton(self, wx.ID_ANY, "Horizontal Trace", style = wx.RB_GROUP) self.rbVTrace = wx.RadioButton(self, wx.ID_ANY, "Vertical Trace") self.rbHSkip = wx.RadioButton(self, wx.ID_ANY, "Row without holes") self.rbVSkip = wx.RadioButton(self, wx.ID_ANY, "Column without holes") self.Bind(wx.EVT_RADIOBUTTON, self.onHTrace, self.rbHTrace ) self.Bind(wx.EVT_RADIOBUTTON, self.onVTrace, self.rbVTrace ) self.Bind(wx.EVT_RADIOBUTTON, self.onHSkip, self.rbHSkip ) self.Bind(wx.EVT_RADIOBUTTON, self.onVSkip, self.rbVSkip ) szItems.AddSpacer((10, 10)) szItems.Add(self.rbHTrace) szItems.AddSpacer((10, 10)) szItems.Add(self.rbVTrace) szItems.AddSpacer((10, 10)) szItems.Add(self.rbHSkip) szItems.AddSpacer((10, 10)) szItems.Add(self.rbVSkip) szItems.AddSpacer((10, 10)) t1 = wx.StaticText(self, wx.ID_ANY, "Point A") self.scAX = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scAX.SetRange(0,self.cols-1) self.scAX.SetValue(0) self.scAY = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scAY.SetRange(0,self.rows-1) self.scAY.SetValue(0) t2 = wx.StaticText(self, wx.ID_ANY, "Point B") self.scBX = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scBX.SetRange(0,self.cols-1) self.scBX.SetValue(0) self.scBY = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scBY.SetRange(0,self.rows-1) self.scBY.SetValue(0) szData = wx.FlexGridSizer(cols=3, hgap=6, vgap=6) szData.AddMany([ t1, self.scAX, self.scAY, t2, self.scBX, self.scBY]) box = wx.StaticBox(self, -1, "Positions") szDataBox = wx.StaticBoxSizer(box, wx.VERTICAL) szDataBox.Add(szData) szDataBox.AddSpacer((10, 10)) self.cbRepeat = wx.CheckBox(self, wx.ID_ANY, "Repeat across row/column") szDataBox.Add(self.cbRepeat) self.cbRepeat.SetValue(False) hsz = wx.BoxSizer(wx.HORIZONTAL) hsz.Add(szItems) hsz.AddSpacer((20, 20)) hsz.Add(szDataBox) sizer = wx.BoxSizer(wx.VERTICAL) sizer.AddSpacer((20, 20)) sizer.Add(isizer) sizer.AddSpacer((20, 20)) sizer.Add(hsz) sizer.AddSpacer((20, 20)) hsizer = wx.BoxSizer(wx.HORIZONTAL) hsizer.AddSpacer((20, 20)) hsizer.Add(sizer) hsizer.AddSpacer((20, 20)) self.lbSegments = wx.ListBox(self, wx.ID_ANY, size=(200, 200), choices=[]) self.setSegmentList() self.lbSegments.Bind(wx.EVT_LISTBOX, self.onSegmentSelect) hsizer.Add(self.lbSegments, 1, wx.ALL, 20) hsizer.AddSpacer((20, 20)) dbSizer = wx.BoxSizer(wx.VERTICAL) dbSizer.Add(hsizer) dscSizer = wx.BoxSizer(wx.HORIZONTAL) dscSizer.AddSpacer((20, 10)) dscSizer.Add(wx.StaticText(self, wx.ID_ANY, "Description: ")) dscSizer.AddSpacer((5,5)) self.tcDesc = wx.TextCtrl(self, wx.ID_ANY, "", size=(500, -1)) dscSizer.Add(self.tcDesc) dbSizer.Add(dscSizer) dbSizer.AddSpacer((10, 10)) tbSizer = wx.BoxSizer(wx.HORIZONTAL) tbSizer.AddSpacer((20, 20)) self.bAdd = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngAdd, size=TBDIM) self.bAdd.SetToolTipString("Add a new item to the template") self.Bind(wx.EVT_BUTTON, self.onAdd, self.bAdd) tbSizer.Add(self.bAdd) tbSizer.AddSpacer((5, 5)) self.bDel = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngDelete, size=TBDIM) self.bDel.SetToolTipString("Delete an item from the template") self.Bind(wx.EVT_BUTTON, self.onDel, self.bDel) tbSizer.Add(self.bDel) tbSizer.AddSpacer((20, 10)) self.bPrev = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngView, size=TBDIM) self.bPrev.SetToolTipString("Display preview window") self.Bind(wx.EVT_BUTTON, self.onPreview, self.bPrev) tbSizer.Add(self.bPrev) tbSizer.AddSpacer((20, 20)) self.bNew = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngNewtempfile, size=TBDIM) self.bNew.SetToolTipString("Create a new Template File") self.Bind(wx.EVT_BUTTON, self.onNew, self.bNew) tbSizer.Add(self.bNew) tbSizer.AddSpacer((5, 5)) self.bLoad = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngOpen, size=TBDIM) self.bLoad.SetToolTipString("Load a Template File") self.Bind(wx.EVT_BUTTON, self.onLoad, self.bLoad) tbSizer.Add(self.bLoad) tbSizer.AddSpacer((5, 5)) self.bSave = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngSave, size=TBDIM) self.bSave.SetToolTipString("Save Template") self.Bind(wx.EVT_BUTTON, self.onSave, self.bSave) tbSizer.Add(self.bSave) tbSizer.AddSpacer((5, 5)) self.bSaveAs = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngSaveas, size=TBDIM) self.bSaveAs.SetToolTipString("Save Template As A New File") self.Bind(wx.EVT_BUTTON, self.onSaveAs, self.bSaveAs) tbSizer.Add(self.bSaveAs) tbSizer.AddSpacer((50, 10)) self.bExit = wx.BitmapButton(self, wx.ID_ANY, self.settings.images.pngExit, size=TBDIM) self.bExit.SetToolTipString("Exit") self.Bind(wx.EVT_BUTTON, self.onClose, self.bExit) tbSizer.Add(self.bExit) tbSizer.AddSpacer((10, 10)) dbSizer.Add(tbSizer) dbSizer.AddSpacer((20, 20)) self.SetSizer(dbSizer) self.Fit() self.rbHTrace.SetValue(1) self.onHTrace(None) def updateTitle(self): if self.fileName is None: self.SetTitle("New Proto-board template") else: self.SetTitle("Proto-board template file: %s" % self.fileName) def onNew(self, evt): if self.modified: if not self.abandonChanges(): return self.stype = STYPE_HTRACE self.segments = [] self.selectedSegment = wx.NOT_FOUND self.cols = 5 self.rows = 5 self.modified = False self.fileName = None self.createProtoBoard() self.tcDesc.SetValue("") self.scRows.SetValue(self.rows) self.scCols.SetValue(self.cols) self.scAX.SetRange(0, self.cols-1) self.scAX.SetValue(0) self.scBX.SetRange(0, self.cols-1) self.scBX.SetValue(0) self.scAY.SetRange(0, self.rows-1) self.scAY.SetValue(0) self.scBY.SetRange(0, self.rows-1) self.scBY.SetValue(0) self.setSegmentList() self.rbHTrace.SetValue(True) self.setHTrace() self.updateTitle() def onLoad(self, evt): if self.modified: if not self.abandonChanges(): return dlg = wx.FileDialog( self, message="Choose a proto-board template...", defaultDir=self.settings.templDir, defaultFile="", wildcard=wildcard, style=wx.OPEN ) rc = dlg.ShowModal() if rc == wx.ID_OK: path = dlg.GetPath() dlg.Destroy() if rc != wx.ID_OK: return pb = self.parent.loadBoard(path) if pb is None: dlg = wx.MessageDialog(self, 'Error loading proto-board template file: ' + path, 'Load Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return self.fileName = path self.updateTitle() dsc = pb.getDescription() if dsc is None: self.tcDesc.SetValue("") else: self.tcDesc.SetValue(dsc) self.cols, self.rows = pb.getSize() self.scRows.SetValue(self.rows) self.scCols.SetValue(self.cols) self.scAX.SetRange(0, self.cols-1) self.scBX.SetRange(0, self.cols-1) self.scAY.SetRange(0, self.rows-1) self.scBY.SetRange(0, self.rows-1) self.segments = [] ht = pb.getHTraces() for t in ht: self.addSegment(Segment(STYPE_HTRACE, t[0], t[1], t[2])) vt = pb.getVTraces() for t in vt: self.addSegment(Segment(STYPE_VTRACE, t[0], t[1], t[2])) hs, vs = pb.getSkips() for s in hs: self.addSegment(Segment(STYPE_HSKIP, s, None, None)) for s in vs: self.addSegment(Segment(STYPE_VSKIP, s, None, None)) self.setSegmentList() self.createProtoBoard() self.setModified(False) def setModified(self, flag=True): self.modified = flag def abandonChanges(self): if self.modified: dlg = wx.MessageDialog(self, 'Are you sure you want to exit?\nPending changes will be lost', 'Changes pending', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) rc = dlg.ShowModal() dlg.Destroy() if rc == wx.ID_NO: return False return True def onSave(self, evt): if self.fileName is None: self.onSaveAs(None) return self.saveToFile(self.fileName) def onSaveAs(self, evt): dfn = "" if not self.fileName is None: dfn = self.fileName dlg = wx.FileDialog( self, message="Save proto board template as ...", defaultDir=os.getcwd(), defaultFile=dfn, wildcard=wildcard, style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT ) rc = dlg.ShowModal() if rc == wx.ID_OK: path = dlg.GetPath() dlg.Destroy() if rc != wx.ID_OK: return if self.saveToFile(path): self.fileName = path self.updateTitle() def saveToFile(self, fn): pb = ProtoBoard(self.cols, self.rows) dsc = self.tcDesc.GetValue().strip() if dsc == "": pb.setDescription(None) else: pb.setDescription(dsc) pb.clearTraces() pb.clearSkips() for s in self.segments: s.addSegment(pb) try: fp = open(fn, "w") fp.write(pb.getXml(includeDescription=True)) fp.write("\n") fp.close() except: dlg = wx.MessageDialog(self, 'Error writing to file ' + fn, 'Save Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return False self.setModified(False) dlg = wx.MessageDialog(self, 'Proto Board template saved to ' + fn, 'Saved', wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() return True def onPreview(self, evt): self.createProtoBoard() def createProtoBoard(self): self.pb = ProtoBoard(self.cols, self.rows) self.updateProtoBoard(False) if not self.pbPrev is None: try: self.prevPosition = self.pbPrev.GetPosition() self.pbPrev.Destroy() except wx.PyDeadObjectError: self.pbPrev = None self.prevPosition = [-1, -1] self.pbPrev = ProtoBoardPreview(self.parent, self.pb, self.prevPosition, self.settings) self.pbPrev.Show() if len(self.segments) > 0: s = self.segments[-1] self.hiLightPos(s.getFirstPos()) def hiLightPos(self, pos): if self.pbPrev is None: return self.pbPrev.setHiLightedPos(pos) def updateProtoBoard(self, refresh=True): self.pb.clearTraces() self.pb.clearSkips() for s in self.segments: s.addSegment(self.pb) if refresh: if not self.pbPrev is None: try: self.pbPrev.refresh() except wx.PyDeadObjectError: self.pbPrev = None def onSpinRow(self, evt): self.setModified() nr = self.scRows.GetValue() self.scAY.SetRange(0, nr-1) self.scBY.SetRange(0, nr-1) self.rows = nr self.limitSegments() self.createProtoBoard() def onSpinCol(self, evt): self.setModified() nc = self.scCols.GetValue() self.scAX.SetRange(0, nc-1) self.scBX.SetRange(0, nc-1) self.cols = nc self.limitSegments() self.createProtoBoard() def setSegmentList(self): self.lbSegments.Set([s.getStr() for s in self.segments]) def onSegmentSelect(self, evt): self.selectedSegment = self.lbSegments.GetSelection() if self.selectedSegment is None: self.hiLightPos(None) return if self.selectedSegment == wx.NOT_FOUND: self.hiLightPos(None) return if self.selectedSegment < 0 or self.selectedSegment >= len(self.segments): self.hiLightPos(None) return pos = self.segments[self.selectedSegment].getFirstPos() self.hiLightPos(pos) def limitSegments(self): delSeg = [] for sx in range(len(self.segments)): deleteSeg, chg = self.segments[sx].limitValues(self.cols, self.rows) if deleteSeg: delSeg.append(sx) if deleteSeg or chg: self.setModified() for sx in delSeg[::-1]: del self.segments[sx] self.setSegmentList() def onAdd(self, evt): self.setModified() rpt = self.cbRepeat.GetValue() if self.stype == STYPE_HTRACE: ax = self.scAX.GetValue() ay = self.scAY.GetValue() bx = self.scBX.GetValue() by = self.scBY.GetValue() tlen = bx - ax + 1 if ax > bx: t = ax ax = bx bx = t if ay > by: t = ay ay = by by = t if rpt: while True: for r in range(ay, by+1): self.addSegment(Segment(self.stype, ax, bx, r)) ax += tlen bx += tlen if bx >= self.cols: break else: for r in range(ay, by+1): self.addSegment(Segment(self.stype, ax, bx, r)) elif self.stype == STYPE_VTRACE: ax = self.scAX.GetValue() ay = self.scAY.GetValue() bx = self.scBX.GetValue() by = self.scBY.GetValue() tlen = by - ay + 1 if ax > bx: t = ax ax = bx bx = t if ay > by: t = ay ay = by by = t if rpt: while True: for c in range(ax, bx+1): self.addSegment(Segment(self.stype, c, ay, by)) ay += tlen by += tlen if by >= self.rows: break else: for c in range(ax, bx+1): self.addSegment(Segment(self.stype, c, ay, by)) elif self.stype == STYPE_HSKIP: self.addSegment(Segment(self.stype, self.scAY.GetValue(), None, None)) elif self.stype == STYPE_VSKIP: self.addSegment(Segment(self.stype, self.scAX.GetValue(), None, None)) self.setSegmentList() self.selectedSegment = len(self.segments)-1 self.lbSegments.SetSelection(self.selectedSegment) self.updateProtoBoard() def addSegment(self, seg): for s in self.segments: if s.getValues() == seg.getValues(): return False self.segments.append(seg) return True def onDel(self, evt): if self.selectedSegment is None: return if self.selectedSegment == wx.NOT_FOUND: return if self.selectedSegment < 0: return if self.selectedSegment >= len(self.segments): return self.setModified() del self.segments[self.selectedSegment] self.setSegmentList() if self.selectedSegment >= len(self.segments): self.selectedSegment = len(self.segments) - 1 if self.selectedSegment < 0: self.selectedSegment = wx.NOT_FOUND else: self.lbSegments.SetSelection(self.selectedSegment) else: self.lbSegments.SetSelection(self.selectedSegment) self.updateProtoBoard() def onHTrace(self, evt): self.setHTrace() def setHTrace(self): self.stype = STYPE_HTRACE self.scAX.Enable(True) self.scAY.Enable(True) self.scBX.Enable(True) self.scBY.Enable(True) def onVTrace(self, evt): self.stype = STYPE_VTRACE self.scAX.Enable(True) self.scAY.Enable(True) self.scBX.Enable(True) self.scBY.Enable(True) def onHSkip(self, evt): self.stype = STYPE_HSKIP self.scAX.Enable(False) self.scAY.Enable(True) self.scBX.Enable(False) self.scBY.Enable(False) def onVSkip(self, evt): self.stype = STYPE_VSKIP self.scAX.Enable(True) self.scAY.Enable(False) self.scBX.Enable(False) self.scBY.Enable(False) def onClose(self, evt): if self.modified: if not self.abandonChanges(): return if not self.pbPrev is None: try: self.pbPrev.Destroy() except wx.PyDeadObjectError: self.pbPrev = None self.EndModal(wx.ID_OK)
class NewFileDialog(wx.Dialog): def __init__(self, parent): self.parent = parent self.settings = parent.settings self.images = parent.settings.images self.chosenTemplate = None self.pb = None title = "New Proto-board file" wx.Dialog.__init__(self, parent, wx.ID_ANY, title, size=(100, 100)) self.SetBackgroundColour("white") self.Bind(wx.EVT_CLOSE, self.onClose) sizer = wx.BoxSizer(wx.VERTICAL) sizer.AddSpacer((10, 10)) hsizer = wx.BoxSizer(wx.HORIZONTAL) hsizer.AddSpacer((20, 10)) box = wx.StaticBox(self, -1, "Choose an existing template") tmplSizer = wx.StaticBoxSizer(box, wx.VERTICAL) self.templates = [x for x in sorted(os.listdir(self.settings.templDir)) if x.endswith(".pbt")] self.descText = {} for t in self.templates: self.descText[t] = self.getTemplateDesc(os.path.join(self.settings.templDir, t)) self.chTempl = wx.Choice(self, wx.ID_ANY, choices = self.templates) self.chTempl.Bind(wx.EVT_CHOICE, self.onTemplChoice) if len(self.templates) > 0: self.chTempl.SetSelection(0) self.chosenTemplate = self.templates[0] tmplSizer.Add(self.chTempl, 0, wx.ALL, 10) self.tbTmplOk = wx.BitmapButton(self, wx.ID_ANY, self.images.pngOk, size=BDIM) self.setTemplateHelp() self.Bind(wx.EVT_BUTTON, self.onTmplOk, self.tbTmplOk) tmplSizer.Add(self.tbTmplOk, 0, wx.ALIGN_CENTER) hsizer.Add(tmplSizer, 0, wx.EXPAND) hsizer.AddSpacer((10, 10)) box = wx.StaticBox(self, -1, "Choose proto board parameters") rightSizer = wx.StaticBoxSizer(box, wx.VERTICAL) rightSizer.AddSpacer((20, 20)) t1 = wx.StaticText(self, wx.ID_ANY, "Columns:") self.scCols = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scCols.SetRange(5,100) self.scCols.SetValue(5) t2 = wx.StaticText(self, wx.ID_ANY, "Rows:") self.scRows = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scRows.SetRange(5,100) self.scRows.SetValue(5) t3 = wx.StaticText(self, wx.ID_ANY, "Trace Length:") self.scTraces = wx.SpinCtrl(self, wx.ID_ANY, size=(50, -1)) self.scTraces.SetRange(1,20) self.scTraces.SetValue(1) t4 = wx.StaticText(self, wx.ID_ANY, "Full Length:") self.cbFull = wx.CheckBox(self, wx.ID_ANY, "") t5 = wx.StaticText(self, wx.ID_ANY, "Vertical Traces:") self.cbVert = wx.CheckBox(self, wx.ID_ANY, "") isizer = wx.FlexGridSizer(cols=4, hgap=6, vgap=6) isizer.AddMany([ t1, self.scCols, t2, self.scRows, t3, self.scTraces, t4, self.cbFull, t5, self.cbVert]) rightSizer.Add(isizer, 1, wx.ALIGN_CENTER_HORIZONTAL|wx.LEFT|wx.RIGHT, 10) rightSizer.AddSpacer((10, 10)) btnSizer=wx.BoxSizer(wx.HORIZONTAL) self.tbOk = wx.BitmapButton(self, wx.ID_ANY, self.images.pngOk, size=BDIM) self.tbOk.SetToolTipString("Create new proto-board file") self.Bind(wx.EVT_BUTTON, self.onOk, self.tbOk) btnSizer.Add(self.tbOk) btnSizer.AddSpacer((20, 20)) self.tbCancel = wx.BitmapButton(self, wx.ID_ANY, self.images.pngCancel, size=BDIM) self.tbCancel.SetToolTipString("Exit without creating new file") self.Bind(wx.EVT_BUTTON, self.onClose, self.tbCancel) btnSizer.Add(self.tbCancel) rightSizer.Add(btnSizer, 0, wx.ALIGN_CENTER_HORIZONTAL) hsizer.Add(rightSizer, 0, wx.EXPAND) hsizer.AddSpacer((20, 10)) sizer.Add(hsizer) sizer.AddSpacer((20, 20)) self.SetSizer(sizer) self.Fit() def getTemplateDesc(self, fnTmpl): try: with open(fnTmpl, "r") as x: xml = x.read() except: return None xmldoc = XMLDoc(xml, makelist=["trace", "cut", "removal", "wire", "component"]) root = xmldoc.getRoot() try: return root.description except AttributeError: return None def onTemplChoice(self, evt): self.chosenTemplate = self.chTempl.GetStringSelection() self.setTemplateHelp() def setTemplateHelp(self): if self.chosenTemplate is None: self.tbTmplOk.SetToolTipString("Create based on a template") elif self.descText[self.chosenTemplate] is None: self.tbTmplOk.SetToolTipString("Create using template %s" % self.chosenTemplate) else: self.tbTmplOk.SetToolTipString("Create using %s" % self.descText[self.chosenTemplate]) def getData(self): return self.pb def onTmplOk(self, evt): i = self.chTempl.GetSelection() fn = os.path.join(self.settings.templDir, self.chTempl.GetString(i)) self.pb = self.parent.loadBoard(fn) self.EndModal(wx.ID_OK) def onOk(self, evt): r = self.scRows.GetValue() c = self.scCols.GetValue() vertical = self.cbVert.IsChecked() if self.cbFull.IsChecked(): if vertical: tl = r else: tl = c else: tl = self.scTraces.GetValue() self.pb = ProtoBoard(c, r) if vertical: if tl > r: tl = r for i in range(c): for j in range(0, r-tl+1, tl): self.pb.addVTrace(i, j, j+tl-1) nl = r % tl if nl != 0: for i in range(c): self.pb.addVTrace(i, r-nl, r-1) else: if tl > c: tl = c for i in range(r): for j in range(0, c-tl+1, tl): self.pb.addHTrace(j, j+tl-1, i) nl = c % tl if nl != 0: for i in range(r): self.pb.addHTrace(c-nl, c-1, i) self.EndModal(wx.ID_OK) def onClose(self, evt): self.EndModal(wx.ID_CANCEL)
def adapermaprotoh(n): pb = ProtoBoard(n, 18) for c in range(n): pb.addVTrace(c, 3, 7) pb.addVTrace(c, 10, 14) pb.addHSkip(2) pb.addHSkip(8) pb.addHSkip(9) pb.addHSkip(15) pb.addHTrace(0, n - 1, 0) pb.addHTrace(0, n - 1, 1) pb.addHTrace(0, n - 1, 16) pb.addHTrace(0, n - 1, 17) return pb, "ada_permaproto_%d_h.pb" % n
def saveToFile(self, fn): pb = ProtoBoard(self.cols, self.rows) dsc = self.tcDesc.GetValue().strip() if dsc == "": pb.setDescription(None) else: pb.setDescription(dsc) pb.clearTraces() pb.clearSkips() for s in self.segments: s.addSegment(pb) try: fp = open(fn, "w") fp.write(pb.getXml(includeDescription=True)) fp.write("\n") fp.close() except: dlg = wx.MessageDialog(self, 'Error writing to file ' + fn, 'Save Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return False self.setModified(False) dlg = wx.MessageDialog(self, 'Proto Board template saved to ' + fn, 'Saved', wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() return True
def adapermaprotoh(n): pb = ProtoBoard(n, 18) for c in range(n): pb.addVTrace(c, 3, 7) pb.addVTrace(c, 10, 14) pb.addHSkip(2) pb.addHSkip(8) pb.addHSkip(9) pb.addHSkip(15) pb.addHTrace(0, n-1, 0) pb.addHTrace(0, n-1, 1) pb.addHTrace(0, n-1, 16) pb.addHTrace(0, n-1, 17) return pb, "ada_permaproto_%d_h.pb" % n
def loadBoard(self, fn): try: with open(fn, "r") as x: xml = x.read() except: return None xmldoc = XMLDoc( xml, makelist=["trace", "cut", "removal", "wire", "component"]) compID.reInit() root = xmldoc.getRoot() sz = [int(x) for x in str(root.size).split(',')] pb = ProtoBoard(sz[0], sz[1]) try: pb.setDescription((str(root.description))) except AttributeError: pb.setDescription(None) try: tl = root.htraces.trace except AttributeError: tl = [] for t in tl: trc = [int(x) for x in str(t).split(',')] pb.addHTrace(trc[0], trc[1], trc[2]) try: tl = root.vtraces.trace except AttributeError: tl = [] for t in tl: trc = [int(x) for x in str(t).split(',')] pb.addVTrace(trc[0], trc[1], trc[2]) try: s = str(root.hskips).strip() except AttributeError: s = "" if len(s) > 0: for sk in s.split(','): pb.addHSkip(int(sk)) try: s = str(root.vskips).strip() except AttributeError: s = "" if len(s) > 0: for sk in s.split(','): pb.addVSkip(int(sk)) try: cl = root.hcuts.cut except AttributeError: cl = [] for c in cl: cut = [int(x) for x in str(c).split(',')] pb.addHCut(cut[0], cut[1], cut[2]) try: cl = root.vcuts.cut except AttributeError: cl = [] for c in cl: cut = [int(x) for x in str(c).split(',')] pb.addVCut(cut[0], cut[1], cut[2]) try: rl = root.removals.removal except AttributeError: rl = [] for r in rl: rmv = [int(x) for x in str(r).split(',')] pb.traceRemove([rmv[0], rmv[1]]) try: wirelist = root.wires.wire except AttributeError: wirelist = [] for w in wirelist: s = str(w.pointa) pta = [int(x) for x in s.split(',')] s = str(w.pointb) ptb = [int(x) for x in s.split(',')] s = str(w.color) clr = [int(x) for x in s.split(',')] c = StretchComponent(WIRENAME, pta, ptb, LT_WIRE) pb.addWire(c, wx.Colour(clr[0], clr[1], clr[2])) try: complist = root.components.component except AttributeError: complist = [] cl = self.settings.fixedComponentList for c in complist: tp = str(c.type) cid = str(c.id) nm = str(c.name) value = str(c.value) s = str(c.anchor) vw = int(str(c.view)) anchor = [int(x) for x in s.split(',')] comp = cl.getComponent(tp)[0] comp.setID(cid) comp.setName(nm) comp.setValue(value) comp.setAnchor(anchor) cl.setView(comp, vw) pb.addComponent(comp) compID.reserveID(cid) try: complist = root.stretchcomponents.component except AttributeError: complist = [] cl = self.settings.stretchComponentList for c in complist: tp = str(c.type) cid = str(c.id) nm = str(c.name) value = str(c.value) s = str(c.pointa) pta = [int(x) for x in s.split(',')] s = str(c.pointb) ptb = [int(x) for x in s.split(',')] comp = cl.getComponent(tp)[0] comp.setID(cid) comp.setP1(pta) comp.setP2(ptb) comp.setName(nm) comp.setValue(value) pb.addStretchComponent(comp) compID.reserveID(cid) try: complist = root.growcomponents.component except AttributeError: complist = [] cl = self.settings.growComponentList for c in complist: tp = str(c.type) cid = str(c.id) nm = str(c.name) value = str(c.value) s = str(c.pointa) pta = [int(x) for x in s.split(',')] s = str(c.pointb) ptb = [int(x) for x in s.split(',')] comp = cl.getComponent(tp)[0] comp.setID(cid) comp.setP1(pta) comp.setP2(ptb) comp.setName(nm) comp.setValue(value) pb.addGrowComponent(comp) compID.reserveID(cid) pb.setModified(False) return pb
def adapermaprotov(n): pb = ProtoBoard(18, n) for r in range(n): pb.addHTrace(3, 7, r) pb.addHTrace(10, 14, r) pb.addVSkip(2) pb.addVSkip(8) pb.addVSkip(9) pb.addVSkip(15) pb.addVTrace(0, 0, n - 1) pb.addVTrace(1, 0, n - 1) pb.addVTrace(16, 0, n - 1) pb.addVTrace(17, 0, n - 1) return pb, "ada_permaproto_%d_v.pb" % n
def loadBoard(self, fn): try: with open(fn, "r") as x: xml = x.read() except: return None xmldoc = XMLDoc(xml, makelist=["trace", "cut", "removal", "wire", "component"]) compID.reInit() root = xmldoc.getRoot() sz = [int(x) for x in str(root.size).split(',')] pb = ProtoBoard(sz[0], sz[1]) try: pb.setDescription((str(root.description))) except AttributeError: pb.setDescription(None) try: tl = root.htraces.trace except AttributeError: tl = [] for t in tl: trc = [int(x) for x in str(t).split(',')] pb.addHTrace(trc[0], trc[1], trc[2]) try: tl = root.vtraces.trace except AttributeError: tl = [] for t in tl: trc = [int(x) for x in str(t).split(',')] pb.addVTrace(trc[0], trc[1], trc[2]) try: s = str(root.hskips).strip() except AttributeError: s = "" if len(s) > 0: for sk in s.split(','): pb.addHSkip(int(sk)) try: s = str(root.vskips).strip() except AttributeError: s = "" if len(s) > 0: for sk in s.split(','): pb.addVSkip(int(sk)) try: cl = root.hcuts.cut except AttributeError: cl = [] for c in cl: cut = [int(x) for x in str(c).split(',')] pb.addHCut(cut[0], cut[1], cut[2]) try: cl = root.vcuts.cut except AttributeError: cl = [] for c in cl: cut = [int(x) for x in str(c).split(',')] pb.addVCut(cut[0], cut[1], cut[2]) try: rl = root.removals.removal except AttributeError: rl = [] for r in rl: rmv = [int(x) for x in str(r).split(',')] pb.traceRemove([rmv[0], rmv[1]]) try: wirelist = root.wires.wire except AttributeError: wirelist = [] for w in wirelist: s = str(w.pointa) pta = [int(x) for x in s.split(',')] s = str(w.pointb) ptb = [int(x) for x in s.split(',')] s = str(w.color) clr = [int(x) for x in s.split(',')] c = StretchComponent(WIRENAME, pta, ptb, LT_WIRE) pb.addWire(c, wx.Colour(clr[0], clr[1], clr[2])) try: complist = root.components.component except AttributeError: complist = [] cl = self.settings.fixedComponentList for c in complist: tp = str(c.type) cid = str(c.id) nm = str(c.name) value = str(c.value) s = str(c.anchor) vw = int(str(c.view)) anchor = [int(x) for x in s.split(',')] comp = cl.getComponent(tp)[0] comp.setID(cid) comp.setName(nm) comp.setValue(value) comp.setAnchor(anchor) cl.setView(comp, vw) pb.addComponent(comp) compID.reserveID(cid) try: complist = root.stretchcomponents.component except AttributeError: complist = [] cl = self.settings.stretchComponentList for c in complist: tp = str(c.type) cid = str(c.id) nm = str(c.name) value = str(c.value) s = str(c.pointa) pta = [int(x) for x in s.split(',')] s = str(c.pointb) ptb = [int(x) for x in s.split(',')] comp = cl.getComponent(tp)[0] comp.setID(cid) comp.setP1(pta) comp.setP2(ptb) comp.setName(nm) comp.setValue(value) pb.addStretchComponent(comp) compID.reserveID(cid) try: complist = root.growcomponents.component except AttributeError: complist = [] cl = self.settings.growComponentList for c in complist: tp = str(c.type) cid = str(c.id) nm = str(c.name) value = str(c.value) s = str(c.pointa) pta = [int(x) for x in s.split(',')] s = str(c.pointb) ptb = [int(x) for x in s.split(',')] comp = cl.getComponent(tp)[0] comp.setID(cid) comp.setP1(pta) comp.setP2(ptb) comp.setName(nm) comp.setValue(value) pb.addGrowComponent(comp) compID.reserveID(cid) pb.setModified(False) return pb