diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/defconQt/fontView.py | 70 | ||||
| -rw-r--r-- | Lib/defconQt/glyphCollectionView.py | 20 | ||||
| -rw-r--r-- | Lib/defconQt/glyphView.py | 18 | ||||
| -rw-r--r-- | Lib/defconQt/spaceCenter.py | 42 |
4 files changed, 114 insertions, 36 deletions
diff --git a/Lib/defconQt/fontView.py b/Lib/defconQt/fontView.py index 04633a2..c3849d3 100644 --- a/Lib/defconQt/fontView.py +++ b/Lib/defconQt/fontView.py @@ -8,18 +8,18 @@ from defconQt.scriptingWindow import MainScriptingWindow from defconQt.objects.defcon import GlyphSet, TFont, TGlyph from defconQt.util import platformSpecific from defcon import Color, Component -from defconQt.spaceCenter import MainSpaceWindow +from defconQt.spaceCenter import MainSpaceWindow, comboBoxItems from PyQt5.QtCore import ( pyqtSignal, QEvent, QMimeData, QRegularExpression, QSettings, Qt) from PyQt5.QtGui import ( QColor, QCursor, QIcon, QIntValidator, QKeySequence, QPixmap, QRegularExpressionValidator, QTextCursor) from PyQt5.QtWidgets import ( - QAction, QApplication, QCheckBox, QComboBox, QDialog, QDialogButtonBox, - QErrorMessage, QFileDialog, QGridLayout, QGroupBox, QLabel, QLineEdit, - QListWidget, QListWidgetItem, QMainWindow, QMenu, QMessageBox, - QPlainTextEdit, QPushButton, QRadioButton, QSlider, QSplitter, QTabWidget, - QTextEdit, QToolTip, QVBoxLayout, QWidget) + QAbstractItemView, QAction, QApplication, QCheckBox, QComboBox, QDialog, + QDialogButtonBox, QErrorMessage, QFileDialog, QGridLayout, QGroupBox, + QLabel, QLineEdit, QListWidget, QListWidgetItem, QMainWindow, QMenu, + QMessageBox, QPlainTextEdit, QPushButton, QRadioButton, QSlider, QSplitter, + QTabWidget, QTextEdit, QToolTip, QVBoxLayout, QWidget) from collections import OrderedDict import os import pickle @@ -1190,6 +1190,7 @@ class SettingsDialog(QDialog): self.tabWidget = QTabWidget(self) self.tabWidget.addTab(GlyphSetTab(self), "Glyph sets") + self.tabWidget.addTab(SpaceCenterTab(self), "Space center") buttonBox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel) @@ -1210,7 +1211,7 @@ class SettingsDialog(QDialog): def getDefaultGlyphSet(settings=None): if settings is None: settings = QSettings() - settings.value("settings/defaultGlyphSet", latinDefault.name, type=str) + settings.value("settings/defaultGlyphSet", latinDefault.name, str) def readGlyphSets(settings=None): @@ -1239,7 +1240,7 @@ class GlyphSetTab(QWidget): self.defaultGlyphSetBox = QCheckBox("Default glyph set:", self) self.defaultGlyphSetDrop = QComboBox(self) defaultGlyphSet = settings.value( - "settings/defaultGlyphSet", latinDefault.name, type=str) + "settings/defaultGlyphSet", latinDefault.name, str) self.defaultGlyphSetBox.toggled.connect(self.toggleGlyphSetDrop) self.defaultGlyphSetBox.setChecked(len(defaultGlyphSet)) self.glyphSets = readGlyphSets() @@ -1266,7 +1267,7 @@ class GlyphSetTab(QWidget): splitter.addWidget(self.glyphSetContents) self.addGlyphSetButton = QPushButton("+", self) self.addGlyphSetButton.pressed.connect(self.addGlyphSet) - self.removeGlyphSetButton = QPushButton("-", self) + self.removeGlyphSetButton = QPushButton("−", self) self.removeGlyphSetButton.setEnabled(len(self.glyphSets) > 1) self.removeGlyphSetButton.pressed.connect(self.removeGlyphSet) self.importButton = QPushButton("Import", self) @@ -1365,3 +1366,54 @@ class GlyphSetTab(QWidget): defaultGlyphSet = self.defaultGlyphSetDrop.currentText() if defaultGlyphSet != latinDefault.name: settings.setValue("settings/defaultGlyphSet", defaultGlyphSet) + + +class SpaceCenterTab(QTabWidget): + + def __init__(self, parent=None): + super(SpaceCenterTab, self).__init__(parent) + + settings = QSettings() + self.inputTextLabel = QLabel("Default text:", self) + self.inputTextList = QListWidget(self) + self.inputTextList.setDragDropMode(QAbstractItemView.InternalMove) + entries = settings.value("spaceCenter/comboBoxItems", comboBoxItems, + str) + for entry in entries: + item = QListWidgetItem(entry, self.inputTextList) + item.setFlags(item.flags() | Qt.ItemIsEditable) + self.addItemButton = QPushButton("+", self) + self.removeItemButton = QPushButton("−", self) + if not len(entries): + self.removeItemButton.setEnabled(False) + + layout = QGridLayout(self) + l = 0 + layout.addWidget(self.inputTextLabel, l, 0, 1, 3) + l += 1 + layout.addWidget(self.inputTextList, l, 0, 1, 3) + l += 1 + layout.addWidget(self.addItemButton, l, 0) + layout.addWidget(self.removeItemButton, l, 1) + self.setLayout(layout) + + def addItem(self): + item = QListWidgetItem(self.inputTextList) + item.setFlags(item.flags() | Qt.ItemIsEditable) + self.inputTextList.setCurrentItem(item) + self.inputTextList.editItem(item) + self.removeItemButton.setEnabled(True) + + def removeItem(self): + i = self.inputTextList.currentRow() + self.inputTextList.takeItem(i) + if not self.inputTextList.count(): + self.removeItemButton.setEnabled(False) + + def writeValues(self): + entries = [] + for i in range(self.inputTextList.count()): + item = self.inputTextList.item(i) + entries.append(item.text()) + settings = QSettings() + settings.setValue("spaceCenter/comboBoxItems", entries) diff --git a/Lib/defconQt/glyphCollectionView.py b/Lib/defconQt/glyphCollectionView.py index c56874f..d7c3188 100644 --- a/Lib/defconQt/glyphCollectionView.py +++ b/Lib/defconQt/glyphCollectionView.py @@ -50,8 +50,7 @@ class GlyphCollectionWidget(QWidget): super(GlyphCollectionWidget, self).__init__(parent) self.setAttribute(Qt.WA_KeyCompression) self._glyphs = [] - # TODO: hide behind a façade - self.squareSize = 56 + self._squareSize = 56 self._columns = 10 self._selection = set() self._oldSelection = None @@ -124,6 +123,16 @@ class GlyphCollectionWidget(QWidget): index = self._lastSelectedCell return self._glyphs[index] if index is not None else None + def _get_squareSize(self): + return self._squareSize + + def _set_squareSize(self, squareSize): + self._squareSize = squareSize + voidFont.setPointSize(.425 * self.squareSize) + + squareSize = property(_get_squareSize, _set_squareSize, doc="The size of" + "a glyph cell.") + def scrollArea(self): return self._scrollArea @@ -239,6 +248,9 @@ class GlyphCollectionWidget(QWidget): self.lastSelectedCell = newSel def keyPressEvent(self, event): + def isUnicodeChar(char): + return len(char) and unicodedata.category(char) != "Cc" + key = event.key() modifiers = event.modifiers() if key in arrowKeys: @@ -270,8 +282,8 @@ class GlyphCollectionWidget(QWidget): # XXX: have template setter clear glyph content glyph.template = True self.selection = set() - elif (modifiers in (Qt.NoModifier, Qt.ShiftModifier) and - unicodedata.category(event.text()) != "Cc"): + elif modifiers in (Qt.NoModifier, Qt.ShiftModifier) and \ + isUnicodeChar(event.text()): # adapted from defconAppkit # get the current time rightNow = time.time() diff --git a/Lib/defconQt/glyphView.py b/Lib/defconQt/glyphView.py index 88b3761..29255e2 100644 --- a/Lib/defconQt/glyphView.py +++ b/Lib/defconQt/glyphView.py @@ -350,16 +350,6 @@ class MainGfxWindow(QMainWindow): toolsGroup.addAction(knifeToolButton) self.addToolBar(toolBar) - self.setContextMenuPolicy(Qt.ActionsContextMenu) - createAnchorAction = QAction("Add Anchor…", self) - createAnchorAction.triggered.connect( - self._redirect('view', 'createAnchor')) - self.addAction(createAnchorAction) - createComponentAction = QAction("Add Component…", self) - createComponentAction.triggered.connect( - self._redirect('view', 'createComponent')) - self.addAction(createComponentAction) - for layer in self._layerSet: self._listenToLayer(layer) @@ -1849,6 +1839,14 @@ class GlyphView(QGraphicsView): self.addBlues() self.addHorizontalMetrics() + self.setContextMenuPolicy(Qt.ActionsContextMenu) + createAnchorAction = QAction("Add Anchor…", self) + createAnchorAction.triggered.connect(self.createAnchor) + self.addAction(createAnchorAction) + createComponentAction = QAction("Add Component…", self) + createComponentAction.triggered.connect(self.createComponent) + self.addAction(createComponentAction) + for layer in layerSet: if self._name not in layer: self._listenToLayer(layer) diff --git a/Lib/defconQt/spaceCenter.py b/Lib/defconQt/spaceCenter.py index 1af5208..fa5d25b 100644 --- a/Lib/defconQt/spaceCenter.py +++ b/Lib/defconQt/spaceCenter.py @@ -2,7 +2,7 @@ from defconQt import icons_db # noqa from defconQt.glyphCollectionView import cellSelectionColor from defconQt.glyphView import MainGfxWindow from getpass import getuser -from PyQt5.QtCore import QEvent, QSize, Qt +from PyQt5.QtCore import QEvent, QSettings, QSize, Qt from PyQt5.QtGui import ( QBrush, QColor, QIcon, QIntValidator, QKeySequence, QPainter, QPen) from PyQt5.QtWidgets import ( @@ -10,6 +10,14 @@ from PyQt5.QtWidgets import ( QPushButton, QScrollArea, QStyledItemDelegate, QTableWidget, QTableWidgetItem, QVBoxLayout, QSizePolicy, QToolBar, QWidget) +comboBoxItems = [ + "abcdefghijklmnopqrstuvwxyz", + "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "0123456789", + "nn/? nono/? oo", + "HH/? HOHO/? OO", +] + defaultPointSize = 150 glyphSelectionColor = QColor(cellSelectionColor) glyphSelectionColor.setAlphaF(.09) @@ -29,19 +37,17 @@ class MainSpaceWindow(QWidget): string = "Hello %s" % string self.font = font self.glyphs = [] - self.toolbar = FontToolBar(string, pointSize, self) + self.toolbar = FontToolBar(pointSize, self) self.canvas = GlyphsCanvas(self.font, self.glyphs, pointSize, self) self.table = SpaceTable(self.glyphs, self) self.toolbar.comboBox.currentIndexChanged[ str].connect(self.canvas.setPointSize) - self.toolbar.textField.textEdited.connect(self._textChanged) + self.toolbar.textField.editTextChanged.connect(self._textChanged) self.canvas.doubleClickCallback = self._glyphOpened self.canvas.pointSizeCallback = self.toolbar.setPointSize self.canvas.selectionChangedCallback = self.table.setCurrentGlyph self.table.selectionChangedCallback = self.canvas.setSelected - # TODO: not exactly DRY - self.toolbar.textField.setText(string) - self.toolbar.textField.textEdited.emit(string) + self.toolbar.textField.setEditText(string) app = QApplication.instance() app.currentGlyphChanged.connect(self._textChanged) @@ -88,7 +94,7 @@ class MainSpaceWindow(QWidget): self._unsubscribeFromGlyphs() # subscribe to the new glyphs left = self.textToGlyphNames(self.toolbar.leftTextField.text()) - newText = self.textToGlyphNames(self.toolbar.textField.text()) + newText = self.textToGlyphNames(self.toolbar.textField.currentText()) right = self.textToGlyphNames(self.toolbar.rightTextField.text()) leftGlyphs = [] for name in left: @@ -186,7 +192,7 @@ class MainSpaceWindow(QWidget): glyphNames.append(chr(glyph.unicode)) else: glyphNames.append("".join(("/", glyph.name, " "))) - self.toolbar.textField.setText("".join(glyphNames)) + self.toolbar.textField.setEditText("".join(glyphNames)) # set the records into the view self.canvas.setGlyphs(self.glyphs) self.table.setGlyphs(self.glyphs) @@ -201,22 +207,32 @@ pointSizes = [50, 75, 100, 125, 150, 200, 250, 300, 350, 400, 450, 500] class FontToolBar(QToolBar): - def __init__(self, string, pointSize, parent=None): + def __init__(self, pointSize, parent=None): super(FontToolBar, self).__init__(parent) auxiliaryWidth = self.fontMetrics().width('0') * 8 self.leftTextField = QLineEdit(self) self.leftTextField.setMaximumWidth(auxiliaryWidth) - self.textField = QLineEdit(string, self) + self.textField = QComboBox(self) + self.textField.setEditable(True) + completer = self.textField.completer() + completer.setCaseSensitivity(Qt.CaseSensitive) + self.textField.setCompleter(completer) + # XXX: had to use Maximum because Preferred did entend the widget(?) + self.textField.setSizePolicy(QSizePolicy.Expanding, + QSizePolicy.Maximum) + items = QSettings().value("spaceCenter/comboBoxItems", comboBoxItems, + str) + self.textField.addItems(items) self.rightTextField = QLineEdit(self) self.rightTextField.setMaximumWidth(auxiliaryWidth) - self.leftTextField.textEdited.connect(self.textField.textEdited) - self.rightTextField.textEdited.connect(self.textField.textEdited) + self.leftTextField.textEdited.connect(self.textField.editTextChanged) + self.rightTextField.textEdited.connect(self.textField.editTextChanged) self.comboBox = QComboBox(self) self.comboBox.setEditable(True) self.comboBox.setValidator(QIntValidator(self)) for p in pointSizes: self.comboBox.addItem(str(p)) - self.comboBox.lineEdit().setText(str(pointSize)) + self.comboBox.setEditText(str(pointSize)) self.configBar = QPushButton(self) self.configBar.setFlat(True) |
