Commits

Yuya Nishihara  committed 2c6c0ce

pyqt: add experiment why Japanese kome gets invisible

  • Participants
  • Parent commits 9e15713

Comments (0)

Files changed (1)

File pyqt/qtextedit-kome.py

+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+import sys
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+from __builtin__ import hex
+
+asciiart = r"""
+<div style="white-space: pre;">
++------------------+
+|                  |
++------------------+
+</div>
+"""
+
+def main():
+    app = QApplication(sys.argv)
+    '''
+    w = QLabel(u'Quick fox ※ 飛んでった')
+    courier = QFont('Courier')
+    w.setFont(courier)
+    w.show()
+
+    print 'font:', courier.family()
+    print 'in font:', QFontMetrics(courier).inFontUcs4(ord(u'飛'))
+    sys.stdout.flush()
+
+    return app.exec_()
+
+    '''
+    w = QTextEdit()
+    w.show()
+    #w.setHtml(u'<pre style="font-family: MS UIGothic,courier;">※</pre>')
+    w.setFont(QFont('Comic Sans MS', 10))
+    w.setHtml(asciiart)
+    #c = QTextCursor(w.document())
+    #c.beginEditBlock()
+    #f = QTextCharFormat()
+    #f.setFontFixedPitch(True)
+    #c.mergeBlockCharFormat(f)
+    #c.endEditBlock()
+
+    def examine():
+        doc = w.document()
+        preblock = doc.firstBlock()
+        fmt = preblock.charFormat()
+        print 'fixed pitch:', fmt.fontFixedPitch()
+        print 'font family:', fmt.fontFamily()
+        #print 'font default family:', font.defaultFamily()
+        sys.stdout.flush()
+
+    QTimer.singleShot(0, examine)
+    return app.exec_()
+
+if __name__ == '__main__':
+    sys.exit(main())