aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-11-24 17:40:25 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-11-24 17:40:25 -0300
commited6e4c1eba0baf55e336d740363953cfd27afb60 (patch)
treeb49309118cb417336e1f9baf8a6cee0a545b936d /examples
parent422dcb5c636779a36ff156571175b5d07598ea74 (diff)
Fixed charactermap example.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/widgets/charactermap.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/examples/widgets/charactermap.py b/examples/widgets/charactermap.py
index 2a19ef1..04f547e 100755
--- a/examples/widgets/charactermap.py
+++ b/examples/widgets/charactermap.py
@@ -71,20 +71,24 @@ class CharacterWidget(QtGui.QWidget):
widgetPosition = self.mapFromGlobal(event.globalPos())
key = (widgetPosition.y() / self.squareSize) * self.columns + widgetPosition.x() / self.squareSize
- text = "<p>Character: <span style=\"font-size: 24pt; font-family: %s\">" % (self.displayFont.family()) + \
- chr(key) + \
- "</span><p>Value: 0x" + \
- chr(key)
+ if 0 < key < 128:
+ ch = chr(key)
+ else:
+ ch = ' '
+ text = '<p>Character: <span style="font-size: 24pt; font-family: %s">%s</span><p>Value: %s' % \
+ (self.displayFont.family(), ch, hex(key))
QtGui.QToolTip.showText(event.globalPos(), text, self)
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self.lastKey = (event.y() / self.squareSize) * self.columns + event.x() / self.squareSize
- try:
- c = chr(self.lastKey)
- self.characterSelected.emit(c)
- except:
- pass
+ c = chr(self.lastKey)
+ self.characterSelected.emit(c)
+ #try:
+ #c = chr(self.lastKey)
+ #self.characterSelected.emit(c)
+ #except:
+ #pass
self.update()
else:
super(CharacterWidget, self).mousePressEvent(event)
@@ -121,9 +125,13 @@ class CharacterWidget(QtGui.QWidget):
row * self.squareSize + 1, self.squareSize,
self.squareSize, QtCore.Qt.red)
- painter.drawText(column * self.squareSize + (self.squareSize / 2) - fontMetrics.width(chr(key)) / 2,
- row * self.squareSize + 4 + fontMetrics.ascent(),
- chr(key))
+ if 0 < key < 256:
+ ch = chr(key)
+ else:
+ ch = ' '
+ x = column * self.squareSize + (self.squareSize / 2) - fontMetrics.width(ch) / 2
+ y = row * self.squareSize + 4 + fontMetrics.ascent()
+ painter.drawText(x, y, ch)
class MainWindow(QtGui.QMainWindow):