def __init__(self, library, fname, mypath, runflag, parent=None): super(SupsiSimMainWindow, self).__init__(parent) self.resize(1024, 768) self.centralWidget = QWidget(self) self.verticalLayout = QVBoxLayout(self.centralWidget) #self.verticalLayout.setMargin(0) self.view = GraphicsView(self.centralWidget) self.view.setMouseTracking(True) self.scene = Scene(self) self.view.setScene(self.scene) self.view.setRenderHint(QPainter.Antialiasing) self.verticalLayout.addWidget(self.view) self.setCentralWidget(self.centralWidget) self.addactions() self.addMenubar() self.addToolbars() self.filename = fname self.path = mypath self.library = library self.runflag = runflag if fname != 'untitled': self.scene.loadDgm(self.getFullFileName()) self.setWindowTitle(self.filename) self.status = self.statusBar() self.evpos = QtCore.QPointF(0, 0) self.editor = Editor(self) self.editor.install(self.scene) self.status.showMessage('Ready') self.modified = False
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.centralWidget = QWidget() self.resize(800, 500) self.setWindowTitle('Library') self.libConfig = [] self.readLib() self.closeFlag = False self.tabs = QTabWidget() tabS = '' index = 0 for el in self.libConfig: if el['lib'] != tabS: if tabS != '': tab = QWidget() layout = QVBoxLayout() layout.addWidget(view) tab.setLayout(layout) self.tabs.addTab(tab, tabS) if tabS == 'common': index = self.tabs.indexOf(tab) tabS = el['lib'] diagram = CompViewer(self) view = QGraphicsView(diagram) diagram.compLock = True i = 1 io = (el['st'] == 1) b = Block(None, diagram, el['name'], el['ip'], el['op'], io, el['icon'], el['params'], False) px = (i - 1) % 2 py = (i - 1) / 2 b.setPos(px * 150, py * 150) i += 1 tab = QWidget() layout = QVBoxLayout() layout.addWidget(view) tab.setLayout(layout) self.tabs.addTab(tab, tabS) layout = QHBoxLayout() layout.addWidget(self.tabs) self.widget = QWidget() self.widget.setLayout(layout) self.setCentralWidget(self.widget) self.tabs.setTabPosition(QTabWidget.West) self.tabs.setCurrentIndex(index)
class Library(QMainWindow): ''' ''' def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.centralWidget = QWidget() self.resize(800, 500) self.setWindowTitle('Library') self.libConfig = [] self.readLib() self.closeFlag = False self.tabs = QTabWidget() tabS = '' index = 0 for el in self.libConfig: if el['lib'] != tabS: if tabS != '': tab = QWidget() layout = QVBoxLayout() layout.addWidget(view) tab.setLayout(layout) self.tabs.addTab(tab, tabS) if tabS == 'common': index = self.tabs.indexOf(tab) tabS = el['lib'] diagram = CompViewer(self) view = QGraphicsView(diagram) diagram.compLock = True i = 1 io = (el['st'] == 1) b = Block(None, diagram, el['name'], el['ip'], el['op'], io, el['icon'], el['params'], False) px = (i - 1) % 2 py = (i - 1) / 2 b.setPos(px * 150, py * 150) i += 1 tab = QWidget() layout = QVBoxLayout() layout.addWidget(view) tab.setLayout(layout) self.tabs.addTab(tab, tabS) layout = QHBoxLayout() layout.addWidget(self.tabs) self.widget = QWidget() self.widget.setLayout(layout) self.setCentralWidget(self.widget) self.tabs.setTabPosition(QTabWidget.West) self.tabs.setCurrentIndex(index) def getBlock(self, fn): f = open(fn, 'r') d = f.read() f.close() d = json.loads(d) return d def readLib(self): commonDir = respath + 'blocks/blocks' userDir = os.environ.get('PYUSERBLKS') + '/blocks/' blkList = [] try: fn = open(commonDir + '/common.blks') for f in fn: f = f.rstrip() try: d = self.getBlock(respath + 'blocks/blocks/' + f) d['lib'] = 'common' blkList.append(d) except: try: d = self.getBlock(myDir + '/' + f) d['lib'] = 'common' blkList.append(d) except: pass fn.close() except: pass files = os.listdir(commonDir) for f in sorted(files): if f.endswith('.xblk'): d = self.getBlock(respath + 'blocks/blocks/' + f) blkList.append(d) try: files = os.listdir(userDir) for f in sorted(files): if f.endswith('.xblk'): d = self.getBlock(userDir + '/' + f) blkList.append(d) except: pass self.libConfig = sorted(blkList, key=lambda k: (k['lib'].lower())) def closeEvent(self, event): if self.closeFlag: event.accept() else: event.ignore()