class CmdPrompt(QWidget): """ CmdPrompt for Embroidermodder. """ def __init__(self, parent=None): """Default class constructor.""" super(CmdPrompt, self).__init__(parent) qDebug("CmdPrompt Constructor") self.setObjectName("Command Prompt") self.promptInput = promptInput = CmdPromptInput(self) self.promptHistory = CmdPromptHistory() self.promptDivider = QFrame(self) promptVBoxLayout = QVBoxLayout(self) self.promptSplitter = CmdPromptSplitter(self) self.setFocusProxy(promptInput) self.promptHistory.setFocusProxy(promptInput) self.promptDivider.setLineWidth(1) self.promptDivider.setFrameStyle(QFrame.HLine) QWIDGETSIZE_MAX = 1 # TODO/FIXME. What is QWIDGETSIZE_MAX??? self.promptDivider.setMaximumSize(QWIDGETSIZE_MAX, 1) promptVBoxLayout.addWidget(self.promptSplitter) promptVBoxLayout.addWidget(self.promptHistory) promptVBoxLayout.addWidget(self.promptDivider) promptVBoxLayout.addWidget(promptInput) promptVBoxLayout.setSpacing(0) promptVBoxLayout.setContentsMargins(0, 0, 0, 0) self.setLayout(promptVBoxLayout) #TODO# self.styleHash = QHash<QString, QString>() #TODO# self.styleHash.insert("color", "#000000") # Match -------| #TODO# self.styleHash.insert("background-color", "#FFFFFF") # | #TODO# self.styleHash.insert("selection-color", "#FFFFFF") # | #TODO# self.styleHash.insert("selection-background-color", "#000000") # Match -------| #TODO# self.styleHash.insert("font-family", "Monospace") #TODO# self.styleHash.insert("font-style", "normal") #TODO# self.styleHash.insert("font-size", "12px") # self.updateStyle() self.blinkState = False self.blinkTimer = QTimer(self) self.blinkTimer.timeout.connect(self.blink) self.show() #### stopBlinking = SIGNAL(str) #TODO# I'm guessing these are custom Signals... #TODO# promptInput.stopBlinking.connect(self.stopBlinking) #TODO# connect(promptInput, SIGNAL(appendHistory(const QString&, int)), promptHistory, SLOT(appendHistory(const QString&, int))); #TODO# connect(this, SIGNAL(appendTheHistory(const QString&, int)), promptHistory, SLOT(appendHistory(const QString&, int))); # For use outside of command prompt #TODO# connect(promptInput, SIGNAL(startCommand(const QString&)), this, SIGNAL(startCommand(const QString&))); #TODO# connect(promptInput, SIGNAL(runCommand(const QString&, const QString&)), this, SIGNAL(runCommand(const QString&, const QString&))); #TODO# connect(promptInput, SIGNAL(deletePressed()), this, SIGNAL(deletePressed())); #TODO# connect(promptInput, SIGNAL(tabPressed()), this, SIGNAL(tabPressed())); #TODO# connect(promptInput, SIGNAL(escapePressed()), this, SIGNAL(escapePressed())); #TODO# connect(promptInput, SIGNAL(upPressed()), this, SIGNAL(upPressed())); #TODO# connect(promptInput, SIGNAL(downPressed()), this, SIGNAL(downPressed())); #TODO# connect(promptInput, SIGNAL(F1Pressed()), this, SIGNAL(F1Pressed())); #TODO# connect(promptInput, SIGNAL(F2Pressed()), this, SIGNAL(F2Pressed())); #TODO# connect(promptInput, SIGNAL(F3Pressed()), this, SIGNAL(F3Pressed())); #TODO# connect(promptInput, SIGNAL(F4Pressed()), this, SIGNAL(F4Pressed())); #TODO# connect(promptInput, SIGNAL(F5Pressed()), this, SIGNAL(F5Pressed())); #TODO# connect(promptInput, SIGNAL(F6Pressed()), this, SIGNAL(F6Pressed())); #TODO# connect(promptInput, SIGNAL(F7Pressed()), this, SIGNAL(F7Pressed())); #TODO# connect(promptInput, SIGNAL(F8Pressed()), this, SIGNAL(F8Pressed())); #TODO# connect(promptInput, SIGNAL(F9Pressed()), this, SIGNAL(F9Pressed())); #TODO# connect(promptInput, SIGNAL(F10Pressed()), this, SIGNAL(F10Pressed())); #TODO# connect(promptInput, SIGNAL(F11Pressed()), this, SIGNAL(F11Pressed())); #TODO# connect(promptInput, SIGNAL(F12Pressed()), this, SIGNAL(F12Pressed())); #TODO# connect(promptInput, SIGNAL(cutPressed()), this, SIGNAL(cutPressed())); #TODO# connect(promptInput, SIGNAL(copyPressed()), this, SIGNAL(copyPressed())); #TODO# connect(promptInput, SIGNAL(pastePressed()), this, SIGNAL(pastePressed())); #TODO# connect(promptInput, SIGNAL(selectAllPressed()), this, SIGNAL(selectAllPressed())); #TODO# connect(promptInput, SIGNAL(undoPressed()), this, SIGNAL(undoPressed())); #TODO# connect(promptInput, SIGNAL(redoPressed()), this, SIGNAL(redoPressed())); #TODO# #TODO# connect(promptInput, SIGNAL(shiftPressed()), this, SIGNAL(shiftPressed())); #TODO# connect(promptInput, SIGNAL(shiftReleased()), this, SIGNAL(shiftReleased())); #TODO# #TODO# connect(promptHistory, SIGNAL(historyAppended(const QString&)), this, SIGNAL(historyAppended(const QString&))); def floatingChanged(self, isFloating): #TODO """ TOWRITE :param `isFloating`: TOWRITE :type `isFloating`: bool """ qDebug("CmdPrompt floatingChanged(%d)", isFloating) if isFloating: self.promptSplitter.hide() else: self.promptSplitter.show() def saveHistory(self, fileName, html): #TODO """ TOWRITE :param `fileName`: TOWRITE :type `fileName`: QString :param `html`: TOWRITE :type `html`: bool """ qDebug("CmdPrompt saveHistory"); file = QFile(fileName) if (not file.open(QIODevice.WriteOnly | QIODevice.Text)): return # TODO: save during input in case of crash output = QTextStream(file) if html: output << promptHistory.toHtml() else: output << promptHistory.toPlainText() def alert(self, txt): """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ alertTxt = "<font color=\"red\">" + txt + "</font>" # TODO: Make the alert color customizable self.setPrefix(alertTxt) #TODO# appendHistory(QString()) def startBlinking(self): """ TOWRITE """ self.blinkTimer.start(750) self.promptInput.isBlinking = True def stopBlinking(self): """ TOWRITE """ self.blinkTimer.stop() self.promptInput.isBlinking = False def blink(self): """ TOWRITE """ self.blinkState = not self.blinkState if self.blinkState: qDebug("CmdPrompt blink1") else: qDebug("CmdPrompt blink0") def setPromptTextColor(self, color): """ TOWRITE :param `color`: TOWRITE :type `color`: QColor """ self.styleHash.insert("color", color.name()) self.styleHash.insert("selection-background-color", color.name()) self.updateStyle() def setPromptBackgroundColor(self, color): """ TOWRITE :param `color`: TOWRITE :type `color`: QColor """ self.styleHash.insert("background-color", color.name()) self.styleHash.insert("selection-color", color.name()) self.updateStyle() def setPromptFontFamily(self, family): """ TOWRITE :param `family`: TOWRITE :type `family`: QString """ self.styleHash.insert("font-family", family) self.updateStyle() def setPromptFontStyle(self, style): """ TOWRITE :param `style`: TOWRITE :type `style`: QString """ self.styleHash.insert("font-style", style) self.updateStyle() def setPromptFontSize(self, size): """ TOWRITE :param `size`: TOWRITE :type `size`: int """ self.styleHash.insert("font-size", QString().setNum(size).append("px")) self.updateStyle() def updateStyle(self): # TODO """ TOWRITE """ style = "QTextBrowser,QLineEdit{" QHashIterator<QString, QString> i(*styleHash); while (i.hasNext()): i.next() style.append(i.key() + ":" + i.value() + ";") style.append("}") self.setStyleSheet(style) def appendHistory(self, txt): # TODO """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ if (txt.isNull()): #TODO# #TODO# emit appendTheHistory(self.promptInput.curText, self.promptInput.prefix.length()) return qDebug("CmdPrompt - appendHistory()") #TODO# emit appendTheHistory(txt, self.promptInput.prefix.length()) def setPrefix(self, txt): """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ self.promptInput.prefix = txt self.promptInput.curText = txt self.promptInput.setText(txt)
class MainWindow(QDialog): """monkey_linux UI""" def __init__(self,parent=None): super(MainWindow, self).__init__() self.init_conf() self.setParent(parent) common.Log.info("set up ui") self.setup_ui() self.findDeviceAction.triggered.connect(self.get_device_status) self.deleteDeviceAction.triggered.connect(self.del_device) # self.storeButton.clicked.connect(self.set_conf) self.startButton.clicked.connect(self.start) self.stopButton.clicked.connect(self.stop) self.checkLogButton.clicked.connect(self.check) self.monkeyButton.clicked.connect(self.checkMonkeyLog) self.exportButton.clicked.connect(self.exportConf) self.importButton.clicked.connect(self.importConf) self.setAbout.triggered.connect(self.about) self.startTime = datetime.datetime.now() self.secsTime = float(1) * 60 * 60 def setup_ui(self): # main window width hand height # self.setMinimumWidth(600) self.setMaximumWidth(800) self.setMinimumHeight(600) # main window title self.setWindowTitle(static.title) # file menu bar self.menuBar = QMenuBar() self.menuBar.setMaximumHeight(23) # self.menuFile = self.menuBar.addMenu(static.menuFile) # self.importAction = QAction(QIcon(static.importPNG), static.importFile, self) # self.exportAction = QAction(QIcon(static.exportPNG), static.exportFile, self) # self.menuFile.addAction(self.importAction) # self.menuFile.addAction(self.exportAction) self.setEnvActioin = QAction(QIcon(static.setPNG), static.pcSet, self) self.menuSet = self.menuBar.addMenu(static.menuSet) self.menuSet.addAction(self.setEnvActioin) self.setAbout = QAction(QIcon(static.setPNG), static.menuAbout, self) self.setAbout.setStatusTip('About') # 状态栏提示 self.menuHelp = self.menuBar.addMenu(static.menuHelp) self.menuHelp.addAction(self.setAbout) # set all layout self.hbox = QHBoxLayout(self) # device ======== self.topLeft = QFrame(self) self.topLeft.setMaximumSize(218, 300) self.topLeft.setMinimumSize(218, 200) self.topLeft.setFrameShape(QFrame.StyledPanel) self.topLeftLayout = QVBoxLayout(self.topLeft) self.toolBar = QToolBar() # self.androidDeviceAction = QRadioButton('Android', self) # self.androidDeviceAction.setFocusPolicy(Qt.NoFocus) # self.ipDeviceAction = QRadioButton('IP', self) # self.ipDeviceAction.setFocusPolicy(Qt.NoFocus) # self.ipDeviceAction.move(10, 10) # self.ipDeviceAction.toggle() self.findDeviceAction = QAction(QIcon(static.findDevice), static.findDeviceButton, self) self.deleteDeviceAction = QAction(QIcon(static.deleteDevice), static.deleteDeviceButton, self) # self.toolBar.addWidget(self.androidDeviceAction) # self.toolBar.addWidget(self.ipDeviceAction) self.toolBar.addAction(self.findDeviceAction) self.toolBar.addAction(self.deleteDeviceAction) self.deviceLab = QLabel(static.deviceName, self) self.device = QTableWidget(1, 2) self.device.setHorizontalHeaderLabels(['name', 'status']) self.device.setColumnWidth(0, 100) self.device.setColumnWidth(1, 80) self.topLeftLayout.addWidget(self.deviceLab) self.topLeftLayout.addWidget(self.toolBar) self.topLeftLayout.addWidget(self.device) # set button or other for running monkey or not and status of device and log ======== self.topRight = QFrame(self) self.topRight.setFrameShape(QFrame.StyledPanel) self.topRight.setMaximumHeight(40) self.startButton = QPushButton(QIcon(static.startPNG), "") self.stopButton = QPushButton(QIcon(static.stopPNG), "") self.status = QLabel(static.status) self.statusEdit = QLineEdit(self) self.statusEdit.setReadOnly(True) self.statusEdit.setMaximumWidth(80) self.statusEdit.setMinimumWidth(80) self.statusEdit.setText("") # check log self.checkLogButton = QPushButton(static.checkLog) self.checkLogButton.setMaximumHeight(20) self.checkLogButton.setMinimumHeight(20) self.checkLogButton.setMaximumWidth(60) self.selectLog = QLabel(static.selectlog) self.logfile = QComboBox() self.dirlist = os.listdir(os.path.join(DIR, "Result")) for d in self.dirlist: if d != "AutoMonkey.log": self.logfile.insertItem(0, d) self.logfile.setMaximumWidth(150) self.logfile.setMaximumHeight(20) self.logfile.setMinimumHeight(20) self.topLayout = QHBoxLayout(self.topRight) self.topLayout.addWidget(self.startButton) self.topLayout.addWidget(self.stopButton) self.topLayout.addWidget(self.status) self.topLayout.addWidget(self.statusEdit) self.topLayout.addWidget(self.selectLog) self.topLayout.addWidget(self.logfile) self.topLayout.addWidget(self.checkLogButton) # set parameter for monkey ======= self.midRight = QFrame(self) self.midRight.setMaximumSize(555, 200) self.midRight.setMinimumSize(555, 200) self.midRight.setFrameShape(QFrame.StyledPanel) self.midRightLayout = QVBoxLayout(self.midRight) self.subLayout0 = QVBoxLayout() self.subLayout1 = QVBoxLayout() self.subLayout2 = QHBoxLayout() self.subLayout3 = QVBoxLayout() self.subLayout4 = QVBoxLayout() self.subLayout5 = QHBoxLayout() self.subLayout6 = QHBoxLayout() self.toolBar = QToolBar() # self.storeAction = QAction(QIcon(static.storePNG), static.storeButton, self) self.startAction = QAction(QIcon(static.startPNG), static.startButton, self) self.stopAction = QAction(QIcon(static.stopPNG), static.stopButton, self) # self.toolBar.addAction(self.storeAction) self.toolBar.addAction(self.startAction) self.toolBar.addAction(self.stopAction) self.timeLongLbl = QLabel(static.timeString, self) self.timeLong = QLineEdit(self) self.timeLong.setMaximumWidth(100) self.timeLong.setMinimumWidth(100) self.timeLong.setPlaceholderText(static.timeLong) self.timeLongUnit = QLabel("H") self.etSetLbl = QLabel(static.eventTypeSet) self.etSet = QTableWidget(2, 2) self.etSet.setMaximumHeight(150) self.etSet.setHorizontalHeaderLabels(['option', 'value']) self.etSet.horizontalHeader().setStretchLastSection(True) self.etSet.setItem(0, 0, QTableWidgetItem("--throttle")) self.etSet.setItem(0, 1, QTableWidgetItem(str(static.eventType["--throttle"]))) # set event type percent self.etPercentLbl = QLabel(static.eventTpyePercent, self) self.etPercent = QTableWidget(2, 2) self.etPercent.setMaximumHeight(150) self.etPercent.setHorizontalHeaderLabels(['option', 'value']) self.etPercent.horizontalHeader().setStretchLastSection(True) self.etPercent.setItem(0, 0, QTableWidgetItem("--pct-touch")) self.etPercent.setItem(0, 1, QTableWidgetItem(str(static.eventPercent["--pct-touch"]))) self.etPercent.setItem(1, 0, QTableWidgetItem("--pct-motion")) self.etPercent.setItem(1, 1, QTableWidgetItem(str(static.eventPercent["--pct-motion"]))) # self.storeButton = QPushButton(QIcon(static.storePNG), static.storeButton) # self.storeButton.setToolTip(static.storeButton) self.exportButton = QPushButton(QIcon(static.exportPNG), static.exportFile) self.exportButton.setToolTip(static.exportFile) self.importButton = QPushButton(QIcon(static.importPNG), static.importFile) self.importButton.setToolTip(static.importFile) self.subLayout2.addWidget(self.timeLongLbl) self.subLayout2.addWidget(self.timeLong) self.subLayout2.addWidget(self.timeLongUnit) self.subLayout2.addWidget(QLabel(" " * 300)) # self.subLayout2.addWidget(self.storeButton) self.subLayout2.addWidget(self.exportButton) self.subLayout2.addWidget(self.importButton) self.subLayout0.addLayout(self.subLayout2) self.subLayout3.addWidget(self.etSetLbl) self.subLayout3.addWidget(self.etSet) self.subLayout4.addWidget(self.etPercentLbl) self.subLayout4.addWidget(self.etPercent) self.subLayout5.addLayout(self.subLayout0) self.subLayout6.addLayout(self.subLayout3) self.subLayout6.addLayout(self.subLayout4) self.midRightLayout.addLayout(self.subLayout5) self.midRightLayout.addLayout(self.subLayout6) # log ======== self.bottom = QFrame(self) self.bottom.setFrameShape(QFrame.StyledPanel) # log information self.logInfo = QLabel(static.logInfo) # information filter self.logFilter = QLabel(static.logFilter) self.monkeyButton = QPushButton(static.openMonkeyLog) self.combo = QComboBox() for i in range(len(static.logLevel)): self.combo.addItem(static.logLevel[i]) self.combo.setMaximumWidth(55) self.combo.setMaximumHeight(20) self.combo.setMinimumHeight(20) # information details self.bottomLayout = QVBoxLayout(self.bottom) self.subLayout = QHBoxLayout() self.subLayout.addWidget(self.logInfo) for i in range(10): self.subLayout.addWidget(QLabel("")) self.subLayout.addWidget(self.monkeyButton) self.subLayout.addWidget(self.logFilter) self.subLayout.addWidget(self.combo) self.bottomLayout.addLayout(self.subLayout) self.tabwidget = TabWidget() self.tabwidget.setMinimumHeight(100) self.bottomLayout.addWidget(self.tabwidget) # splitter mainWindow ++++++++++++++++++++++++++++++++++++ self.splitter2 = QSplitter(Qt.Vertical) self.splitter2.addWidget(self.topRight) self.splitter2.addWidget(self.midRight) self.splitter0 = QSplitter(Qt.Horizontal) self.splitter0.addWidget(self.topLeft) self.splitter0.addWidget(self.splitter2) self.splitter1 = QSplitter(Qt.Vertical) self.splitter1.addWidget(self.menuBar) self.splitter1.addWidget(self.splitter0) self.splitter1.addWidget(self.bottom) self.hbox.addWidget(self.splitter1) self.setLayout(self.hbox) self.show() def about(self): common.showDialog(static.menuAbout, static.dialogAbout) def init_conf(self): common.Log.info("init monkey conf") with open(monkeyConfFile, "w") as f: f.write("deviceList = []" + "\n") f.write("times = " + static.times + "\n") f.write("--throttle = " + static.eventType["--throttle"] + "\n") f.write("--pct-touch = " + static.eventPercent["--pct-touch"] + "\n") f.write("--pct-motion = " + static.eventPercent["--pct-motion"] + "\n") def setup_env(self): pass def _set_eventType(self, confFile): try: option = self.etSet.item(0, 0).text() value = self.etSet.item(0, 1).text() if value > "0": with open(confFile, 'a+') as f: f.write(option + " = " + value + "\n") except AttributeError, e: pass
class CmdPrompt(QWidget): """ CmdPrompt for Embroidermodder. """ def __init__(self, parent=None): """Default class constructor.""" super(CmdPrompt, self).__init__(parent) qDebug("CmdPrompt Constructor") self.setObjectName("Command Prompt") self.promptInput = promptInput = CmdPromptInput(self) self.promptHistory = CmdPromptHistory() self.promptDivider = QFrame(self) promptVBoxLayout = QVBoxLayout(self) self.promptSplitter = CmdPromptSplitter(self) self.setFocusProxy(promptInput) self.promptHistory.setFocusProxy(promptInput) self.promptDivider.setLineWidth(1) self.promptDivider.setFrameStyle(QFrame.HLine) QWIDGETSIZE_MAX = 1 # TODO/FIXME. What is QWIDGETSIZE_MAX??? self.promptDivider.setMaximumSize(QWIDGETSIZE_MAX, 1) promptVBoxLayout.addWidget(self.promptSplitter) promptVBoxLayout.addWidget(self.promptHistory) promptVBoxLayout.addWidget(self.promptDivider) promptVBoxLayout.addWidget(promptInput) promptVBoxLayout.setSpacing(0) promptVBoxLayout.setContentsMargins(0, 0, 0, 0) self.setLayout(promptVBoxLayout) #TODO# self.styleHash = QHash<QString, QString>() #TODO# self.styleHash.insert("color", "#000000") # Match -------| #TODO# self.styleHash.insert("background-color", "#FFFFFF") # | #TODO# self.styleHash.insert("selection-color", "#FFFFFF") # | #TODO# self.styleHash.insert("selection-background-color", "#000000") # Match -------| #TODO# self.styleHash.insert("font-family", "Monospace") #TODO# self.styleHash.insert("font-style", "normal") #TODO# self.styleHash.insert("font-size", "12px") # self.updateStyle() self.blinkState = False self.blinkTimer = QTimer(self) self.blinkTimer.timeout.connect(self.blink) self.show() #### stopBlinking = SIGNAL(str) #TODO# I'm guessing these are custom Signals... #TODO# promptInput.stopBlinking.connect(self.stopBlinking) #TODO# connect(promptInput, SIGNAL(appendHistory(const QString&, int)), promptHistory, SLOT(appendHistory(const QString&, int))); #TODO# connect(this, SIGNAL(appendTheHistory(const QString&, int)), promptHistory, SLOT(appendHistory(const QString&, int))); # For use outside of command prompt #TODO# connect(promptInput, SIGNAL(startCommand(const QString&)), this, SIGNAL(startCommand(const QString&))); #TODO# connect(promptInput, SIGNAL(runCommand(const QString&, const QString&)), this, SIGNAL(runCommand(const QString&, const QString&))); #TODO# connect(promptInput, SIGNAL(deletePressed()), this, SIGNAL(deletePressed())); #TODO# connect(promptInput, SIGNAL(tabPressed()), this, SIGNAL(tabPressed())); #TODO# connect(promptInput, SIGNAL(escapePressed()), this, SIGNAL(escapePressed())); #TODO# connect(promptInput, SIGNAL(upPressed()), this, SIGNAL(upPressed())); #TODO# connect(promptInput, SIGNAL(downPressed()), this, SIGNAL(downPressed())); #TODO# connect(promptInput, SIGNAL(F1Pressed()), this, SIGNAL(F1Pressed())); #TODO# connect(promptInput, SIGNAL(F2Pressed()), this, SIGNAL(F2Pressed())); #TODO# connect(promptInput, SIGNAL(F3Pressed()), this, SIGNAL(F3Pressed())); #TODO# connect(promptInput, SIGNAL(F4Pressed()), this, SIGNAL(F4Pressed())); #TODO# connect(promptInput, SIGNAL(F5Pressed()), this, SIGNAL(F5Pressed())); #TODO# connect(promptInput, SIGNAL(F6Pressed()), this, SIGNAL(F6Pressed())); #TODO# connect(promptInput, SIGNAL(F7Pressed()), this, SIGNAL(F7Pressed())); #TODO# connect(promptInput, SIGNAL(F8Pressed()), this, SIGNAL(F8Pressed())); #TODO# connect(promptInput, SIGNAL(F9Pressed()), this, SIGNAL(F9Pressed())); #TODO# connect(promptInput, SIGNAL(F10Pressed()), this, SIGNAL(F10Pressed())); #TODO# connect(promptInput, SIGNAL(F11Pressed()), this, SIGNAL(F11Pressed())); #TODO# connect(promptInput, SIGNAL(F12Pressed()), this, SIGNAL(F12Pressed())); #TODO# connect(promptInput, SIGNAL(cutPressed()), this, SIGNAL(cutPressed())); #TODO# connect(promptInput, SIGNAL(copyPressed()), this, SIGNAL(copyPressed())); #TODO# connect(promptInput, SIGNAL(pastePressed()), this, SIGNAL(pastePressed())); #TODO# connect(promptInput, SIGNAL(selectAllPressed()), this, SIGNAL(selectAllPressed())); #TODO# connect(promptInput, SIGNAL(undoPressed()), this, SIGNAL(undoPressed())); #TODO# connect(promptInput, SIGNAL(redoPressed()), this, SIGNAL(redoPressed())); #TODO# #TODO# connect(promptInput, SIGNAL(shiftPressed()), this, SIGNAL(shiftPressed())); #TODO# connect(promptInput, SIGNAL(shiftReleased()), this, SIGNAL(shiftReleased())); #TODO# #TODO# connect(promptHistory, SIGNAL(historyAppended(const QString&)), this, SIGNAL(historyAppended(const QString&))); def floatingChanged(self, isFloating): #TODO """ TOWRITE :param `isFloating`: TOWRITE :type `isFloating`: bool """ qDebug("CmdPrompt floatingChanged(%d)", isFloating) if isFloating: self.promptSplitter.hide() else: self.promptSplitter.show() def saveHistory(self, fileName, html): #TODO """ TOWRITE :param `fileName`: TOWRITE :type `fileName`: QString :param `html`: TOWRITE :type `html`: bool """ qDebug("CmdPrompt saveHistory") file = QFile(fileName) if (not file.open(QIODevice.WriteOnly | QIODevice.Text)): return # TODO: save during input in case of crash output = QTextStream(file) if html: output << promptHistory.toHtml() else: output << promptHistory.toPlainText() def alert(self, txt): """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ alertTxt = "<font color=\"red\">" + txt + "</font>" # TODO: Make the alert color customizable self.setPrefix(alertTxt) #TODO# appendHistory(QString()) def startBlinking(self): """ TOWRITE """ self.blinkTimer.start(750) self.promptInput.isBlinking = True def stopBlinking(self): """ TOWRITE """ self.blinkTimer.stop() self.promptInput.isBlinking = False def blink(self): """ TOWRITE """ self.blinkState = not self.blinkState if self.blinkState: qDebug("CmdPrompt blink1") else: qDebug("CmdPrompt blink0") def setPromptTextColor(self, color): """ TOWRITE :param `color`: TOWRITE :type `color`: QColor """ self.styleHash.insert("color", color.name()) self.styleHash.insert("selection-background-color", color.name()) self.updateStyle() def setPromptBackgroundColor(self, color): """ TOWRITE :param `color`: TOWRITE :type `color`: QColor """ self.styleHash.insert("background-color", color.name()) self.styleHash.insert("selection-color", color.name()) self.updateStyle() def setPromptFontFamily(self, family): """ TOWRITE :param `family`: TOWRITE :type `family`: QString """ self.styleHash.insert("font-family", family) self.updateStyle() def setPromptFontStyle(self, style): """ TOWRITE :param `style`: TOWRITE :type `style`: QString """ self.styleHash.insert("font-style", style) self.updateStyle() def setPromptFontSize(self, size): """ TOWRITE :param `size`: TOWRITE :type `size`: int """ self.styleHash.insert("font-size", QString().setNum(size).append("px")) self.updateStyle() def updateStyle(self): # TODO """ TOWRITE """ style = "QTextBrowser,QLineEdit{" QHashIterator < QString, QString > i(*styleHash) while (i.hasNext()): i.next() style.append(i.key() + ":" + i.value() + ";") style.append("}") self.setStyleSheet(style) def appendHistory(self, txt): # TODO """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ if (txt.isNull()): #TODO# #TODO# emit appendTheHistory(self.promptInput.curText, self.promptInput.prefix.length()) return qDebug("CmdPrompt - appendHistory()") #TODO# emit appendTheHistory(txt, self.promptInput.prefix.length()) def setPrefix(self, txt): """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ self.promptInput.prefix = txt self.promptInput.curText = txt self.promptInput.setText(txt)
class CmdPrompt(QWidget): """ Subclass of `QWidget`_ CmdPrompt for Embroidermodder. .. sphinx_generate_methods_summary:: CmdPrompt """ def QWIDGETSIZE_MAX(self): return (1 << 24) - 1 def __init__(self, parent=None): """ Default class constructor. :param `parent`: Pointer to a parent widget instance. :type `parent`: `QWidget`_ """ super(CmdPrompt, self).__init__(parent) qDebug("CmdPrompt Constructor") self.setObjectName("Command Prompt") self.promptInput = promptInput = CmdPromptInput(self) self.promptHistory = promptHistory = CmdPromptHistory() self.promptDivider = QFrame(self) promptVBoxLayout = QVBoxLayout(self) self.promptSplitter = CmdPromptSplitter(self) self.setFocusProxy(promptInput) self.promptHistory.setFocusProxy(promptInput) self.promptDivider.setLineWidth(1) self.promptDivider.setFrameStyle(QFrame.HLine) self.promptDivider.setMaximumSize(self.QWIDGETSIZE_MAX(), 1) promptVBoxLayout.addWidget(self.promptSplitter) promptVBoxLayout.addWidget(self.promptHistory) promptVBoxLayout.addWidget(self.promptDivider) promptVBoxLayout.addWidget(promptInput) promptVBoxLayout.setSpacing(0) promptVBoxLayout.setContentsMargins(0, 0, 0, 0) self.setLayout(promptVBoxLayout) self.styleHash = {} # QHash<QString, QString>() self.styleHash["color"] = "#000000" # Match -------| self.styleHash["background-color"] = "#FFFFFF" # | self.styleHash["selection-color"] = "#FFFFFF" # | self.styleHash["selection-background-color"] = "#000000" # Match -------| self.styleHash["font-family"] = "Monospace" self.styleHash["font-style"] = "normal" self.styleHash["font-size"] = "12px" self.updateStyle() self.blinkState = False self.blinkTimer = QTimer(self) self.blinkTimer.timeout.connect(self.blink) self.show() self.connect(promptInput, SIGNAL("stopBlinking()"), self, SLOT("stopBlinking()")) self.connect(promptInput, SIGNAL("appendHistory(QString, int)"), promptHistory, SLOT("appendHistory(const QString&, int)")) self.connect(self, SIGNAL("appendTheHistory(QString, int)"), promptHistory, SLOT("appendHistory(const QString&, int)")) # For use outside of command prompt self.connect(promptInput, SIGNAL("startCommand(QString)"), self, SIGNAL("startCommand(QString)")) self.connect(promptInput, SIGNAL("runCommand(QString, QString)"), self, SIGNAL("runCommand(QString, QString)")) self.connect(promptInput, SIGNAL("deletePressed()"), self, SIGNAL("deletePressed()")) self.connect(promptInput, SIGNAL("tabPressed()"), self, SIGNAL("tabPressed()")) self.connect(promptInput, SIGNAL("escapePressed()"), self, SIGNAL("escapePressed()")) self.connect(promptInput, SIGNAL("upPressed()"), self, SIGNAL("upPressed()")) self.connect(promptInput, SIGNAL("downPressed()"), self, SIGNAL("downPressed()")) self.connect(promptInput, SIGNAL("F1Pressed()"), self, SIGNAL("F1Pressed()")) self.connect(promptInput, SIGNAL("F2Pressed()"), self, SIGNAL("F2Pressed()")) self.connect(promptInput, SIGNAL("F3Pressed()"), self, SIGNAL("F3Pressed()")) self.connect(promptInput, SIGNAL("F4Pressed()"), self, SIGNAL("F4Pressed()")) self.connect(promptInput, SIGNAL("F5Pressed()"), self, SIGNAL("F5Pressed()")) self.connect(promptInput, SIGNAL("F6Pressed()"), self, SIGNAL("F6Pressed()")) self.connect(promptInput, SIGNAL("F7Pressed()"), self, SIGNAL("F7Pressed()")) self.connect(promptInput, SIGNAL("F8Pressed()"), self, SIGNAL("F8Pressed()")) self.connect(promptInput, SIGNAL("F9Pressed()"), self, SIGNAL("F9Pressed()")) self.connect(promptInput, SIGNAL("F10Pressed()"), self, SIGNAL("F10Pressed()")) self.connect(promptInput, SIGNAL("F11Pressed()"), self, SIGNAL("F11Pressed()")) self.connect(promptInput, SIGNAL("F12Pressed()"), self, SIGNAL("F12Pressed()")) self.connect(promptInput, SIGNAL("cutPressed()"), self, SIGNAL("cutPressed()")) self.connect(promptInput, SIGNAL("copyPressed()"), self, SIGNAL("copyPressed()")) self.connect(promptInput, SIGNAL("pastePressed()"), self, SIGNAL("pastePressed()")) self.connect(promptInput, SIGNAL("selectAllPressed()"), self, SIGNAL("selectAllPressed()")) self.connect(promptInput, SIGNAL("undoPressed()"), self, SIGNAL("undoPressed()")) self.connect(promptInput, SIGNAL("redoPressed()"), self, SIGNAL("redoPressed()")) self.connect(promptInput, SIGNAL("shiftPressed()"), self, SIGNAL("shiftPressed()")) self.connect(promptInput, SIGNAL("shiftReleased()"), self, SIGNAL("shiftReleased()")) self.connect(promptHistory, SIGNAL("historyAppended(QString)"), self, SIGNAL("historyAppended(QString)")) def updateStyle(self): """ TOWRITE """ style = ["QTextBrowser,QLineEdit{"] for key, value in self.styleHash.items(): style.append(key + ":" + value + ";") style.append("}") style = "".join(style) self.setStyleSheet(style) # Slots ------------------------------------------------------------------ @Slot(bool) def floatingChanged(self, isFloating): """ TOWRITE :param `isFloating`: TOWRITE :type `isFloating`: bool """ qDebug("CmdPrompt floatingChanged(%d)" % isFloating) if isFloating: self.promptSplitter.hide() else: self.promptSplitter.show() @Slot(str, bool) def saveHistory(self, fileName, html): """ TOWRITE :param `fileName`: TOWRITE :type `fileName`: QString :param `html`: TOWRITE :type `html`: bool """ qDebug("CmdPrompt saveHistory") file = QFile(fileName) if (not file.open(QIODevice.WriteOnly | QIODevice.Text)): return # TODO: save during input in case of crash output = QTextStream(file) if html: output << self.promptHistory.toHtml() else: output << self.promptHistory.toPlainText() @Slot(str) def alert(self, txt): """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ alertTxt = "<font color=\"red\">" + txt + "</font>" # TODO: Make the alert color customizable self.setPrefix(alertTxt) self.appendHistory('') @Slot() def startBlinking(self): """ TOWRITE """ self.blinkTimer.start(750) self.promptInput.isBlinking = True @Slot() def stopBlinking(self): """ TOWRITE """ self.blinkTimer.stop() self.promptInput.isBlinking = False @Slot() def blink(self): """ TOWRITE """ self.blinkState = not self.blinkState if self.blinkState: qDebug("CmdPrompt blink1") else: qDebug("CmdPrompt blink0") @Slot(QColor) def setPromptTextColor(self, color): """ TOWRITE :param `color`: TOWRITE :type `color`: `QColor`_ """ self.styleHash["color"] = color.name() self.styleHash["selection-background-color"] = color.name() self.updateStyle() @Slot(QColor) def setPromptBackgroundColor(self, color): """ TOWRITE :param `color`: TOWRITE :type `color`: `QColor`_ """ self.styleHash["background-color"] = color.name() self.styleHash["selection-color"] = color.name() self.updateStyle() @Slot(str) def setPromptFontFamily(self, family): """ TOWRITE :param `family`: TOWRITE :type `family`: QString """ self.styleHash["font-family"] = family self.updateStyle() @Slot(str) def setPromptFontStyle(self, style): """ TOWRITE :param `style`: TOWRITE :type `style`: QString """ self.styleHash["font-style"] = style self.updateStyle() @Slot(int) def setPromptFontSize(self, size): """ TOWRITE :param `size`: TOWRITE :type `size`: int """ self.styleHash["font-size"] = "%spx" % size # QString().setNum(size).append("px")) self.updateStyle() @Slot(str) def appendHistory(self, txt): """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ if not txt: self.appendTheHistory.emit(self.promptInput.curText, len(self.promptInput.prefix)) return qDebug("CmdPrompt - appendHistory()") self.appendTheHistory(txt, len(self.promptInput.prefix)) @Slot(str) def setPrefix(self, txt): """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ self.promptInput.prefix = txt self.promptInput.curText = txt self.promptInput.setText(txt) # cmdprompt.hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh @Slot() def getHistory(self): """ TOWRITE :rtype: QString """ return self.promptHistory.toHtml() @Slot() def getPrefix(self): """ TOWRITE :rtype: QString """ return self.promptInput.prefix @Slot() def getCurrentText(self): """ TOWRITE :rtype: QString """ return self.promptInput.curText @Slot(str) def setCurrentText(self, txt): """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ self.promptInput.curText = self.promptInput.prefix + txt self.promptInput.setText(self.promptInput.curText) @Slot(str) def setHistory(self, txt): """ TOWRITE :param `txt`: TOWRITE :type `txt`: QString """ self.promptHistory.setHtml(txt) self.promptHistory.moveCursor(QTextCursor.End, QTextCursor.MoveAnchor) @Slot(int) def startResizingTheHistory(self, y): """ TOWRITE :param `y`: TOWRITE :type `y`: int """ self.promptHistory.startResizeHistory(y) @Slot(int) def stopResizingTheHistory(self, y): """ TOWRITE :param `y`: TOWRITE :type `y`: int """ self.promptHistory.stopResizeHistory(y) @Slot(int) def resizeTheHistory(self, y): """ TOWRITE :param `y`: TOWRITE :type `y`: int """ self.promptHistory.resizeHistory(y) @Slot(str, str) def addCommand(self, alias, cmd): """ TOWRITE :param `alias`: TOWRITE :type `alias`: QString :param `alias`: TOWRITE :type `alias`: QString """ self.promptInput.addCommand(alias, cmd) @Slot() def endCommand(self): """ TOWRITE """ self.promptInput.endCommand() @Slot() def isCommandActive(self): """ TOWRITE :rtype: bool """ return self.promptInput.cmdActive @Slot() def activeCommand(self): """ TOWRITE :rtype: QString """ return self.promptInput.curCmd @Slot() def lastCommand(self): """ TOWRITE :rtype: QString """ return self.promptInput.lastCmd @Slot() def processInput(self): """ TOWRITE """ self.promptInput.processInput() @Slot() def enableRapidFire(self): """ TOWRITE """ self.promptInput.rapidFireEnabled = True @Slot() def disableRapidFire(self): """ TOWRITE """ self.promptInput.rapidFireEnabled = False @Slot() def isRapidFireEnabled(self): """ TOWRITE :rtype: bool """ return self.promptInput.rapidFireEnabled # Signals ---------------------------------------------------------------- appendTheHistory = Signal(str, int) # For connecting outside of command prompt startCommand = Signal(str) runCommand = Signal(str, str) deletePressed = Signal() tabPressed = Signal() escapePressed = Signal() upPressed = Signal() downPressed = Signal() F1Pressed = Signal() F2Pressed = Signal() F3Pressed = Signal() F4Pressed = Signal() F5Pressed = Signal() F6Pressed = Signal() F7Pressed = Signal() F8Pressed = Signal() F9Pressed = Signal() F10Pressed = Signal() F11Pressed = Signal() F12Pressed = Signal() cutPressed = Signal() copyPressed = Signal() pastePressed = Signal() selectAllPressed = Signal() undoPressed = Signal() redoPressed = Signal() shiftPressed = Signal() shiftReleased = Signal() showSettings = Signal() historyAppended = Signal(str)