def getSymbol(param, properties,parent=None,scene=None,): from spycelib import block, text carry = param['carry'] if 'carry' in param else 0 tmin = str(properties['min']) if 'min' in properties else '0' tmax = str(properties['max']) if 'max' in properties else '1' include_max = param['include_max'][0] if 'include_max' in param else 'False' attributes = dict() attributes['name'] = name attributes['libname'] = libname inp, outp, _ = ports(param) w2 = outp[0][1] if carry: attributes['bbox'] = (-w2, -40, 2*w2, 80) else: attributes['bbox'] = (-w2, -40, 2*w2, 80) attributes['input'] = inp attributes['output'] = outp attributes['icon'] = views['icon'] b = block.Block(attributes,param,properties, name, libname, parent, scene) # display limits lmin = text.textItem(tmin, anchor=7, parent=b) lmin.setPos(-w2+3, 20) lmin.setMutable(False) if include_max == "True": tmax += '-1' lmax = text.textItem(tmax, anchor=3, parent=b) lmax.setPos(w2-1, -15) lmax.setMutable(False) return b
def getSymbol( param, properties, parent=None, scene=None, ): from spycelib import const, block, text eq = properties['eq'] if 'eq' in properties else '{i0} == 0' attributes = dict() attributes['name'] = name attributes['libname'] = libname inp, outp, inout = ports(param) attributes['input'] = inp attributes['output'] = outp _, x0, y0 = inp[0] _, x1, y1 = inp[-1] _, x2, y2 = outp[0] w = x2 - x0 h = y1 - y0 attributes['bbox'] = [x0, y0 - 10, w, h + 20 + const.PD] b = block.Block(attributes, param, properties, name, libname, parent, scene) # display equation tt = eq ll = text.textItem(tt, anchor=5, parent=b) ll.setPos((x1 + x2) / 2, y1 + const.PD / 2 - (y0 + y1) / 2) ll.setMutable(False) return b
def getSymbol( param, properties, parent=None, scene=None, ): from spycelib import block, text if 'sel' in param: sel = [eval(i) for i in param['sel'].split()] else: sel = [0, 1] attributes = dict() attributes['name'] = name attributes['libname'] = libname inp, outp, _ = ports(param) attributes['input'] = inp attributes['output'] = outp attributes['icon'] = views['icon'] b = block.Block(attributes, param, properties, name, libname, parent, scene) for p in b.ports(): if p.porttype == 'input': t = p.label.text() if t.startswith('.i'): ix = int(p.label.text()[2:]) s = sel[ix] l = text.textItem(str(s), anchor=4, parent=b) x, y = p.pos().x(), p.pos().y() l.setPos(x + 5, y) l.setMutable(False) return b
def getSymbol(param, properties,parent=None,scene=None,): from spycelib import block, text attributes = dict() attributes['name'] = name attributes['libname'] = libname attributes['input'] = [] attributes['output'] = [] # attributes['icon'] = views['icon'] b = block.Block(attributes,param,properties, name, libname, parent, scene) # display properties t = [] for k in sorted(properties.keys()): v = properties[k] t.append('{}'.format(v)) if len(t) == 0: t = ['example: pi = 3.1415'] lbl = text.textItem('\n'.join(t), anchor=7, parent=b) lbl.setMutable(False) width = lbl.boundingRect().width() height = lbl.boundingRect().height() w = max(int(width/20)*20 + 20, 40) h = max(int(height/20)*20 + 20, 40) b.bbox = [-w//2, -h//2, w, h] b.setup() x, y = b.center.x(), b.center.y() lbl.setPos(-w//2, -h//2) return b
def getSymbol( param, properties, parent=None, scene=None, ): from spycelib import block, text ifcond = param['ifcond'] if 'ifcond' in param else '{i0} == 1' ifcond = [i.strip() for i in ifcond.split(',')] ncond = len(ifcond) attributes = dict() attributes['name'] = name attributes['libname'] = libname inp, outp, _ = ports(param) attributes['input'] = inp attributes['output'] = outp attributes['icon'] = views['icon'] b = block.Block(attributes, param, properties, name, libname, parent, scene) for p in b.ports(): t = p.label.text() if t.startswith('.if'): c = int(t.split('_')[-1]) tt = 'if' if c == 0 else 'else' if c == ncond else 'elif' if tt.endswith('if'): tt += ' {}'.format(ifcond[c]) l = text.textItem(tt, anchor=4, parent=b) x, y = p.pos().x(), p.pos().y() l.setPos(x + 5, y) l.setMutable(False) return b
def portAddType(self, event): item = self.scene.item if not isPort(item): error('use on nodes/pins') return if item.signalType: dialog = textLineDialog('Signal type: ','Signal type',item.signalType.text()) else: dialog = textLineDialog('Signal type: ','Signal type') ret = dialog.getLabel() if ret: txt = fix_code(ret).strip() # clean up using autopep8 item.signalType = textItem(txt, anchor=8, parent=item) item.signalType.setBrush(colors['signalType']) font = item.signalType.font() font.setItalic(True) item.signalType.setFont(font)
def getSymbol(param, properties, parent=None, scene=None): global name, libname from spycelib import block, const, text from Qt import QtGui, QtWidgets, QtCore # see https://github.com/mottosso/Qt.py A = param['A'] if 'A' in param else '++' Z = param['Z'] if 'Z' in param else '+' operator = properties['op'][0] if 'op' in properties else '&' inp, outp, inout = ports(param) _, left, top = inp[0] bottom = inp[-1][2] right = outp[0][1] pw = const.PW d = 8 # size of circle w, h = right - left, bottom - top + 20 # if h < const.BHmin: # dh = const.BHmin - h # else: # dh = 0 dh = 0 attributes = dict() _name = properties.pop('_name') if '_name' in properties else name _libname = properties.pop( '_libname') if '_libname' in properties else libname attributes['name'] = _name attributes['libname'] = _libname attributes['input'] = inp attributes['output'] = outp attributes['bbox'] = (left + d, top - 10 - dh / 2.0, w - 2 * d, h + dh) attributes['icon'] = views['icon'] b = block.Block(attributes, param, properties, _name, _libname, parent, scene) # add circles for inverted outputs, and wires for non-inverted outputs pi = QtWidgets.QGraphicsPathItem(b) pi.setPen(QtGui.QPen(const.colors['block'])) pp = QtGui.QPainterPath() for n, x, y in outp: if n.startswith('.zn'): pp.addEllipse(x - pw / 2.0 - d, y - d / 2.0, d, d) else: pp.moveTo(x - pw / 2.0, y) pp.lineTo(x - pw / 2.0 - d, y) for n, x, y in inp: if n.startswith('.an'): pp.addEllipse(x + pw / 2.0, y - d / 2.0, d, d) else: pp.moveTo(x + pw / 2.0, y) pp.lineTo(x + pw / 2.0 + d, y) pi.setPath(pp) pi.setPos(-b.center) # create a new label in the centre ll = text.textItem('{}'.format(operator), anchor=5, parent=b) font = ll.font() font.fromString('Sans Serif,16') ll.setFont(font) # ll.setPos(0,0) ll.setMutable(False) return b