From 0f5a46ce6f6d5bb49befc5d2d8f2bb3b2d68890a Mon Sep 17 00:00:00 2001 From: Andrey Golovizin Date: Fri, 19 Sep 2014 23:56:12 +0200 Subject: [PATCH] Use proper font in GlyphEdit. --- pixelocr/gui/glyphedit.py | 34 +++++++++++++++++++++++++++++++--- pixelocr/page.py | 5 +++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/pixelocr/gui/glyphedit.py b/pixelocr/gui/glyphedit.py index e857a8c..fc86d9a 100644 --- a/pixelocr/gui/glyphedit.py +++ b/pixelocr/gui/glyphedit.py @@ -20,8 +20,10 @@ from PyQt4.QtCore import ( ) from PyQt4.QtGui import ( + QFont, QHBoxLayout, QLineEdit, + QPalette, QToolButton, QWidget, ) @@ -44,24 +46,34 @@ class GlyphEdit(QWidget): def __init__(self, parent, document): super().__init__(parent) self.document = document + config = document.config self.layout = QHBoxLayout(self) self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) + self.text = QLineEdit(self) + self.text.returnPressed.connect(self.sendGlyph) + + font = QFont() + if config.glyph_font_family: + font.setFamily(config.glyph_font_family) + if config.glyph_font_size: + font.setPixelSize(config.glyph_font_size) + self.text.setFont(font) + self.bold = StyleButton(self) self.bold.setText('B') self.bold.setShortcut('Ctrl+b') + self.bold.toggled.connect(self.setBold) self.italic = StyleButton(self) self.italic.setText('I') self.italic.setShortcut('Ctrl+i') + self.italic.toggled.connect(self.setItalic) self.setAllowBoldItalic(self.document.config.allow_bold_italic) - self.text = QLineEdit(self) - self.text.returnPressed.connect(self.sendGlyph) - self.layout.addWidget(self.bold) self.layout.addWidget(self.italic) self.layout.addWidget(self.text) @@ -69,6 +81,7 @@ class GlyphEdit(QWidget): def requestGlyph(self, glyph, bold, italic): self.bold.setChecked(bold) self.italic.setChecked(italic) + self.setColor(glyph.qcolor) self.setEnabled(True) self.text.clear() self.text.setFocus() @@ -76,6 +89,21 @@ class GlyphEdit(QWidget): def sendGlyph(self): self.glyphEntered.emit(self.text.text(), self.bold.isChecked(), self.italic.isChecked()) + def setBold(self, enable): + font = self.text.font() + font.setBold(enable) + self.text.setFont(font) + + def setItalic(self, enable): + font = self.text.font() + font.setItalic(enable) + self.text.setFont(font) + + def setColor(self, color): + palette = self.text.palette() + palette.setColor(QPalette.Text, color) + self.text.setPalette(palette) + def setAllowBoldItalic(self, allow=True): if not allow and self.allowBoldItalic: self.italic.pressed.connect(self.bold.release) diff --git a/pixelocr/page.py b/pixelocr/page.py index e34fa5b..1c4f33f 100644 --- a/pixelocr/page.py +++ b/pixelocr/page.py @@ -86,6 +86,11 @@ class PageObject(object): def color(self): return self.image.color + @property + def qcolor(self): + from PyQt4.QtGui import QColor + return QColor(*self.color) + def fits(self, left, top, right, bottom): """Return True if the glyph fits into the given bounding box."""