def __init__(self, parent=None): super().__init__(parent) self.editor = PythonEditor(self) self.resize(650, 500) fileMenu = QMenu(self.tr("&File"), self) fileMenu.addAction(self.tr("&New…"), self.newFile, QKeySequence.New) fileMenu.addAction(self.tr("&Open…"), self.openFile, QKeySequence.Open) fileMenu.addAction(self.tr("&Save"), self.saveFile, QKeySequence.Save) fileMenu.addAction(self.tr("Save &As…"), self.saveFileAs, QKeySequence.SaveAs) fileMenu.addSeparator() fileMenu.addAction(self.tr("&Run…"), self.runScript, "Ctrl+R") fileMenu.addSeparator() fileMenu.addAction(self.tr("&Close"), self.close, platformSpecific.closeKeySequence()) self.menuBar().addMenu(fileMenu) self.fileChooser = FileChooser(self) self.fileChooser.fileOpened.connect(self.openFile) splitter = QSplitter(self) splitter.addWidget(self.fileChooser) splitter.addWidget(self.editor) splitter.setStretchFactor(0, 2) splitter.setStretchFactor(1, 5) splitter.setSizes([0, 1]) self.setCentralWidget(splitter) self.newFile() self.editor.modificationChanged.connect(self.setWindowModified)
def __init__(self, font=None, parent=None): super().__init__(parent) self.font = font self.font.info.addObserver(self, "_fontInfoChanged", "Info.Changed") self.editor = FeatureCodeEditor(self) self.editor.setPlainText(self.font.features.text) self.editor.modificationChanged.connect(self.setWindowModified) fileMenu = QMenu(self.tr("&File"), self) fileMenu.addAction(self.tr("&Save…"), self.save, QKeySequence.Save) fileMenu.addSeparator() fileMenu.addAction(self.tr("&Reload From Disk"), self.reload) fileMenu.addAction( self.tr("&Close"), self.close, platformSpecific.closeKeySequence()) self.menuBar().addMenu(fileMenu) self.updateWindowTitle() self.setCentralWidget(self.editor) self.resize(600, 500)
def __init__(self, font, parent=None): super().__init__(parent) self._font = None self._infoWindow = None self._featuresWindow = None self._groupsWindow = None self._kerningWindow = None self._metricsWindow = None self.toolBar = ToolBar(self) self.toolBar.setTools(t() for t in QApplication.instance().drawingTools()) self.glyphCellView = GlyphCellView(self) self.glyphCellView.glyphActivated.connect(self.openGlyphTab) self.glyphCellView.glyphsDropped.connect(self._orderChanged) self.glyphCellView.selectionChanged.connect(self._selectionChanged) self.glyphCellView.setAcceptDrops(True) self.glyphCellView.setCellRepresentationName("TruFont.GlyphCell") self.glyphCellView.setFrameShape(self.glyphCellView.NoFrame) self.glyphCellView.setFocus() self.tabWidget = TabWidget(self) self.tabWidget.setAutoHide(True) self.tabWidget.setHeroFirstTab(True) self.tabWidget.addTab(self.tr("Font")) self.stackWidget = QStackedWidget(self) self.stackWidget.addWidget(self.glyphCellView) self.tabWidget.currentTabChanged.connect(self._tabChanged) self.tabWidget.tabRemoved.connect( lambda index: self.stackWidget.removeWidget(self.stackWidget.widget(index)) ) self.stackWidget.currentChanged.connect(self._widgetChanged) self.propertiesView = PropertiesView(font, self) self.propertiesView.hide() self.statusBar = StatusBar(self) self.statusBar.setMinimumSize(32) self.statusBar.setMaximumSize(128) self.statusBar.sizeChanged.connect(self._sizeChanged) self.setFont_(font) app = QApplication.instance() app.dispatcher.addObserver( self, "_drawingToolRegistered", "drawingToolRegistered" ) app.dispatcher.addObserver( self, "_drawingToolUnregistered", "drawingToolUnregistered" ) app.dispatcher.addObserver( self, "_glyphViewGlyphsChanged", "glyphViewGlyphsChanged" ) layout = QHBoxLayout(self) layout.addWidget(self.toolBar) vLayout = QVBoxLayout() vLayout.addWidget(self.tabWidget) pageWidget = PageWidget() pageWidget.addWidget(self.stackWidget) pageWidget.addWidget(self.statusBar) vLayout.addWidget(pageWidget) layout.addLayout(vLayout) layout.addWidget(self.propertiesView) layout.setContentsMargins(0, 2, 0, 0) layout.setSpacing(2) elements = [ ("Ctrl+D", self.deselect), (platformSpecific.closeKeySequence(), self.closeGlyphTab), # XXX: does this really not warrant widget focus? (QKeySequence.Delete, self.delete), ("Shift+" + QKeySequence(QKeySequence.Delete).toString(), self.delete), ("Z", lambda: self.zoom(1)), ("X", lambda: self.zoom(-1)), ] e = platformSpecific.altDeleteSequence() if e is not None: elements.append((e, self.delete)) e = platformSpecific.altRedoSequence() if e is not None: elements.append((e, self.redo)) for keys, callback in elements: shortcut = QShortcut(QKeySequence(keys), self) shortcut.activated.connect(callback) self.installEventFilter(PreviewEventFilter(self)) self.readSettings() self.propertiesView.activeLayerModified.connect(self._activeLayerModified) self.statusBar.sizeChanged.connect(self.writeSettings)
Window_Scripting = "&Scripting" Window_Properties = "&Properties" Window_Output = "&Output" Help = "&Help" Help_Documentation = "&Documentation" Help_Report_An_Issue = "&Report an Issue" Help_About = "&About" _shortcuts = { Entries.File_New: QKeySequence.New, Entries.File_Open: QKeySequence.Open, Entries.File_Save: QKeySequence.Save, Entries.File_Save_As: QKeySequence.SaveAs, Entries.File_Close: platformSpecific.closeKeySequence(), Entries.File_Export: "Ctrl+E", Entries.File_Exit: QKeySequence.Quit, Entries.Edit_Undo: QKeySequence.Undo, Entries.Edit_Redo: QKeySequence.Redo, Entries.Edit_Cut: QKeySequence.Cut, Entries.Edit_Copy: QKeySequence.Copy, Entries.Edit_Copy_As_Component: "Ctrl+Alt+C", Entries.Edit_Paste: QKeySequence.Paste, Entries.Edit_Select_All: QKeySequence.SelectAll, Entries.Edit_Deselect: "Ctrl+D", Entries.Edit_Find: QKeySequence.Find, Entries.View_Zoom_In: QKeySequence.ZoomIn, Entries.View_Zoom_Out: QKeySequence.ZoomOut, Entries.View_Reset_Zoom: "Ctrl+0", Entries.View_Next_Tab: QKeySequence.NextChild,
Window_Metrics = "M&etrics" Window_Scripting = "&Scripting" Window_Output = "&Output" Help = "&Help" Help_Documentation = "&Documentation" Help_Report_An_Issue = "&Report an Issue" Help_About = "&About" _shortcuts = { Entries.File_New: QKeySequence.New, Entries.File_Open: QKeySequence.Open, Entries.File_Save: QKeySequence.Save, Entries.File_Save_As: QKeySequence.SaveAs, Entries.File_Close: platformSpecific.closeKeySequence(), Entries.File_Export: "Ctrl+E", Entries.File_Exit: QKeySequence.Quit, Entries.Edit_Undo: QKeySequence.Undo, Entries.Edit_Redo: QKeySequence.Redo, Entries.Edit_Cut: QKeySequence.Cut, Entries.Edit_Copy: QKeySequence.Copy, Entries.Edit_Copy_As_Component: "Ctrl+Alt+C", Entries.Edit_Paste: QKeySequence.Paste, Entries.Edit_Select_All: QKeySequence.SelectAll, Entries.Edit_Find: QKeySequence.Find, Entries.View_Zoom_In: QKeySequence.ZoomIn, Entries.View_Zoom_Out: QKeySequence.ZoomOut, Entries.View_Reset_Zoom: "Ctrl+0",
def __init__(self, glyph, parent=None): super().__init__(parent) self.setAttribute(Qt.WA_DeleteOnClose, False) menuBar = self.menuBar() fileMenu = QMenu(self.tr("&File"), self) fileMenu.addAction( self.tr("&Save"), self.saveFile, QKeySequence.Save) action = fileMenu.addAction( self.tr("&Close"), self.close, platformSpecific.closeKeySequence()) menuBar.addMenu(fileMenu) editMenu = QMenu(self.tr("&Edit"), self) self._undoAction = editMenu.addAction( self.tr("&Undo"), self.undo, QKeySequence.Undo) self._redoAction = editMenu.addAction( self.tr("&Redo"), self.redo, QKeySequence.Redo) editMenu.addSeparator() cutAction = editMenu.addAction( self.tr("C&ut"), self.cutOutlines, QKeySequence.Cut) copyAction = editMenu.addAction( self.tr("&Copy"), self.copyOutlines, QKeySequence.Copy) self._selectActions = (cutAction, copyAction) editMenu.addAction( self.tr("&Paste"), self.pasteOutlines, QKeySequence.Paste) editMenu.addAction( self.tr("Select &All"), self.selectAll, QKeySequence.SelectAll) editMenu.addAction(self.tr("&Deselect"), self.deselect, "Ctrl+D") menuBar.addMenu(editMenu) glyphMenu = QMenu(self.tr("&Glyph"), self) glyphMenu.addAction( self.tr("&Next Glyph"), lambda: self.glyphOffset(1), "End") glyphMenu.addAction( self.tr("&Previous Glyph"), lambda: self.glyphOffset(-1), "Home") glyphMenu.addAction(self.tr("&Go To…"), self.changeGlyph, "G") glyphMenu.addSeparator() self._layerAction = glyphMenu.addAction( self.tr("&Layer Actions…"), self.layerActions, "L") menuBar.addMenu(glyphMenu) self.view = GlyphCanvasView(self) # create tools and buttons toolBars # TODO: switch to ButtonToolBar self._tools = [] self._toolsToolBar = QToolBar(self.tr("Tools"), self) self._toolsToolBar.setMovable(False) self._buttons = [] self._buttonsToolBar = QToolBar(self.tr("Buttons"), self) self._buttonsToolBar.setMovable(False) self.addToolBar(self._toolsToolBar) self.addToolBar(self._buttonsToolBar) # http://www.setnode.com/blog/right-aligning-a-button-in-a-qtoolbar/ self._layersToolBar = QToolBar(self.tr("Layers"), self) spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._currentLayerBox = QComboBox(self) self._currentLayerBox.currentIndexChanged.connect( self._layerChanged) self._layersToolBar.addWidget(spacer) self._layersToolBar.addWidget(self._currentLayerBox) self._layersToolBar.setContentsMargins(0, 0, 2, 0) self._layersToolBar.setMovable(False) self.addToolBar(self._layersToolBar) viewMenu = self.createPopupMenu() viewMenu.setTitle(self.tr("View")) viewMenu.addSeparator() action = viewMenu.addAction( self.tr("Lock Toolbars"), self.lockToolBars) viewMenu.addSeparator() viewMenu.addAction( self.tr("Zoom In"), lambda: self.view.zoom(1), QKeySequence.ZoomIn) viewMenu.addAction( self.tr("Zoom Out"), lambda: self.view.zoom(-1), QKeySequence.ZoomOut) viewMenu.addAction( self.tr("Reset Zoom"), self.view.fitScaleBBox, "Ctrl+0") action.setCheckable(True) action.setChecked(True) menuBar.addMenu(viewMenu) self.setGlyph(glyph) app = QApplication.instance() tools = app.drawingTools() for index, tool in enumerate(tools): action = self.installTool(tool) if not index: action.trigger() app.dispatcher.addObserver( self, "_drawingToolInstalled", "drawingToolInstalled") self.installButton(RemoveOverlapButton) self.setCentralWidget(self.view) self.resize(900, 700) self.view.setFocus(True)