class Form1(QMainWindow): def __init__(self,parent = None,name = None,fl = 0): QMainWindow.__init__(self,parent,name,fl) self.statusBar() self.image0 = QPixmap() self.image0.loadFromData(image0_data,"PNG") self.image1 = QPixmap() self.image1.loadFromData(image1_data,"PNG") self.image2 = QPixmap() self.image2.loadFromData(image2_data,"PNG") self.image3 = QPixmap() self.image3.loadFromData(image3_data,"PNG") if not name: self.setName("Form1") self.setCentralWidget(QWidget(self,"qt_central_widget")) self.addButton = QPushButton(self.centralWidget(),"addButton") self.addButton.setGeometry(QRect(620,20,111,31)) self.addButton.setAutoDefault(1) self.replaceButton = QPushButton(self.centralWidget(),"replaceButton") self.replaceButton.setGeometry(QRect(740,20,110,31)) self.replaceButton.setAutoDefault(1) self.deleteButton = QPushButton(self.centralWidget(),"deleteButton") self.deleteButton.setGeometry(QRect(860,20,111,31)) self.deleteButton.setAutoDefault(1) self.pushButton1 = QPushButton(self.centralWidget(),"pushButton1") self.pushButton1.setGeometry(QRect(290,430,121,41)) self.pushButton1.setAutoDefault(1) self.pushButton1_2 = QPushButton(self.centralWidget(),"pushButton1_2") self.pushButton1_2.setGeometry(QRect(420,430,121,41)) self.pushButton1_2.setAutoDefault(1) self.table1 = QTable(self.centralWidget(),"table1") self.table1.setGeometry(QRect(10,70,980,350)) self.table1.setNumRows(100) self.table1.setNumCols(100) self.table1.setReadOnly(1) self.table1.setSelectionMode(QTable.Single) self.lineEdit1 = QLineEdit(self.centralWidget(),"lineEdit1") self.lineEdit1.setGeometry(QRect(10,20,601,31)) self.fileNewAction = QAction(self,"fileNewAction") self.fileNewAction.setIconSet(QIconSet(self.image0)) self.fileOpenAction = QAction(self,"fileOpenAction") self.fileOpenAction.setIconSet(QIconSet(self.image1)) self.fileSaveAction = QAction(self,"fileSaveAction") self.fileSaveAction.setIconSet(QIconSet(self.image2)) self.fileSaveAsAction = QAction(self,"fileSaveAsAction") self.filePrintAction = QAction(self,"filePrintAction") self.filePrintAction.setIconSet(QIconSet(self.image3)) self.fileExitAction = QAction(self,"fileExitAction") self.helpContentsAction = QAction(self,"helpContentsAction") self.helpIndexAction = QAction(self,"helpIndexAction") self.helpAboutAction = QAction(self,"helpAboutAction") self.editSettingsAction = QAction(self,"editSettingsAction") self.menunew_itemAction = QAction(self,"menunew_itemAction") self.toolBar = QToolBar(QString(""),self,Qt.DockTop) self.fileNewAction.addTo(self.toolBar) self.fileOpenAction.addTo(self.toolBar) self.fileSaveAction.addTo(self.toolBar) self.fileSaveAsAction.addTo(self.toolBar) self.MenuBar = QMenuBar(self,"MenuBar") self.fileMenu = QPopupMenu(self) self.fileNewAction.addTo(self.fileMenu) self.fileOpenAction.addTo(self.fileMenu) self.fileSaveAction.addTo(self.fileMenu) self.fileSaveAsAction.addTo(self.fileMenu) self.fileMenu.insertSeparator() self.fileExitAction.addTo(self.fileMenu) self.MenuBar.insertItem(QString(""),self.fileMenu,1) self.Edit = QPopupMenu(self) self.editSettingsAction.addTo(self.Edit) self.MenuBar.insertItem(QString(""),self.Edit,2) self.helpMenu = QPopupMenu(self) self.helpAboutAction.addTo(self.helpMenu) self.MenuBar.insertItem(QString(""),self.helpMenu,3) self.languageChange() self.resize(QSize(1000,556).expandedTo(self.minimumSizeHint())) self.clearWState(Qt.WState_Polished) self.connect(self.fileExitAction,SIGNAL("activated()"),self.close) self.connect(self.pushButton1_2,SIGNAL("clicked()"),self.close) self.connect(self.table1,SIGNAL("pressed(int,int,int,const QPoint&)"),self.table_click) self.connect(self.addButton,SIGNAL("clicked()"),self.add_entry) self.connect(self.replaceButton,SIGNAL("clicked()"),self.replace_entry) self.connect(self.lineEdit1,SIGNAL("returnPressed()"),self.add_entry) self.connect(self.deleteButton,SIGNAL("clicked()"),self.delete_entry) self.connect(self.addButton,SIGNAL("clicked()"),self.lineEdit1.clear) self.connect(self.lineEdit1,SIGNAL("returnPressed()"),self.lineEdit1.clear) self.connect(self.replaceButton,SIGNAL("clicked()"),self.lineEdit1.clear) self.connect(self.deleteButton,SIGNAL("clicked()"),self.lineEdit1.clear) self.connect(self.pushButton1,SIGNAL("clicked()"),self.run_programs) self.connect(self.fileNewAction,SIGNAL("activated()"),self.new_graph) self.connect(self.editSettingsAction,SIGNAL("activated()"),self.display_config) self.connect(self.fileOpenAction,SIGNAL("activated()"),self.open_command) self.connect(self.fileSaveAction,SIGNAL("activated()"),self.save_command) self.connect(self.fileSaveAsAction,SIGNAL("activated()"),self.saveas_command) self.connect(self.helpAboutAction,SIGNAL("activated()"),self.show_about) self.setTabOrder(self.lineEdit1,self.addButton) self.setTabOrder(self.addButton,self.replaceButton) self.setTabOrder(self.replaceButton,self.deleteButton) self.setTabOrder(self.deleteButton,self.pushButton1) self.setTabOrder(self.pushButton1,self.pushButton1_2) self.setTabOrder(self.pushButton1_2,self.table1) def languageChange(self): self.setCaption(self.__tr("QTPlumb")) self.addButton.setText(self.__tr("Add")) self.replaceButton.setText(self.__tr("Replace")) self.deleteButton.setText(self.__tr("Delete")) self.pushButton1.setText(self.__tr("Run Programs")) self.pushButton1_2.setText(self.__tr("Close")) QToolTip.add(self.table1,self.__tr("Click on the spreadsheet to create connections")) QToolTip.add(self.lineEdit1,self.__tr("Enter your programs here")) self.fileNewAction.setText(self.__tr("New")) self.fileNewAction.setMenuText(self.__tr("&New")) self.fileNewAction.setAccel(self.__tr("Ctrl+N")) self.fileOpenAction.setText(self.__tr("Open")) self.fileOpenAction.setMenuText(self.__tr("&Open...")) self.fileOpenAction.setAccel(self.__tr("Ctrl+O")) self.fileSaveAction.setText(self.__tr("Save")) self.fileSaveAction.setMenuText(self.__tr("&Save")) self.fileSaveAction.setAccel(self.__tr("Ctrl+S")) self.fileSaveAsAction.setText(self.__tr("Save As")) self.fileSaveAsAction.setMenuText(self.__tr("Save &As...")) self.fileSaveAsAction.setAccel(QString.null) self.filePrintAction.setText(self.__tr("Print")) self.filePrintAction.setMenuText(self.__tr("&Print...")) self.filePrintAction.setAccel(self.__tr("Ctrl+P")) self.fileExitAction.setText(self.__tr("E&xit")) self.fileExitAction.setMenuText(self.__tr("E&xit")) self.fileExitAction.setAccel(QString.null) self.helpContentsAction.setText(self.__tr("Contents")) self.helpContentsAction.setMenuText(self.__tr("&Contents...")) self.helpContentsAction.setAccel(QString.null) self.helpIndexAction.setText(self.__tr("Index")) self.helpIndexAction.setMenuText(self.__tr("&Index...")) self.helpIndexAction.setAccel(QString.null) self.helpAboutAction.setText(self.__tr("About")) self.helpAboutAction.setMenuText(self.__tr("&About")) self.helpAboutAction.setAccel(QString.null) self.editSettingsAction.setText(self.__tr("Options")) self.editSettingsAction.setMenuText(self.__tr("Options")) self.menunew_itemAction.setText(self.__tr("new item")) self.menunew_itemAction.setMenuText(self.__tr("new item")) self.toolBar.setLabel(self.__tr("Tools")) if self.MenuBar.findItem(1): self.MenuBar.findItem(1).setText(self.__tr("&File")) if self.MenuBar.findItem(2): self.MenuBar.findItem(2).setText(self.__tr("Edit")) if self.MenuBar.findItem(3): self.MenuBar.findItem(3).setText(self.__tr("&Help")) def run_programs(self): import glob from commands import getoutput from thread import start_new_thread if len(glob.glob(getoutput("echo ~") + "/.qtplumb")) > 0: file = open(getoutput("echo ~") + "/.qtplumb", "r") command = file.readline() xterm_loc = file.readline() for i in range(0, 5): if xterm_loc != "\n": break xterm_loc = file.readline() file.close() command = command[0:(len(command) - 1)] command = xterm_loc + " -hold -e " + command else: command = "../testadj " for i in range(0, len(self.programs)): command += " \"%d:" % (i + 1) + self.programs[i] + "\" " command += " -e " for i in range(1, len(self.programs) + 2): for j in range(1, len(self.programs) + 2): if self.table1.text(i, j).ascii() == "X": command += " %d," % (i - 1) + "%d " % (j - 1) def command_runner(x): getoutput(command) start_new_thread(command_runner, (0, )) def table_click(self,row,col,button,point): if (row == 0) or (row > len(self.programs) + 1) or (col > (len(self.programs) + 1)) or ((row == 1) and (col == 0)): self.disable_ed() return if col == 0: self.selectedEntry = [row,col] self.replaceButton.setEnabled(1) self.deleteButton.setEnabled(1) self.lineEdit1.setText(self.table1.text(row,col)) return if self.table1.text(row, col).ascii() != "X": self.table1.setText(row, col, QString("X")) else: self.table1.setText(row, col, QString("")) self.disable_ed() def add_entry(self): s = self.lineEdit1.text().ascii() self.programs.append(s) self.table1.setText(len(self.programs) + 1, 0, s) self.table1.setText(0, len(self.programs) + 1, s) def replace_entry(self): s = self.lineEdit1.text().ascii() self.programs[self.selectedEntry[0] - 1] = s self.table1.setText(self.selectedEntry[0], 0, s) self.table1.setText(0, self.selectedEntry[0], s) def init_two(self): self.programs = [] self.table1.setText(0, 1, QString("Console")) self.table1.setText(1, 0, QString("Console")) self.disable_ed() self.filename = "" def delete_entry(self): self.table1.removeRow(self.selectedEntry[0]) self.table1.removeColumn(self.selectedEntry[0]) self.programs.pop(self.selectedEntry[0] - 2) self.disable_ed() def disable_ed(self): self.selectedEntry = [0,0] self.deleteButton.setEnabled(0) self.replaceButton.setEnabled(0) def new_graph(self): for i in range(0, len(self.programs) + 2): for j in range(0, len(self.programs) + 2): self.table1.clearCell(i, j) self.init_two() def open_command(self): from commands import getoutput if self.filename == "": temp = QFileDialog.getOpenFileName(getoutput("echo ~"), "Commands (*.cmd);;All Files (*.*)", self, "Save as", "Choose a file").ascii() else: temp = QFileDialog.getOpenFileName(self.filename, "Commands (*.cmd);;All Files (*.*)", self, "Save as", "Choose a file").ascii() if temp == None: return self.filename = temp file = open(self.filename, "r") command = file.read() file.close() def add_to_graph(s): self.lineEdit1.setText(s) self.add_entry() tempstring = "" mode = 1 for i in range(0, len(command)): if command[i] == '-' and mode == 1: if command[i + 1] == 'e': i += 2 mode = 2 if command[i] == ":" and mode == 1: i += 1 tempstring = "" while command[i] != '"' and command[i - 1] != '\\': tempstring += command[i] i += 1 add_to_graph(tempstring) if command[i] == ',' and mode == 2: tempstring = "" frm = 0 dest = 0 while command[i] != ' ': i -= 1 i += 1 while command[i] != ',': tempstring += command[i] i += 1 i += 1 frm = int(tempstring) tempstring = "" while command[i] != " " and command[i] != "\n": tempstring += command[i] i += 1 dest = int(tempstring) self.table1.setText(frm + 1, dest + 1, "X") def save_command(self): if self.filename == "": self.saveas_command() return command = "../testadj " for i in range(0, len(self.programs)): command += " \"%d:" % (i + 1) + self.programs[i] + "\" " command += "-e " for i in range(1, len(self.programs) + 1): for j in range(1, len(self.programs) + 2): if self.table1.text(i, j).ascii() == "X": command += " %d," % i + "%d " % (j - 1) file = open(self.filename, "w") file.write(command) file.write("\n") file.close() def saveas_command(self): from commands import getoutput if self.filename == "": temp = QFileDialog.getSaveFileName(getoutput("echo ~"), "Commands (*.cmd);;All Files (*.*)", self, "Save as", "Choose a file").ascii() else: temp = QFileDialog.getSaveFileName(self.filename, "Commands (*.cmd);;All Files (*.*)", self, "Save as", "Choose a file").ascii() if temp != None: self.filename = temp self.save_command() def show_about(self): from aboutbox import aboutBox box = aboutBox(self, "About", 0, 0) box.show() box.exec_loop() def display_config(self): from configbox import configBox box = configBox(self, "QTPlumb Config", 0, 0) box.init_two() box.show() box.exec_loop() def __tr(self,s,c = None): return qApp.translate("Form1",s,c)
class Routing(QWidget): """A variable-sized table with sliders, ideal for signal routing purposes. Args: rows (int), columns (int), route to self (bool), Parent (obj) (None),""" def __init__(self, row, col, routeToSelf = True, parent = None,name = None,fl = 0): QWidget.__init__(self,parent,name,fl) if not name: self.setName("Form4") self.routeToSelf = routeToSelf self.empty_cells = [] self.currentvalue = None #holds current slider value self.table1 = QTable(self,"table1") self.table1.setPaletteBackgroundColor(QColor(0,0,0)) self.table1.viewport().setPaletteBackgroundColor(QColor(0,0,0)) self.table1.setResizePolicy(QTable.AutoOne) self.table1.setVScrollBarMode(QTable.AlwaysOff) for r in range(self.table1.numRows()): self.table1.setRowHeight(r, 18) self.table1.setRowStretchable(r, False) pr = Param()#Holding param self.root_param.insertChild(pr) self.params.append(pr) for c in range(self.table1.numCols()): if r == 0: self.table1.setColumnWidth(c, self.columnwidth) if self.routeToSelf is True or r is not c: p = Param(type=float) pr.insertChild(p) self.table1.setCellWidget(r, c, ParamProgress(p, self.table1)) else: #do nothing #self.params[r].append(-1) self.empty_cells.append((r, c)) self.table1.setHScrollBarMode(QTable.AlwaysOff) self.table1.setShowGrid(0) self.table1.setReadOnly(1) self.table1.setSelectionMode(QTable.NoSelection) self.table1.setFocusPolicy(QWidget.NoFocus) self.root_param = Param() self.params = [] #holds all parent Params self.columnwidth = 50 self.setsize(row, col) self.adjustSize() def setsize(self, row, col): """set size of table: row, col Creates a parent Param for every row, with child params for every col. No other adjustments, namings or range settings are done here, but has to be done in the subclass, preferrably after the init of this class.""" self.table1.setNumRows(row) self.table1.setNumCols(col) self.setUpdatesEnabled(False) for r in range(self.table1.numRows()): self.table1.setRowHeight(r, 18) self.table1.setRowStretchable(r, False) pr = Param()#Holding param self.root_param.insertChild(pr) self.params.append(pr) for c in range(self.table1.numCols()): if r == 0: self.table1.setColumnWidth(c, self.columnwidth) if self.routeToSelf is True or r is not c: p = Param(type=float) pr.insertChild(p) self.table1.setCellWidget(r, c, ParamProgress(p, self.table1)) else: #do nothing #self.params[r].append(-1) self.empty_cells.append((r, c)) self.table1.viewport().adjustSize() self.table1.adjustSize() self.setUpdatesEnabled(True) def set_row_labels(self, lust): self.table1.setRowLabels(lust) #self.table1.viewport().adjustSize() self.table1.adjustSize() def set_col_labels(self, lust): self.table1.setColumnLabels(lust) self.table1.setTopMargin(18) #self.table1.viewport().adjustSize() self.table1.adjustSize() def params_reparent(self, parent): for p in self.params: parent.insertChild(p) def set_column_width(self, i): for c in range(self.table1.numCols()): self.table1.setColumnWidth(c, i) self.table1.adjustSize() self.table1.viewport().adjustSize() self.columnwidth = i def set_row_height(self, i): for c in range(self.table1.numRows()): self.table1.setRowHeight(c, i) self.table1.adjustSize() self.table1.viewport().adjustSize() def setlabels(self, row, col): """set labels for headers: row(list), col(list)""" for i, item in enumerate(row): self.table1.verticalHeader().setLabel(i, QString(item)) for i, item in enumerate(col): self.table1.horizontalHeader().setLabel(i, QString(item)) def clear_cell(self, r, c): self.table1.clearCellWidget(r, c) self.table1.setCellWidget(r, c, QFrame()) self.table1.cellWidget(r, c).setPaletteBackgroundColor(QColor(50, 50, 50)) self.empty_cells.append((r, c))
class Canvasinfo(QWidget): def __init__(self,parent = None,name = None,fl = 0): QWidget.__init__(self,parent,name,fl) if not name: self.setName("Canvasinfo") self.canvaslabels = QTable(self,"canvaslabels") self.canvaslabels.setNumCols(2) self.canvaslabels.horizontalHeader().setLabel(0,"X") self.canvaslabels.horizontalHeader().setLabel(1,"Y") self.canvaslabels.setNumRows(5) for i in range (5): self.canvaslabels.verticalHeader().setLabel(i, QIconSet(QPixmap(sys.path[0]+"/larm_utilities/sprite%d.png" % (i + 1))),QString.null) self.canvaslabels.setGeometry(QRect(0,20,300,128)) self.canvaslabels.setCursor(QCursor(13)) self.canvaslabels.setFocusPolicy(QTable.NoFocus) self.canvaslabels.setFrameShape(QTable.StyledPanel) self.canvaslabels.setResizePolicy(QTable.AutoOne) self.canvaslabels.setReadOnly(1) self.canvaslabels.setSelectionMode(QTable.NoSelection) self.canvaslabels.setFocusStyle(QTable.FollowStyle) self.label = QLabel(self,"label") self.label.setGeometry(QRect(0,0,300,20)) self.label.setPaletteForegroundColor(QColor('gold')) label_font = QFont(self.label.font()) label_font.setFamily("Pigiarniq Heavy") self.label.setFont(label_font) self.label.setAlignment(Qt.AlignCenter) self.canvaslabels.setPaletteBackgroundColor(QColor(50, 50, 50)) self.canvaslabels.setPaletteForegroundColor(QColor('gold')) self.canvaslabels.setColumnWidth(0, 132) self.canvaslabels.setColumnWidth(1, 132) self.canvaslabels.setShowGrid(False) self.clearWState(Qt.WState_Polished) self.connect(self,PYSIGNAL("showMachineLabel"),self.updateLabels) self.connect(self,PYSIGNAL("hideMachineLabel"),self.deleteLabels) def deleteLabels(self): self.label.setText(QString()) for r in range(5): for c in range(2): self.canvaslabels.setText(r, c, QString()) def updateLabels(self,d): #set label[0] as main label self.label.setText(d[0]) #recurse through label[1] and set them for r in range(len(d[1])): for c in range(len(d[1][r])): self.canvaslabels.setText(r, c, QString(d[1][r][c])) def __tr(self,s,c = None): return qApp.translate("Canvasinfo",s,c)