aboutsummaryrefslogtreecommitdiffstats
path: root/Lib/defconQt
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/defconQt')
-rw-r--r--Lib/defconQt/__init__.py1
-rw-r--r--Lib/defconQt/charmap.py339
-rw-r--r--Lib/defconQt/controls/__init__.py0
-rw-r--r--Lib/defconQt/controls/__pycache__/__init__.cpython-34.pycbin0 -> 151 bytes
-rw-r--r--Lib/defconQt/controls/__pycache__/glyphCellView.cpython-34.pycbin0 -> 4281 bytes
-rw-r--r--Lib/defconQt/controls/__pycache__/glyphCellView_ex.cpython-34.pycbin0 -> 4703 bytes
-rw-r--r--Lib/defconQt/controls/glyphCellView_ex.py158
-rw-r--r--Lib/defconQt/representationFactories/__init__.py293
-rw-r--r--Lib/defconQt/representationFactories/__pycache__/__init__.cpython-34.pycbin0 -> 7097 bytes
-rw-r--r--Lib/defconQt/representationFactories/glyphCellFactory.py270
-rw-r--r--Lib/defconQt/representationFactories/qPainterPathFactory.py6
-rw-r--r--Lib/defconQt/test.py19
-rw-r--r--Lib/defconQt/windows/__init__.py0
-rw-r--r--Lib/defconQt/windows/__pycache__/baseWindow.cpython-34.pycbin0 -> 3518 bytes
-rw-r--r--Lib/defconQt/windows/__pycache__/progressWindow.cpython-34.pycbin0 -> 1391 bytes
-rw-r--r--Lib/defconQt/windows/baseWindow.py101
-rw-r--r--Lib/defconQt/windows/progressWindow.py50
-rw-r--r--Lib/defconQt/windows/test.py45
-rw-r--r--Lib/defconQt/windows/test2.py13
-rw-r--r--Lib/defconQt/windows/test3.py15
20 files changed, 1310 insertions, 0 deletions
diff --git a/Lib/defconQt/__init__.py b/Lib/defconQt/__init__.py
new file mode 100644
index 0000000..c128876
--- /dev/null
+++ b/Lib/defconQt/__init__.py
@@ -0,0 +1 @@
+version = "0.1" \ No newline at end of file
diff --git a/Lib/defconQt/charmap.py b/Lib/defconQt/charmap.py
new file mode 100644
index 0000000..0032a0f
--- /dev/null
+++ b/Lib/defconQt/charmap.py
@@ -0,0 +1,339 @@
+#!/usr/bin/env python
+
+
+#############################################################################
+##
+## Copyright (C) 2013 Riverbank Computing Limited.
+## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+## All rights reserved.
+##
+## This file is part of the examples of PyQt.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+## the names of its contributors may be used to endorse or promote
+## products derived from this software without specific prior written
+## permission.
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+import representationFactories
+import unicodedata
+
+from defcon import Font
+from PyQt5.QtCore import pyqtSignal, QSize, Qt
+from PyQt5.QtGui import (QClipboard, QFont, QFontDatabase, QFontMetrics,
+ QPainter)
+from PyQt5.QtWidgets import (QApplication, QCheckBox, QComboBox, QFontComboBox,
+ QHBoxLayout, QLabel, QLineEdit, QMainWindow, QPushButton, QScrollArea,
+ QToolTip, QVBoxLayout, QWidget)
+
+glyphSortDescriptors = [
+ dict(type="alphabetical", allowPseudoUnicode=True),
+ dict(type="category", allowPseudoUnicode=True),
+ dict(type="unicode", allowPseudoUnicode=True),
+ dict(type="script", allowPseudoUnicode=True),
+ dict(type="suffix", allowPseudoUnicode=True),
+ dict(type="decompositionBase", allowPseudoUnicode=True)
+]
+
+class CharacterWidget(QWidget):
+
+ characterSelected = pyqtSignal(str)
+
+ def __init__(self, font, parent=None):
+ super(CharacterWidget, self).__init__(parent)
+
+ self.font = font
+ self.glyphs = [font[k] for k in font.unicodeData.sortGlyphNames(font.keys(), glyphSortDescriptors)]
+ self.squareSize = 48
+ self.columns = 11
+ self.lastKey = -1
+# self.setMouseTracking(True)
+
+ def updateFont(self, fontFamily):
+ self.displayFont.setFamily(fontFamily)
+ self.squareSize = max(24, QFontMetrics(self.displayFont).xHeight() * 3)
+ self.adjustSize()
+ self.update()
+
+ def updateSize(self, fontSize):
+# fontSize, _ = fontSize.toInt()
+ self.displayFont.setPointSize(int(fontSize))
+ self.squareSize = max(24, QFontMetrics(self.displayFont).xHeight() * 3)
+ self.adjustSize()
+ self.update()
+
+ def updateStyle(self, fontStyle):
+ fontDatabase = QFontDatabase()
+ oldStrategy = self.displayFont.styleStrategy()
+ self.displayFont = fontDatabase.font(self.displayFont.family(),
+ fontStyle, self.displayFont.pointSize())
+ self.displayFont.setStyleStrategy(oldStrategy)
+ self.squareSize = max(24, QFontMetrics(self.displayFont).xHeight() * 3)
+ self.adjustSize()
+ self.update()
+
+ def updateFontMerging(self, enable):
+ if enable:
+ self.displayFont.setStyleStrategy(QFont.PreferDefault)
+ else:
+ self.displayFont.setStyleStrategy(QFont.NoFontMerging)
+ self.adjustSize()
+ self.update()
+
+ def sizeHint(self):
+ return QSize(self.columns * self.squareSize,
+ (65536 / self.columns) * self.squareSize)
+
+ '''
+ def mouseMoveEvent(self, event):
+ widgetPosition = self.mapFromGlobal(event.globalPos())
+ key = (widgetPosition.y() // self.squareSize) * self.columns + widgetPosition.x() // self.squareSize
+
+ # http://stackoverflow.com/questions/6598554/is-there-any-way-to-insert-qpixmap-object-in-html
+ text = '<p>Character: <span style="font-size: 24pt; font-family: %s">%s</span><p>Value: 0x%x' % (QFont().family(), self._chr(key), key)
+ QToolTip.showText(event.globalPos(), text, self)
+ '''
+
+ def mousePressEvent(self, event):
+ if event.button() == Qt.LeftButton:
+ self.lastKey = (event.y() // self.squareSize) * self.columns + event.x() // self.squareSize
+ key_ch = self._chr(self.lastKey)
+
+ if unicodedata.category(key_ch) != 'Cn':
+ self.characterSelected.emit(key_ch)
+ self.update()
+ else:
+ super(CharacterWidget, self).mousePressEvent(event)
+
+ def paintEvent(self, event):
+ painter = QPainter(self)
+ painter.setRenderHint(QPainter.Antialiasing)
+ painter.fillRect(event.rect(), Qt.white)
+ #painter.setFont(self.displayFont)
+
+ redrawRect = event.rect()
+ beginRow = redrawRect.top() // self.squareSize
+ endRow = redrawRect.bottom() // self.squareSize
+ beginColumn = redrawRect.left() // self.squareSize
+ endColumn = redrawRect.right() // self.squareSize
+
+ painter.setPen(Qt.gray)
+ for row in range(beginRow, endRow + 1):
+ for column in range(beginColumn, endColumn + 1):
+ painter.drawRect(column * self.squareSize,
+ row * self.squareSize, self.squareSize,
+ self.squareSize)
+
+# fontMetrics = QFontMetrics(self.displayFont)
+# painter.setPen(Qt.black)
+
+
+ """
+ draw = self.displayFont["a"].getRepresentation("defconQt.QPainterPath")
+ painter.save()
+ painter.setBrushOrigin(50, 150)
+# painter.scale(1.0, -1.0)
+# painter.translate(0,-self.squareSize)
+# p_x,p_y,p_w,p_h = draw.controlPointRect().getRect()
+# measure = max(p_w, p_h)
+# painter.scale(measure/self.squareSize, measure/self.squareSize)
+ painter.fillPath(draw, Qt.black)
+ painter.restore()
+ """
+ for row in range(beginRow, endRow + 1):
+ for column in range(beginColumn, endColumn + 1):
+ key = row * self.columns + column
+ x,y,w,h = column * self.squareSize, row * self.squareSize, self.squareSize, self.squareSize
+# painter.setClipRect(x,y,w,h)
+
+ if key == self.lastKey:
+ painter.fillRect(column * self.squareSize + 1,
+ row * self.squareSize + 1, self.squareSize - 2,
+ self.squareSize - 2, Qt.red)
+
+ key_ch = str(self._chr(key))
+# painter.drawText(column * self.squareSize + (self.squareSize / 2) - fontMetrics.width(key_ch) / 2,
+# row * self.squareSize + 4 + fontMetrics.ascent(),
+# key_ch)
+# print(key)
+ if key > len(self.glyphs)-1: break
+ glyph = self.glyphs[key].getRepresentation("defconQt.QPainterPath")
+# if key_ch not in self.displayFont: continue
+# glyph = self.displayFont[key_ch].getRepresentation("defconQt.QPainterPath") # , width=self.squareSize, height=self.squareSize
+ # When need to move the painter so that the path draws at the right place
+ print(glyph)
+# p_x,p_y,p_w,p_h = glyph.controlPointRect().getRect()
+# print(p_h, h)
+ painter.save()
+ if self.font.info.unitsPerEm > 0: factor = self.squareSize/(self.font.info.unitsPerEm*(1+2*.125))
+ if factor != 0: print(factor)
+ x_offset = (self.squareSize-self.glyphs[key].width*factor)/2
+ if x_offset < 0:
+ factor *= 1+2*x_offset/(self.glyphs[key].width*factor)
+ x_offset = 0
+ y_offset = self.font.info.descender*factor
+ print(self.glyphs[key].width)
+ print("xo: "+str(x_offset))
+ painter.translate(column * self.squareSize + x_offset, row * self.squareSize + self.squareSize + y_offset)
+# painter.setBrushOrigin((self.squareSize-self.glyphs[key].width)/2,self.font.info.descender)
+# painter.translate(column * self.squareSize + (self.squareSize / 2) - self.glyphs[key].width / 2,
+# row * self.squareSize + 4 + self.displayFont['hhea'].ascent)
+# painter.translate(p_x-x, p_y-y)
+# painter.scale(1.0, -1.0)
+# painter.translate(0,-self.squareSize)
+ painter.scale(factor, -factor)
+ painter.fillPath(glyph, Qt.black)
+ painter.restore()
+
+ @staticmethod
+ def _chr(codepoint):
+ try:
+ # Python v2.
+ return unichr(codepoint)
+ except NameError:
+ # Python v3.
+ return chr(codepoint)
+
+class MainWindow(QMainWindow):
+ def __init__(self, font=Font()):
+ super(MainWindow, self).__init__()
+
+ centralWidget = QWidget()
+
+ self.font = font
+
+ fontLabel = QLabel("Font:")
+ self.fontCombo = QFontComboBox()
+ sizeLabel = QLabel("Size:")
+ self.sizeCombo = QComboBox()
+ styleLabel = QLabel("Style:")
+ self.styleCombo = QComboBox()
+ fontMergingLabel = QLabel("Automatic Font Merging:")
+ self.fontMerging = QCheckBox()
+ self.fontMerging.setChecked(True)
+
+ self.scrollArea = QScrollArea()
+ self.characterWidget = CharacterWidget(self.font)
+ self.scrollArea.setWidget(self.characterWidget)
+
+ self.findStyles(self.fontCombo.currentFont())
+ self.findSizes(self.fontCombo.currentFont())
+
+ self.lineEdit = QLineEdit()
+ clipboardButton = QPushButton("&To clipboard")
+
+ self.clipboard = QApplication.clipboard()
+
+ self.fontCombo.currentFontChanged.connect(self.findStyles)
+ self.fontCombo.activated[str].connect(self.characterWidget.updateFont)
+ self.styleCombo.activated[str].connect(self.characterWidget.updateStyle)
+ self.sizeCombo.currentIndexChanged[str].connect(self.characterWidget.updateSize)
+ self.characterWidget.characterSelected.connect(self.insertCharacter)
+ clipboardButton.clicked.connect(self.updateClipboard)
+
+ controlsLayout = QHBoxLayout()
+ controlsLayout.addWidget(fontLabel)
+ controlsLayout.addWidget(self.fontCombo, 1)
+ controlsLayout.addWidget(sizeLabel)
+ controlsLayout.addWidget(self.sizeCombo, 1)
+ controlsLayout.addWidget(styleLabel)
+ controlsLayout.addWidget(self.styleCombo, 1)
+ controlsLayout.addWidget(fontMergingLabel)
+ controlsLayout.addWidget(self.fontMerging, 1)
+ controlsLayout.addStretch(1)
+
+ lineLayout = QHBoxLayout()
+ lineLayout.addWidget(self.lineEdit, 1)
+ lineLayout.addSpacing(12)
+ lineLayout.addWidget(clipboardButton)
+
+ centralLayout = QVBoxLayout()
+ centralLayout.addLayout(controlsLayout)
+ centralLayout.addWidget(self.scrollArea, 1)
+ centralLayout.addSpacing(4)
+ centralLayout.addLayout(lineLayout)
+ centralWidget.setLayout(centralLayout)
+
+ self.setCentralWidget(centralWidget)
+ self.setWindowTitle("Character Map")
+
+ def findStyles(self, font):
+ fontDatabase = QFontDatabase()
+ currentItem = self.styleCombo.currentText()
+ self.styleCombo.clear()
+
+ for style in fontDatabase.styles(font.family()):
+ self.styleCombo.addItem(style)
+
+ styleIndex = self.styleCombo.findText(currentItem)
+ if styleIndex == -1:
+ self.styleCombo.setCurrentIndex(0)
+ else:
+ self.styleCombo.setCurrentIndex(styleIndex)
+
+ def findSizes(self, font):
+ fontDatabase = QFontDatabase()
+ currentSize = self.sizeCombo.currentText()
+ self.sizeCombo.blockSignals(True)
+ self.sizeCombo.clear()
+
+ if fontDatabase.isSmoothlyScalable(font.family(), fontDatabase.styleString(font)):
+ for size in QFontDatabase.standardSizes():
+ self.sizeCombo.addItem(str(size))
+ self.sizeCombo.setEditable(True)
+ else:
+ for size in fontDatabase.smoothSizes(font.family(), fontDatabase.styleString(font)):
+ self.sizeCombo.addItem(str(size))
+ self.sizeCombo.setEditable(False)
+
+ self.sizeCombo.blockSignals(False)
+
+ sizeIndex = self.sizeCombo.findText(currentSize)
+ if sizeIndex == -1:
+ self.sizeCombo.setCurrentIndex(max(0, self.sizeCombo.count() / 3))
+ else:
+ self.sizeCombo.setCurrentIndex(sizeIndex)
+
+ def insertCharacter(self, character):
+ self.lineEdit.insert(character)
+
+ def updateClipboard(self):
+ self.clipboard.setText(self.lineEdit.text(), QClipboard.Clipboard)
+ self.clipboard.setText(self.lineEdit.text(), QClipboard.Selection)
+
+
+if __name__ == '__main__':
+
+ import sys
+
+ representationFactories.registerAllFactories()
+ app = QApplication(sys.argv)
+ window = MainWindow(Font("C:\\Veloce.ufo"))
+ window.show()
+ sys.exit(app.exec_())
diff --git a/Lib/defconQt/controls/__init__.py b/Lib/defconQt/controls/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Lib/defconQt/controls/__init__.py
diff --git a/Lib/defconQt/controls/__pycache__/__init__.cpython-34.pyc b/Lib/defconQt/controls/__pycache__/__init__.cpython-34.pyc
new file mode 100644
index 0000000..019189a
--- /dev/null
+++ b/Lib/defconQt/controls/__pycache__/__init__.cpython-34.pyc
Binary files differ
diff --git a/Lib/defconQt/controls/__pycache__/glyphCellView.cpython-34.pyc b/Lib/defconQt/controls/__pycache__/glyphCellView.cpython-34.pyc
new file mode 100644
index 0000000..274e224
--- /dev/null
+++ b/Lib/defconQt/controls/__pycache__/glyphCellView.cpython-34.pyc
Binary files differ
diff --git a/Lib/defconQt/controls/__pycache__/glyphCellView_ex.cpython-34.pyc b/Lib/defconQt/controls/__pycache__/glyphCellView_ex.cpython-34.pyc
new file mode 100644
index 0000000..8a99b74
--- /dev/null
+++ b/Lib/defconQt/controls/__pycache__/glyphCellView_ex.cpython-34.pyc
Binary files differ
diff --git a/Lib/defconQt/controls/glyphCellView_ex.py b/Lib/defconQt/controls/glyphCellView_ex.py
new file mode 100644
index 0000000..214da43
--- /dev/null
+++ b/Lib/defconQt/controls/glyphCellView_ex.py
@@ -0,0 +1,158 @@
+from PyQt5.QtCore import QPointF, QSize, Qt
+from PyQt5.QtGui import QBrush, QFont, QFontMetrics, QPainter, QPainterPath
+from PyQt5.QtWidgets import QApplication, QComboBox, QGridLayout, QWidget
+
+class RenderArea(QWidget):
+ def __init__(self, cellWidth, cellHeight, parent=None):
+ super(RenderArea, self).__init__(parent)
+
+ self.width_ = cellWidth
+ self.height_ = cellHeight
+# newFont = self.font()
+# newFont.setPixelSize(12)
+# self.setFont(newFont)
+
+# fontMetrics = QFontMetrics(newFont)
+# self.xBoundingRect = fontMetrics.boundingRect("x")
+# self.yBoundingRect = fontMetrics.boundingRect("y")
+ self.shape = QPainterPath()
+# self.operations = []
+
+ def setShape(self, shape):
+ self.shape = shape
+ self.update()
+
+ def minimumSizeHint(self):
+ return QSize(100, 100)
+
+ def sizeHint(self):
+ return QSize(self.width_, self.height_)
+
+ # Draw a QPainterPath stored in `self.shape`.
+ def oldPaint(self, event):
+ painter = QPainter(self)
+ painter.setRenderHint(QPainter.Antialiasing)
+
+ # Be cartesian
+ painter.translate(event.rect().bottomLeft())
+ painter.scale(1.0, -1.0)
+
+ painter.fillRect(event.rect(), QBrush(Qt.white))
+
+ painter.save()
+ self.drawShape(painter)
+ painter.restore()
+
+ #self.drawOutline(painter)
+ #self.drawCoordinates(painter)
+
+ def newPaint(self, event):
+ _, _, width, height = event.rect().getRect()
+ painter = glyph.getRepresentation("defconQt.QPainterPath", width=width, height=height)
+
+ def paintEvent(self, event):
+ #oldPaint(self, event)
+ pass
+
+ def drawCoordinates(self, painter):
+ #raise NotImplementedError
+ painter.setPen(Qt.red)
+
+ painter.drawLine(0, 0, 50, 0)
+ painter.drawLine(48, -2, 50, 0)
+ painter.drawLine(48, 2, 50, 0)
+ #painter.drawText(60 - self.xBoundingRect.width() / 2,
+ # 0 + self.xBoundingRect.height() / 2, "x")
+
+ painter.drawLine(0, 0, 0, 50)
+ painter.drawLine(-2, 48, 0, 50)
+ painter.drawLine(2, 48, 0, 50)
+ #painter.drawText(0 - self.yBoundingRect.width() / 2,
+ # 60 + self.yBoundingRect.height() / 2, "y")
+
+ '''
+ Debug method – paints a single glyph. drawGlyphCell() is the path forward.
+ '''
+ def drawGlyph(self, font, glyphId): #, width, height
+ #glyph = font[glyphId]
+
+ # TODO: need to write the cell repr
+ #rep = glyph.getRepresentation("defconQt.QPainterPath", width=width, height=height)
+ '''#TODO: adapt glyph size to window size
+ if not rep.isEmpty():
+ glyphWidth = glyph.width
+ '''
+ #self.setShape(rep)
+ self.glyph_ = font[glyphId]
+ self.update()
+
+ def drawGlyphCell(self, glyph, font):
+ rep = font[glyph].getRepresentation("defconQt.GlyphCell", width=self.width_, height=self.height_)
+ self.setShape(rep)
+ #GlyphCellFactory(glyph, font, self.width_, self.height_)
+
+ #def drawOutline(self, painter):
+ # painter.setPen(Qt.darkGreen)
+ # painter.setPen(Qt.DashLine)
+ # painter.setBrush(Qt.NoBrush)
+ # painter.drawRect(0, 0, 100, 100)
+
+ def drawShape(self, painter):
+ #painter.drawPath(self.shape)
+ painter.fillPath(self.shape, Qt.blue)
+
+
+class Window(QWidget):
+
+ def __init__(self, glyphs=[]):
+ super(Window, self).__init__()
+
+ self._glyphs = glyphs
+ self._cellWidth = 200
+ self._cellHeight = 200
+ self._cnt = 4 # till it shows the whole font
+ self.setWindowTitle("Font View")
+
+ self.layoutConstruction(self._cnt)
+
+
+ #self.preloadGlyphCellImages()
+
+ def layoutConstruction(self, cnt):
+ layout = QGridLayout()
+ #layout.setHorizontalSpacing(0)
+ #layout.setVerticalSpacing(0)
+
+ self.glyphsGrid = list(range(cnt))
+ for i in range(cnt):
+ self.glyphsGrid[i] = RenderArea(self._cellWidth, self._cellHeight)
+ layout.addWidget(self.glyphsGrid[i], 0, i)
+ self.setLayout(layout)
+
+ '''
+ def preloadGlyphCellImages(self):
+ representationName = self._cellRepresentationName
+ representationArguments = self._cellRepresentationArguments
+ cellWidth = self._cellWidth
+ cellHeight = self._cellHeight
+ for glyph in self._glyphs:
+ glyph.getRepresentation(representationName, width=cellWidth, height=cellHeight, **representationArguments)
+ self.setLayout(layout)
+ '''
+
+ def setGlyphs_(self, glyphs):
+ self._glyphs = glyphs
+ # self.glyphsGrid.setGlyphs(glyphs)
+
+
+ '''
+ Debug method.
+ '''
+ def setGlyph(self, font, glyphId):
+ self.glyphsGrid[0].drawGlyph(font, glyphId, self._cellWidth, self._cellHeight)
+
+ def shapeSelected(self, index):
+ shape = self.shapes[index]
+ self.glyphsGrid.setShape(shape)
+ for i in range(Window.NumTransformedAreas):
+ self.transformedRenderAreas[i].setShape(shape)
diff --git a/Lib/defconQt/representationFactories/__init__.py b/Lib/defconQt/representationFactories/__init__.py
new file mode 100644
index 0000000..fe62026
--- /dev/null
+++ b/Lib/defconQt/representationFactories/__init__.py
@@ -0,0 +1,293 @@
+from defcon.objects.glyph import addRepresentationFactory
+#from defconQt.representationFactories.qPainterPathFactory import QPainterPathFactory
+###
+from fontTools.pens.qtPen import QtPen
+
+def QPainterPathFactory(glyph, font):
+ pen = QtPen(font)
+ glyph.draw(pen)
+ return pen.path
+###
+#from defconQt.representationFactories.glyphCellFactory import GlyphCellFactory
+###
+from PyQt5.QtCore import QRect, Qt
+from PyQt5.QtGui import QColor, QPainter, QPixmap
+
+GlyphCellHeaderHeight = 14
+GlyphCellMinHeightForHeader = 40
+
+# 1 is white
+cellHeaderBaseColor = QColor.fromRgb(153, 153, 153).setAlphaF(.4)
+#NSColor.colorWithCalibratedWhite_alpha_(.6, .4)
+cellHeaderHighlightColor = QColor.fromRgb(178, 178, 178).setAlphaF(.4)
+#NSColor.colorWithCalibratedWhite_alpha_(.7, .4)
+cellHeaderSelectionColor = QColor.fromRgbF(.2, .3, .7, .15)
+#NSColor.colorWithCalibratedRed_green_blue_alpha_(.2, .3, .7, .15)
+cellHeaderLineColor = QColor.fromRgb(0, 0, 0).setAlphaF(.2)
+#NSColor.colorWithCalibratedWhite_alpha_(0, .2)
+cellHeaderHighlightLineColor = QColor.fromRgb(25, 25, 25).setAlphaF(.5)
+#NSColor.colorWithCalibratedWhite_alpha_(1, .5)
+cellMetricsLineColor = QColor.fromRgb(0, 0, 0).setAlphaF(.08)
+#NSColor.colorWithCalibratedWhite_alpha_(0, .08)
+cellMetricsFillColor = QColor.fromRgb(0, 0, 0).setAlphaF(.08)
+#NSColor.colorWithCalibratedWhite_alpha_(0, .08)
+
+
+
+def GlyphCellFactory(glyph, font, width, height, drawHeader=False, drawMetrics=False):
+ obj = GlyphCellFactoryDrawingController(glyph=glyph, font=font, width=width, height=height, drawHeader=drawHeader, drawMetrics=drawMetrics)
+ return obj.getImage()
+
+
+class GlyphCellFactoryDrawingController(object):
+
+ """
+ This draws the cell with the layers stacked in this order:
+ ------------------
+ header text
+ ------------------
+ header background
+ ------------------
+ foreground
+ ------------------
+ glyph
+ ------------------
+ vertical metrics
+ ------------------
+ horizontal metrics
+ ------------------
+ background
+ ------------------
+
+ Subclasses may override the layer drawing methods to customize
+ the appearance of cells.
+ """
+
+ def __init__(self, glyph, font, width, height, drawHeader=False, drawMetrics=False):
+ self.glyph = glyph
+ self.font = font
+ self.width = width
+ self.height = height
+ self.bufferPercent = .2
+ self.shouldDrawHeader = drawHeader
+ self.shouldDrawMetrics = drawMetrics
+
+ self.headerHeight = 0
+ if drawHeader:
+ self.headerHeight = GlyphCellHeaderHeight
+ availableHeight = (height - self.headerHeight) * (1.0 - (self.bufferPercent * 2))
+ self.buffer = height * self.bufferPercent
+ self.scale = availableHeight / font.info.unitsPerEm
+ self.xOffset = (width - (glyph.width * self.scale)) / 2
+ self.yOffset = abs(font.info.descender * self.scale) + self.buffer
+
+ def getImage(self):
+ image = QPixmap(self.width, self.height) #NSImage.alloc().initWithSize_((self.width, self.height))
+ painter = QPainter(image).setRenderHint(QPainter.Antialiasing)
+ #image.setFlipped_(True)
+ #image.lockFocus()
+ #context = NSGraphicsContext.currentContext()
+
+ # Below is probably wrong… find out about (x,y) orientation and plane translation that might affect this
+ # Qt is top-left by default while AppKit is bottom-left – Qt translation+scale affects text display
+ bodyRect = QRect(0, self.headerHeight, self.width, self.height-self.headerHeight)
+ headerRect = QRect(0, 0, self.width, self.headerHeight)
+ #bodyRect = ((0, 0), (self.width, self.height-self.headerHeight))
+ #headerRect = ((0, -self.height+self.headerHeight), (self.width, self.headerHeight))
+ # background
+ painter.save()
+ #context.saveGraphicsState()
+ painter.translate(0, self.height-self.headerHeight)
+ painter.scale(1.0, -1.0)
+ #bodyTransform = NSAffineTransform.transform()
+ #bodyTransform.translateXBy_yBy_(0, self.height-self.headerHeight)
+ #bodyTransform.scaleXBy_yBy_(1.0, -1.0)
+ #bodyTransform.concat()
+ self.drawCellBackground(painter, bodyRect)
+ painter.restore()
+ #context.restoreGraphicsState()
+ # glyph
+ if self.shouldDrawMetrics:
+ self.drawCellHorizontalMetrics(painter, bodyRect)
+ self.drawCellVerticalMetrics(painter, bodyRect)
+ #context.saveGraphicsState()
+ painter.save()
+ # clip against background only
+ painter.setClipRect(QRect(0, 0, self.width, self.height-self.headerHeight))
+ #NSBezierPath.clipRect_()
+ painter.translate(self.xOffset, self.yOffset)
+ painter.scale(self.scale, self.scale)
+ #glyphTransform = NSAffineTransform.transform()
+ #glyphTransform.translateXBy_yBy_(self.xOffset, self.yOffset)
+ #glyphTransform.scaleBy_(self.scale)
+ #glyphTransform.concat()
+ self.drawCellGlyph(painter)
+ painter.restore()
+ #context.restoreGraphicsState()
+ # foreground
+ painter.save()
+ #context.saveGraphicsState()
+ #bodyTransform.concat() #why this lonely here?
+ self.drawCellForeground(painter, bodyRect)
+ painter.restore()
+ #context.restoreGraphicsState()
+ # header
+ if self.shouldDrawHeader:
+ painter.save()
+ #context.saveGraphicsState()
+ painter.translate(0, self.headerHeight)
+ painter.scale(1.0, -1.0)
+ #headerTransform = NSAffineTransform.transform()
+ #headerTransform.translateXBy_yBy_(0, self.headerHeight)
+ #headerTransform.scaleXBy_yBy_(1.0, -1.0)
+ #headerTransform.concat()
+ self.drawCellHeaderBackground(painter, headerRect)
+ self.drawCellHeaderText(painter, headerRect)
+ painter.restore()
+ #context.restoreGraphicsState()
+ # done
+ #image.unlockFocus()
+
+ return painter#image
+
+ def drawCellBackground(self, painter, rect):
+ pass
+
+ def drawCellHorizontalMetrics(self, painter, rect):
+ (xMin, yMin, width, height) = rect.getRect()
+ glyph = self.glyph
+ font = self.font
+ scale = self.scale
+ yOffset = self.yOffset
+ path = QPainterPath()
+ #path = NSBezierPath.bezierPath()
+ lines = set((0, font.info.descender, font.info.xHeight, font.info.capHeight, font.info.ascender))
+ for y in lines:
+ y = round((y * scale) + yMin + yOffset) - .5
+ path.moveTo(xMin, y)
+ path.lineTo(xMin + width, y)
+ #cellMetricsLineColor.set()
+ stroke = QPainterPathStroker().createStroke(path)
+ stroke.setWidth(1.0)
+
+ painter.save()
+ painter.setPen(cellMetricsLineColor)
+ painter.drawPath(stroke)
+ painter.restore()
+ #path.stroke()
+
+ def drawCellVerticalMetrics(self, painter, rect):
+ (xMin, yMin, width, height) = rect.getRect()
+ glyph = self.glyph
+ scale = self.scale
+ xOffset = self.xOffset
+ left = round((0 * scale) + xMin + xOffset) - .5
+ right = round((glyph.width * scale) + xMin + xOffset) - .5
+
+ # Does this replicate functionality properly? Need to check that…
+ painter.fillRect((xMin, yMin, left - xMin, height), cellMetricsFillColor)
+ painter.fillRect((xMin + right, yMin, width - xMin + right, height), cellMetricsFillColor)
+ #rects = [
+ # ((xMin, yMin), (left - xMin, height)),
+ # ((xMin + right, yMin), (width - xMin + right, height))
+ #]
+ #cellMetricsFillColor.set()
+ #NSRectFillListUsingOperation(rects, len(rects), NSCompositeSourceOver)
+
+ def drawCellGlyph(self, painter):
+ #NSColor.blackColor().set()
+ painter.fillPath(self.glyph.getRepresentation("defconQt.QPainterPath"), Qt.black)
+
+ def drawCellForeground(self, painter, rect):
+ pass
+
+ def drawCellHeaderBackground(self, painter, rect):
+ (xMin, yMin, width, height) = rect.getRect()
+ # background
+ gradient = QLinearGradient(rect.topLeft(), rect.bottomLeft())
+ gradient.setColorAt(0, cellHeaderHighlightColor)
+ gradient.setColorAt(1, cellHeaderBaseColor)
+ painter.save()
+ painter.rotate(90)
+ painter.fillRect(rect, gradient)
+ painter.restore()
+ #try:
+ # gradient = NSGradient.alloc().initWithColors_([cellHeaderHighlightColor, cellHeaderBaseColor])
+ # gradient.drawInRect_angle_(rect, 90)
+ #except NameError:
+ # cellHeaderBaseColor.set()
+ # NSRectFill(rect)
+ # left and right line
+ sizePath = QPainterPath()
+ sizePath.moveTo(xMin + .5, yMin)
+ sizePath.lineTo(xMin + .5, yMin + height)
+ sizePath.moveTo(xMin + width - 1.5, yMin)
+ sizePath.lineTo(xMin + width - 1.5, yMin + height)
+ sizeStroke = QPainterPathStroker().createStroke(path)
+ sizeStroke.setWidth(1.0)
+ #painter.save()
+ painter.setPen(cellHeaderHighlightLineColor)
+ painter.drawPath(sizeStroke)
+ #painter.restore()
+ #cellHeaderHighlightLineColor.set()
+ #sizePath = NSBezierPath.bezierPath()
+ #sizePath.moveToPoint_((xMin + .5, yMin))
+ #sizePath.lineToPoint_((xMin + .5, yMin + height))
+ #sizePath.moveToPoint_((xMin + width - 1.5, yMin))
+ #sizePath.lineToPoint_((xMin + width - 1.5, yMin + height))
+ #sizePath.setLineWidth_(1.0)
+ #sizePath.stroke()
+ # bottom line
+ bottomPath = QPainterPath()
+ bottomPath.moveTo(xMin, yMin + height - .5)
+ bottomPath.lineTo(xMin + width, yMin + height - .5)
+ #cellHeaderLineColor.set()
+ #bottomPath = NSBezierPath.bezierPath()
+ #bottomPath.moveToPoint_((xMin, yMin + height - .5))
+ #bottomPath.lineToPoint_((xMin + width, yMin + height - .5))
+ #bottomPath.setLineWidth_(1.0)
+ #bottomPath.stroke()
+ bottomStroke = QPainterPathStroker().createStroke(path)
+ bottomStroke.setWidth(1.0)
+ #painter.save()
+ painter.setPen(cellHeaderLineColor)
+ painter.drawPath(bottomStroke)
+ #painter.restore()
+
+ def drawCellHeaderText(self, painter, rect):
+ textColor = QColor.fromRgbF(.22, .22, .27, 1.0)
+ #NSColor.colorWithCalibratedRed_green_blue_alpha_(.22, .22, .27, 1.0)
+
+ # TODO: no shadow for now, need to use QGraphicsDropShadowEffect but tricky to impl
+ #painter.save()
+ painter.setPen(textColor)
+ painter.setFont(QFont(QFont.defaultFamily(), 10))
+ painter.drawText(rect, Qt.AlignCenter, self.glyph.name);
+ #painter.restore()
+
+ #paragraph = NSMutableParagraphStyle.alloc().init()
+ #paragraph.setAlignment_(NSCenterTextAlignment)
+ #paragraph.setLineBreakMode_(NSLineBreakByTruncatingMiddle)
+ #shadow = NSShadow.alloc().init()
+ #shadow.setShadowColor_(NSColor.whiteColor())
+ #shadow.setShadowOffset_((0, 1))
+ #shadow.setShadowBlurRadius_(1)
+ #attributes = {
+ # NSFontAttributeName : NSFont.systemFontOfSize_(10.0),
+ # NSForegroundColorAttributeName : NSColor.colorWithCalibratedRed_green_blue_alpha_(.22, .22, .27, 1.0),
+ # NSParagraphStyleAttributeName : paragraph,
+ # NSShadowAttributeName : shadow
+ #}
+ #text = NSAttributedString.alloc().initWithString_attributes_(self.glyph.name, attributes)
+ #text.drawInRect_(rect)
+
+###
+
+_factories = {
+ "defconQt.QPainterPath" : QPainterPathFactory,
+ "defconQt.GlyphCell" : GlyphCellFactory,
+}
+
+def registerAllFactories():
+ for name, factory in _factories.items():
+ addRepresentationFactory(name, factory) \ No newline at end of file
diff --git a/Lib/defconQt/representationFactories/__pycache__/__init__.cpython-34.pyc b/Lib/defconQt/representationFactories/__pycache__/__init__.cpython-34.pyc
new file mode 100644
index 0000000..56b40d2
--- /dev/null
+++ b/Lib/defconQt/representationFactories/__pycache__/__init__.cpython-34.pyc
Binary files differ
diff --git a/Lib/defconQt/representationFactories/glyphCellFactory.py b/Lib/defconQt/representationFactories/glyphCellFactory.py
new file mode 100644
index 0000000..e975ae1
--- /dev/null
+++ b/Lib/defconQt/representationFactories/glyphCellFactory.py
@@ -0,0 +1,270 @@
+from PyQt5.QtCore import QRect, Qt
+from PyQt5.QtGui import QColor, QPainter, QPixmap
+
+GlyphCellHeaderHeight = 14
+GlyphCellMinHeightForHeader = 40
+
+# 1 is white
+cellHeaderBaseColor = QColor.fromRgb(153, 153, 153).setAlphaF(.4)
+#NSColor.colorWithCalibratedWhite_alpha_(.6, .4)
+cellHeaderHighlightColor = QColor.fromRgb(178, 178, 178).setAlphaF(.4)
+#NSColor.colorWithCalibratedWhite_alpha_(.7, .4)
+cellHeaderSelectionColor = QColor.fromRgbF(.2, .3, .7, .15)
+#NSColor.colorWithCalibratedRed_green_blue_alpha_(.2, .3, .7, .15)
+cellHeaderLineColor = QColor.fromRgb(0, 0, 0).setAlphaF(.2)
+#NSColor.colorWithCalibratedWhite_alpha_(0, .2)
+cellHeaderHighlightLineColor = QColor.fromRgb(25, 25, 25).setAlphaF(.5)
+#NSColor.colorWithCalibratedWhite_alpha_(1, .5)
+cellMetricsLineColor = QColor.fromRgb(0, 0, 0).setAlphaF(.08)
+#NSColor.colorWithCalibratedWhite_alpha_(0, .08)
+cellMetricsFillColor = QColor.fromRgb(0, 0, 0).setAlphaF(.08)
+#NSColor.colorWithCalibratedWhite_alpha_(0, .08)
+
+
+
+def GlyphCellFactory(glyph, font, width, height, drawHeader=False, drawMetrics=False):
+ obj = GlyphCellFactoryDrawingController(glyph=glyph, font=font, width=width, height=height, drawHeader=drawHeader, drawMetrics=drawMetrics)
+ return obj.getImage()
+
+
+class GlyphCellFactoryDrawingController(object):
+
+ """
+ This draws the cell with the layers stacked in this order:
+ ------------------
+ header text
+ ------------------
+ header background
+ ------------------
+ foreground
+ ------------------
+ glyph
+ ------------------
+ vertical metrics
+ ------------------
+ horizontal metrics
+ ------------------
+ background
+ ------------------
+
+ Subclasses may override the layer drawing methods to customize
+ the appearance of cells.
+ """
+
+ def __init__(self, glyph, font, width, height, drawHeader=False, drawMetrics=False):
+ self.glyph = glyph
+ self.font = font
+ self.width = width
+ self.height = height
+ self.bufferPercent = .2
+ self.shouldDrawHeader = drawHeader
+ self.shouldDrawMetrics = drawMetrics
+
+ self.headerHeight = 0
+ if drawHeader:
+ self.headerHeight = GlyphCellHeaderHeight
+ availableHeight = (height - self.headerHeight) * (1.0 - (self.bufferPercent * 2))
+ self.buffer = height * self.bufferPercent
+ self.scale = availableHeight / font.info.unitsPerEm
+ self.xOffset = (width - (glyph.width * self.scale)) / 2
+ self.yOffset = abs(font.info.descender * self.scale) + self.buffer
+
+ def getImage(self):
+ image = QPixmap(self.width, self.height) #NSImage.alloc().initWithSize_((self.width, self.height))
+ painter = QPainter(image).setRenderHint(QPainter.Antialiasing)
+ #image.setFlipped_(True)
+ #image.lockFocus()
+ #context = NSGraphicsContext.currentContext()
+
+ # Below is probably wrong… find out about (x,y) orientation and plane translation that might affect this
+ # Qt is top-left by default while AppKit is bottom-left – Qt translation+scale affects text display
+ bodyRect = QRect(0, self.headerHeight, self.width, self.height-self.headerHeight)
+ headerRect = QRect(0, 0, self.width, self.headerHeight)
+ #bodyRect = ((0, 0), (self.width, self.height-self.headerHeight))
+ #headerRect = ((0, -self.height+self.headerHeight), (self.width, self.headerHeight))
+ # background
+ painter.save()
+ #context.saveGraphicsState()
+ painter.translate(0, self.height-self.headerHeight)
+ painter.scale(1.0, -1.0)
+ #bodyTransform = NSAffineTransform.transform()
+ #bodyTransform.translateXBy_yBy_(0, self.height-self.headerHeight)
+ #bodyTransform.scaleXBy_yBy_(1.0, -1.0)
+ #bodyTransform.concat()
+ self.drawCellBackground(painter, bodyRect)
+ painter.restore()
+ #context.restoreGraphicsState()
+ # glyph
+ if self.shouldDrawMetrics:
+ self.drawCellHorizontalMetrics(painter, bodyRect)
+ self.drawCellVerticalMetrics(painter, bodyRect)
+ #context.saveGraphicsState()
+ painter.save()
+ # clip against background only
+ painter.setClipRect(QRect(0, 0, self.width, self.height-self.headerHeight))
+ #NSBezierPath.clipRect_()
+ painter.translate(self.xOffset, self.yOffset)
+ painter.scale(self.scale, self.scale)
+ #glyphTransform = NSAffineTransform.transform()
+ #glyphTransform.translateXBy_yBy_(self.xOffset, self.yOffset)
+ #glyphTransform.scaleBy_(self.scale)
+ #glyphTransform.concat()
+ self.drawCellGlyph(painter)
+ painter.restore()
+ #context.restoreGraphicsState()
+ # foreground
+ painter.save()
+ #context.saveGraphicsState()
+ #bodyTransform.concat() #why this lonely here?
+ self.drawCellForeground(painter, bodyRect)
+ painter.restore()
+ #context.restoreGraphicsState()
+ # header
+ if self.shouldDrawHeader:
+ painter.save()
+ #context.saveGraphicsState()
+ painter.translate(0, self.headerHeight)
+ painter.scale(1.0, -1.0)
+ #headerTransform = NSAffineTransform.transform()
+ #headerTransform.translateXBy_yBy_(0, self.headerHeight)
+ #headerTransform.scaleXBy_yBy_(1.0, -1.0)
+ #headerTransform.concat()
+ self.drawCellHeaderBackground(painter, headerRect)
+ self.drawCellHeaderText(painter, headerRect)
+ painter.restore()
+ #context.restoreGraphicsState()
+ # done
+ #image.unlockFocus()
+
+ return painter#image
+
+ def drawCellBackground(self, painter, rect):
+ pass
+
+ def drawCellHorizontalMetrics(self, painter, rect):
+ (xMin, yMin, width, height) = rect.getRect()
+ glyph = self.glyph
+ font = self.font
+ scale = self.scale
+ yOffset = self.yOffset
+ path = QPainterPath()
+ #path = NSBezierPath.bezierPath()
+ lines = set((0, font.info.descender, font.info.xHeight, font.info.capHeight, font.info.ascender))
+ for y in lines:
+ y = round((y * scale) + yMin + yOffset) - .5
+ path.moveTo(xMin, y)
+ path.lineTo(xMin + width, y)
+ #cellMetricsLineColor.set()
+ stroke = QPainterPathStroker().createStroke(path)
+ stroke.setWidth(1.0)
+
+ painter.save()
+ painter.setPen(cellMetricsLineColor)
+ painter.drawPath(stroke)
+ painter.restore()
+ #path.stroke()
+
+ def drawCellVerticalMetrics(self, painter, rect):
+ (xMin, yMin, width, height) = rect.getRect()
+ glyph = self.glyph
+ scale = self.scale
+ xOffset = self.xOffset
+ left = round((0 * scale) + xMin + xOffset) - .5
+ right = round((glyph.width * scale) + xMin + xOffset) - .5
+
+ # Does this replicate functionality properly? Need to check that…
+ painter.fillRect((xMin, yMin, left - xMin, height), cellMetricsFillColor)
+ painter.fillRect((xMin + right, yMin, width - xMin + right, height), cellMetricsFillColor)
+ #rects = [
+ # ((xMin, yMin), (left - xMin, height)),
+ # ((xMin + right, yMin), (width - xMin + right, height))
+ #]
+ #cellMetricsFillColor.set()
+ #NSRectFillListUsingOperation(rects, len(rects), NSCompositeSourceOver)
+
+ def drawCellGlyph(self, painter):
+ #NSColor.blackColor().set()
+ painter.fillPath(self.glyph.getRepresentation("defconQt.QPainterPath"), Qt.black)
+
+ def drawCellForeground(self, painter, rect):
+ pass
+
+ def drawCellHeaderBackground(self, painter, rect):
+ (xMin, yMin, width, height) = rect.getRect()
+ # background
+ gradient = QLinearGradient(rect.topLeft(), rect.bottomLeft())
+ gradient.setColorAt(0, cellHeaderHighlightColor)
+ gradient.setColorAt(1, cellHeaderBaseColor)
+ painter.save()
+ painter.rotate(90)
+ painter.fillRect(rect, gradient)
+ painter.restore()
+ #try:
+ # gradient = NSGradient.alloc().initWithColors_([cellHeaderHighlightColor, cellHeaderBaseColor])
+ # gradient.drawInRect_angle_(rect, 90)
+ #except NameError:
+ # cellHeaderBaseColor.set()
+ # NSRectFill(rect)
+ # left and right line
+ sizePath = QPainterPath()
+ sizePath.moveTo(xMin + .5, yMin)
+ sizePath.lineTo(xMin + .5, yMin + height)
+ sizePath.moveTo(xMin + width - 1.5, yMin)
+ sizePath.lineTo(xMin + width - 1.5, yMin + height)
+ sizeStroke = QPainterPathStroker().createStroke(path)
+ sizeStroke.setWidth(1.0)
+ #painter.save()
+ painter.setPen(cellHeaderHighlightLineColor)
+ painter.drawPath(sizeStroke)
+ #painter.restore()
+ #cellHeaderHighlightLineColor.set()
+ #sizePath = NSBezierPath.bezierPath()
+ #sizePath.moveToPoint_((xMin + .5, yMin))
+ #sizePath.lineToPoint_((xMin + .5, yMin + height))
+ #sizePath.moveToPoint_((xMin + width - 1.5, yMin))
+ #sizePath.lineToPoint_((xMin + width - 1.5, yMin + height))
+ #sizePath.setLineWidth_(1.0)
+ #sizePath.stroke()
+ # bottom line
+ bottomPath = QPainterPath()
+ bottomPath.moveTo(xMin, yMin + height - .5)
+ bottomPath.lineTo(xMin + width, yMin + height - .5)
+ #cellHeaderLineColor.set()
+ #bottomPath = NSBezierPath.bezierPath()
+ #bottomPath.moveToPoint_((xMin, yMin + height - .5))
+ #bottomPath.lineToPoint_((xMin + width, yMin + height - .5))
+ #bottomPath.setLineWidth_(1.0)
+ #bottomPath.stroke()
+ bottomStroke = QPainterPathStroker().createStroke(path)
+ bottomStroke.setWidth(1.0)
+ #painter.save()
+ painter.setPen(cellHeaderLineColor)
+ painter.drawPath(bottomStroke)
+ #painter.restore()
+
+ def drawCellHeaderText(self, painter, rect):
+ textColor = QColor.fromRgbF(.22, .22, .27, 1.0)
+ #NSColor.colorWithCalibratedRed_green_blue_alpha_(.22, .22, .27, 1.0)
+
+ # TODO: no shadow for now, need to use QGraphicsDropShadowEffect but tricky to impl
+ #painter.save()
+ painter.setPen(textColor)
+ painter.setFont(QFont(QFont.defaultFamily(), 10))
+ painter.drawText(rect, Qt.AlignCenter, self.glyph.name);
+ #painter.restore()
+
+ #paragraph = NSMutableParagraphStyle.alloc().init()
+ #paragraph.setAlignment_(NSCenterTextAlignment)
+ #paragraph.setLineBreakMode_(NSLineBreakByTruncatingMiddle)
+ #shadow = NSShadow.alloc().init()
+ #shadow.setShadowColor_(NSColor.whiteColor())
+ #shadow.setShadowOffset_((0, 1))
+ #shadow.setShadowBlurRadius_(1)
+ #attributes = {
+ # NSFontAttributeName : NSFont.systemFontOfSize_(10.0),
+ # NSForegroundColorAttributeName : NSColor.colorWithCalibratedRed_green_blue_alpha_(.22, .22, .27, 1.0),
+ # NSParagraphStyleAttributeName : paragraph,
+ # NSShadowAttributeName : shadow
+ #}
+ #text = NSAttributedString.alloc().initWithString_attributes_(self.glyph.name, attributes)
+ #text.drawInRect_(rect)
diff --git a/Lib/defconQt/representationFactories/qPainterPathFactory.py b/Lib/defconQt/representationFactories/qPainterPathFactory.py
new file mode 100644
index 0000000..cf28eb5
--- /dev/null
+++ b/Lib/defconQt/representationFactories/qPainterPathFactory.py
@@ -0,0 +1,6 @@
+from fontTools.pens.qtPen import QtPen
+
+def QPainterPathFactory(glyph, font):
+ pen = QtPen(font)
+ glyph.draw(pen)
+ return pen.path \ No newline at end of file
diff --git a/Lib/defconQt/test.py b/Lib/defconQt/test.py
new file mode 100644
index 0000000..47a119d
--- /dev/null
+++ b/Lib/defconQt/test.py
@@ -0,0 +1,19 @@
+from controls.glyphCellView_ex import Window
+import representationFactories
+from PyQt5.QtWidgets import QApplication
+
+if __name__ == '__main__':
+ import sys
+ from defcon import Font
+ path = "C:\\Veloce.ufo"
+ font = Font(path)
+ #glyph = font[b"a"]
+ app = QApplication(sys.argv)
+ window = Window()
+ #window.setGlyphs_(glyph)
+ representationFactories.registerAllFactories()
+ #window.setGlyph(font, "a")
+ window.glyphsGrid[0].drawGlyphCell("a", font)
+ #window.glyphsGrid.setShape(glyph.getRepresentation("defconQt.QPainterPath"))
+ window.show()
+ sys.exit(app.exec_()) \ No newline at end of file
diff --git a/Lib/defconQt/windows/__init__.py b/Lib/defconQt/windows/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Lib/defconQt/windows/__init__.py
diff --git a/Lib/defconQt/windows/__pycache__/baseWindow.cpython-34.pyc b/Lib/defconQt/windows/__pycache__/baseWindow.cpython-34.pyc
new file mode 100644
index 0000000..9814c61
--- /dev/null
+++ b/Lib/defconQt/windows/__pycache__/baseWindow.cpython-34.pyc
Binary files differ
diff --git a/Lib/defconQt/windows/__pycache__/progressWindow.cpython-34.pyc b/Lib/defconQt/windows/__pycache__/progressWindow.cpython-34.pyc
new file mode 100644
index 0000000..ead3ca4
--- /dev/null
+++ b/Lib/defconQt/windows/__pycache__/progressWindow.cpython-34.pyc
Binary files differ
diff --git a/Lib/defconQt/windows/baseWindow.py b/Lib/defconQt/windows/baseWindow.py
new file mode 100644
index 0000000..2fc2b13
--- /dev/null
+++ b/Lib/defconQt/windows/baseWindow.py
@@ -0,0 +1,101 @@
+from PyQt5.QtCore import QDir
+from PyQt5.QtWidgets import (QFileDialog, QMessageBox)
+
+'''
+Base Window is a rather abstract object containing the common methods of
+all widgets.
+As such, it does not have an init function and is meant to be inherited
+by subsequent classes.
+'''
+class BaseWindowController(object):
+
+ '''
+ def setUpBaseWindowBehavior(self):
+ self.w.bind("close", self.windowCloseCallback)
+ if isinstance(self.w, vanilla.Sheet):
+ self.w.bind("became key", self.windowSelectCallback)
+ self.w.bind("resigned key", self.windowDeselectCallback)
+ else:
+ self.w.bind("became main", self.windowSelectCallback)
+ self.w.bind("resigned main", self.windowDeselectCallback)
+
+ def windowCloseCallback(self, sender):
+ self.w.unbind("close", self.windowCloseCallback)
+ if isinstance(self.w, vanilla.Sheet):
+ self.w.unbind("became key", self.windowSelectCallback)
+ self.w.unbind("resigned key", self.windowDeselectCallback)
+ else:
+ self.w.unbind("became main", self.windowSelectCallback)
+ self.w.unbind("resigned main", self.windowDeselectCallback)
+
+ def windowSelectCallback(self, sender):
+ pass
+
+ def windowDeselectCallback(self, sender):
+ pass
+ '''
+
+ def startProgress(self, text="", tickCount=None):
+ try:
+ from defconQt.windows.progressWindow import ProgressWindow
+ except:
+ from progressWindow import ProgressWindow
+ return ProgressWindow(text, tickCount, self.w)
+
+ def showMessage(self, messageText, informativeText, callback=None):
+ QMessageBox.information(self.w.activeWindow(), messageText, informativeText)
+ #if callback is None:
+ # return 1
+ #vanilla.dialogs.message(parentWindow=self.w.getNSWindow(), messageText=messageText, informativeText=informativeText, resultCallback=callback)
+
+ def showAskYesNo(self, messageText, informativeText, callback=None):#
+ result = QMessageBox.question(self.w.activeWindow(), messageText, informativeText, QMessageBox.Yes | QMessageBox.No)
+ #vanilla.dialogs.askYesNo(parentWindow=self.w.getNSWindow(), messageText=messageText, informativeText=informativeText, resultCallback=callback)
+ if callback is None:
+ if result == QMessageBox.Yes:
+ return 1
+ else:
+ return 0
+ # return alert._value
+
+ def showGetFolder(self, callback=None):#
+ directory = QFileDialog.getExistingDirectory(parent=self.w.activeWindow(), directory=QDir.currentPath())
+ if callback is None:
+ return directory
+ #vanilla.dialogs.getFolder(parentWindow=self.w.getNSWindow(), resultCallback=callback)
+
+ def showGetFile(self, fileTypes, callback, allowsMultipleSelection=False):
+ # TODO: Mac OS sees UFO as file, make sure that this accepts it eveywhere
+ # Note: fileTypes must follow QT convention e.g. "All Files (*);;Text Files (*.txt)"
+ # Note#2: getOpenFileNames may pack in an array while getOpenFileName does not
+ if allowsMultipleSelection: # why would you do this in a Font Editor?
+ files = QFileDialog.getOpenFileNames(parent=self.w.activeWindow(), directory=QDir.currentPath(), filter=fileTypes)
+ else:
+ files = QFileDialog.getOpenFileName(parent=self.w.activeWindow(), directory=QDir.currentPath(), filter=fileTypes)
+ #vanilla.dialogs.getFile(fileTypes=fileTypes, allowsMultipleSelection=allowsMultipleSelection,
+ # parentWindow=self.w.getNSWindow(), resultCallback=callback)
+
+ def showPutFile(self, fileTypes, callback=None, fileName=None, directory=None, accessoryView=None):#
+ # ! fileTypes
+
+ # basic instance cannot put a default file name, use the base class
+ #result = QFileDialog.getSaveFileName(parent=self.w, directory=directory, filter=fileTypes)
+ # https://github.com/qtproject/qt/blob/98530cbc3a0bbb633bab96eebb535d7f92ecb1fa/src/gui/dialogs/qfiledialog.cpp#L1965
+ dlg = QFileDialog(parent=self.w.activeWindow(), filter=fileTypes)
+ dlg.setFileMode(QFileDialog.AnyFile)
+ dlg.setAcceptMode(QFileDialog.AcceptSave)
+ if directory: dlg.setDirectory(directory)
+ if fileName: dlg.selectFile(fileName)
+ if (dlg.exec_() == QDialog.Accepted):
+ result = dialog.selectedFiles().value(0)
+ if callback is None:
+ return result
+ '''
+ if accessoryView is not None:
+ w, h = accessoryView._posSize[2:]
+ accessoryView._nsObject.setFrame_(((0, 0), (w, h)))
+ accessoryView = accessoryView._nsObject
+ vanilla.dialogs.putFile(fileTypes=fileTypes,
+ parentWindow=self.w.getNSWindow(), resultCallback=callback, fileName=fileName, directory=directory, accessoryView=accessoryView)
+ '''
+
diff --git a/Lib/defconQt/windows/progressWindow.py b/Lib/defconQt/windows/progressWindow.py
new file mode 100644
index 0000000..d64e5c7
--- /dev/null
+++ b/Lib/defconQt/windows/progressWindow.py
@@ -0,0 +1,50 @@
+#import vanilla
+try:
+ from defconQt.windows.baseWindow import BaseWindowController
+except:
+ from baseWindow import BaseWindowController
+from PyQt5.QtWidgets import QProgressDialog
+
+class ProgressWindow(BaseWindowController):
+
+ def __init__(self, text="", maximum=0, parentWindow=None):
+ self.w = parentWindow
+ if parentWindow is None:
+ raise NotImplementedError
+# self.w = vanilla.Window((250, 60), closable=False, miniaturizable=False, textured=False)
+# else:
+# self.w = vanilla.Sheet((250, 60), parentWindow)
+ # have it uncancelable for now at least
+ #self.w.progress = QProgressDialog(cancelButtonText="0", parent=parentWindow, labelText=text, maximum=maximum)
+ self.w.progress = QProgressDialog(parent=parentWindow, labelText=text, maximum=maximum)
+# self.w.progress.setWindowModality(Qt::WindowModal)
+# self.w.progress = vanilla.ProgressBar((15, 15, -15, 12), maxValue=tickCount, isIndeterminate=isIndeterminate, sizeStyle="small")
+# self.w.text = vanilla.TextBox((15, 32, -15, 14), text, sizeStyle="small")
+# self.w.progress.start()
+# self.w.center()
+# self.setUpBaseWindowBehavior()
+# self.w.open()
+ self.w.progress.open()
+
+ def close(self):
+ self.progress.cancel()
+# self.w.close()
+
+ def update(self, text=None):
+# self.w.progress.increment()
+ cur = self.progress.value()
+ self.progress.setValue(cur+1)
+ if text is not None:
+ self.setLabelText(text)
+# self.w.text._nsObject.display()
+
+ def setTickCount(self, value=0):
+# bar = self.w.progress.getNSProgressIndicator()
+# if value is None:
+# bar.setIndeterminate_(True)
+# self.w.progress.start()
+# else:
+# bar.setIndeterminate_(False)
+# bar.setDoubleValue_(0)
+# bar.setMaxValue_(value)
+ self.progress.setRange(0, value) \ No newline at end of file
diff --git a/Lib/defconQt/windows/test.py b/Lib/defconQt/windows/test.py
new file mode 100644
index 0000000..e9be55c
--- /dev/null
+++ b/Lib/defconQt/windows/test.py
@@ -0,0 +1,45 @@
+from PyQt5.QtCore import *
+from PyQt5.QtWidgets import *
+
+class Form(QWidget):
+ def __init__(self, parent=None):
+ super(Form, self).__init__(parent)
+
+ nameLabel = QLabel("Name:")
+ self.nameLine = QLineEdit()
+ self.submitButton = QPushButton("&amp;Submit")
+
+ buttonLayout1 = QVBoxLayout()
+ buttonLayout1.addWidget(nameLabel)
+ buttonLayout1.addWidget(self.nameLine)
+ buttonLayout1.addWidget(self.submitButton)
+
+ self.submitButton.clicked.connect(self.submitContact)
+
+ mainLayout = QGridLayout()
+ # mainLayout.addWidget(nameLabel, 0, 0)
+ mainLayout.addLayout(buttonLayout1, 0, 1)
+
+ self.setLayout(mainLayout)
+ self.setWindowTitle("Hello Qt")
+
+ def submitContact(self):
+ name = self.nameLine.text()
+
+ if name == "":
+ QMessageBox.information(self, "Empty Field",
+ "Please enter a name and address.")
+ return
+ else:
+ QMessageBox.information(self, "Success!",
+ "Hello %s!" % name)
+
+if __name__ == '__main__':
+ import sys
+
+ app = QApplication(sys.argv)
+
+ screen = Form()
+ screen.show()
+
+ sys.exit(app.exec_()) \ No newline at end of file
diff --git a/Lib/defconQt/windows/test2.py b/Lib/defconQt/windows/test2.py
new file mode 100644
index 0000000..65dc71f
--- /dev/null
+++ b/Lib/defconQt/windows/test2.py
@@ -0,0 +1,13 @@
+from PyQt5.QtCore import *
+from PyQt5.QtWidgets import *
+from progressWindow import *
+
+if __name__ == '__main__':
+ import sys
+
+ app = QApplication(sys.argv)
+
+ screen = ProgressWindow(text="Hello World!", maximum=0, parentWindow=app)
+# screen.show()
+
+ sys.exit(app.exec_()) \ No newline at end of file
diff --git a/Lib/defconQt/windows/test3.py b/Lib/defconQt/windows/test3.py
new file mode 100644
index 0000000..9401c96
--- /dev/null
+++ b/Lib/defconQt/windows/test3.py
@@ -0,0 +1,15 @@
+from PyQt5.QtCore import *
+from PyQt5.QtWidgets import *
+from progressWindow import *
+
+if __name__ == '__main__':
+ import sys
+
+ app = QApplication(sys.argv)
+
+ screen = BaseWindowController()
+ screen.w = None
+ screen.startProgress("Hello World!", 5)
+# screen.show()
+
+ sys.exit(app.exec_()) \ No newline at end of file