def showhelp(self): dlg = QtWidgets.QDialog(self) dlg.setWindowTitle(i18n('Help')) l = QtWidgets.QVBoxLayout(dlg) l.setContentsMargins(6, 6, 6, 6) tabWidget = QtWidgets.QTabWidget(dlg) buttonBar = QtWidgets.QDialogButtonBox(dlg) buttonBar.addButton(QtWidgets.QDialogButtonBox.Close) buttonBar.accepted.connect(dlg.close) buttonBar.rejected.connect(dlg.close) l.addWidget(tabWidget) l.addWidget(buttonBar) tv = QtWidgets.QTextBrowser(tabWidget) image = QtWidgets.QLabel(tabWidget) image.setPixmap(about_pixmap()) tabWidget.addTab(image, i18n('About')) tabWidget.addTab(tv, i18n('Help')) with open(self._cssfile()) as f: tv.document().setDefaultStyleSheet(f.read()) try: with open(self._mdhelp()) as f: tv.document().setHtml(markdown.markdown(f.read())) except: try: with open(self._htmlhelp()) as f: tv.document().setHtml(f.read()) except: tv.setHtml("No help") dlg.exec_()
def __init__(self, parent): super(SnipplerWidget, self).__init__(i18n('Snipplets'), parent) self.setWindowTitle(i18n("Snipplets")) self.snippletView = QtWidgets.QListWidget(self) self.setWidget(self.snippletView) self.loadSnipplets() self.snippletView.itemDoubleClicked.connect(self._insertToParent)
def dirtySaveCancel(self): d = QtWidgets.QMessageBox() d.setWindowTitle(i18n("Question")) d.setText(i18n("Document was modify")) d.setInformativeText(i18n("Save changes?")) d.setIcon(QtWidgets.QMessageBox.Question) d.setStandardButtons(QtWidgets.QMessageBox.Save | QtWidgets.QMessageBox.Cancel) return d.exec_()
def fileOpen(self): name, dummy = QtWidgets.QFileDialog.getOpenFileName( self, i18n("Open File"), self.cwd, i18n("Python files (*.py);;All files (*)")) if name: code_edit = self.createEditor() code_edit.file.open(name) i = self.tabber.add_code_edit(code_edit) self.tabber.setCurrentIndex(i) self.cwd = os.path.dirname(name)
def openTerm(self): if self.termAction.isChecked(): self.stack.setCurrentIndex(1) self.termAction.setIcon(icon('terminal-out')) self.termAction.setText(i18n('To Editor')) self.term.setFocus() # self.term.remoteExec(b'\x04') else: self.termAction.setIcon(icon('terminal')) self.termAction.setText(i18n('Terminal')) self.stack.setCurrentIndex(0)
def rightMenu(self, position): menu = QtWidgets.QMenu() pasteAction = menu.addAction(i18n("Paste")) pasteAction.triggered.connect(self.paste) if not QApplication.clipboard().mimeData().hasText(): pasteAction.setEnabled(False) menu.exec_(self.mapToGlobal(position))
def __init__(self, parent): super(DeviceFilesWidget, self).__init__(i18n('Device files'), parent) self.setWindowTitle(i18n("Device files")) widget = QtWidgets.QWidget(self) vlayout = QtWidgets.QVBoxLayout() self.toolbar = QtWidgets.QToolBar(self) self.toolbar.addAction(i18n("Refresh"), self.loadRemoteFiles) self.toolbar.addAction(icon("download"), i18n("Download to Device"), self.downloadFile) self.filesView = QtWidgets.QTreeWidget(self) self.filesView.header().close() self.deviceItem = QtWidgets.QTreeWidgetItem(0) self.deviceItem.setText(0,i18n("Device")) self.filesView.addTopLevelItem(self.deviceItem) vlayout.addWidget(self.toolbar) vlayout.addWidget(self.filesView) widget.setLayout(vlayout) self.setWidget(widget)
def fileSave(self): ed = self.tabber.active_editor if not ed: return False is_new = ed.file.path.startswith(i18n('NewFile.py (%d)') .replace(' (%d)', '')) if not ed.file.path or is_new: path, dummy = QtWidgets.QFileDialog. \ getSaveFileName(self, i18n("Save File"), self.cwd, i18n("Python files (*.py);;All files (*)")) else: path = ed.file.path if not path: return False old = self.tabber.currentIndex() self.tabber.setCurrentWidget(ed) self.tabber.save_current(path) self.tabber.setCurrentIndex(old) return True
def _writeRemoteFile(self, local_name): '''upload local file to remote device (target board)''' def finished(raw): print(('_writeRemoteFile terminated: ', raw)) name = os.path.basename(local_name) name, ok = QtWidgets.QInputDialog.getText(self, i18n("Download"), i18n("Remote Name"), text=name) if not ok: return remote_name = '/flash/{}'.format(name) if os.path.exists(local_name): with open(local_name, 'rb') as f: data = f.read() else: data = self.tabber.active_editor.toPlainText() cmd = "with open(\"{}\", 'wb') as f:\r" \ " f.write({})".format(remote_name, repr(data)) print(("Writing remote to ", remote_name, repr(data))) print(("--------------\n", cmd, "\n--------------")) self._targetExec(cmd, finished)
def __init__(self): QtWidgets.QMainWindow.__init__(self) self.setWindowTitle(i18n("Edu CIAA MicroPython")) self.cwd = QtCore.QDir.homePath() self.tabber = wcore.TabWidget(self) self.term = termWidget.Terminal(self) self.outline = widgets.PyOutlineTreeWidget() self.dock_outline = QtWidgets.QDockWidget(i18n('Outline')) self.dock_outline.setWidget(self.outline) self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.dock_outline) self.snippler = SnipplerWidget(self) self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.snippler) self.deviceFiles = DeviceFilesWidget(self) self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.deviceFiles) self.stack = QtWidgets.QStackedWidget(self) self.stack.addWidget(self.tabber) self.stack.addWidget(self.term) self.setCentralWidget(self.stack) self.makeAppToolBar() self.resize(1024, 600) self.onListDir.connect(lambda l: self._showDir(l)) self.tabber.currentChanged.connect(self.actualizeOutline) self.fileNew() self.portSelector.onChange(0)
def makeAppToolBar(self): bar = QtWidgets.QToolBar('Toolbar', self) bar.setIconSize(QtCore.QSize(48, 48)) bar.addAction(icon("document-new"), i18n("New"), self.fileNew) bar.addAction(icon("document-open"), i18n("Open"), self.fileOpen) bar.addAction(icon("document-save"), i18n("Save"), self.fileSave) bar.addWidget(WidgetSpacer(self)) bar.addWidget(QtWidgets.QLabel(i18n("Serial Port:"))) bar.addWidget(WidgetSpacer(self, 12)) self.portSelector = PortSelector(self) bar.addWidget(self.portSelector) self.portSelector.setToolTip(i18n("Select Serial Port")) self.runAction = bar.addAction(icon("run"), i18n("Run"), self.progRun) self.runAction.setEnabled(False) self.dlAction = bar.addAction(icon("download"), i18n("Download"), self.progDownload) self.dlAction.setEnabled(False) self.termAction = bar.addAction(icon("terminal"), i18n("Terminal"), self.openTerm) self.termAction.setEnabled(False) self.termAction.setCheckable(True) bar.addAction(icon("about"), i18n("Help"), self.showhelp) self.addToolBar(bar)
def fileNew(self): code_edit = self.createEditor() i = self.tabber.add_code_edit(code_edit, i18n("NewFile.py (%d)")) self.tabber.setCurrentIndex(i)