{"id":419,"date":"2014-08-10T00:32:42","date_gmt":"2014-08-09T15:32:42","guid":{"rendered":"http:\/\/www.typea.info\/blog\/index.php\/2014\/08\/10\/pyqt\/"},"modified":"2014-08-10T00:32:42","modified_gmt":"2014-08-09T15:32:42","slug":"pyqt","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2014\/08\/10\/pyqt\/","title":{"rendered":"PyQt\u3067\u6587\u5b57\u6570\u8a08\u6e2c\u30c4\u30fc\u30eb\u3064\u304f\u308b\u3002\u7c21\u5358\u3059\u304e\u3002"},"content":{"rendered":"<p><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/08\/05\/python_gui_pyqt\">PyQt\u3092\u77e5\u3063\u3066\u3055\u308f\u308a\u59cb\u3081\u305f\u306e\u3060\u304c\u3001\u4fbf\u5229\u3059\u304e\u308b\u3002<\/a><\/p>\n<p>\u3061\u3087\u3063\u3068\u3057\u305f\u30c4\u30fc\u30eb\u3065\u304f\u308a\u306b\u6700\u9069\u3002<\/p>\n<p>&#160;<\/p>\n<p>\u81ea\u5206\u306e\u4e3b\u306a\u4ed5\u4e8b\u306f\u696d\u52d9\u30a2\u30d7\u30ea\u3065\u304f\u308a\u306a\u306e\u3060\u304c\u3001\u958b\u767a\u306e\u306a\u304b\u3067\u3061\u3087\u3063\u3068\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u5fc5\u8981\u306a\u6642\u306f\u3001\u3060\u3044\u305f\u3044Python\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u66f8\u3044\u3066\u3044\u308b\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u51e6\u7406\u3057\u3066\u3001\u4f55\u3089\u304b\u306e\u7d50\u679c\u3092CSV\u306b\u62bd\u51fa\u3059\u308b\u3068\u304b\u306d\u3002<\/p>\n<p>\u305d\u3093\u306a\u3093\u306f\u3001\u3042\u307e\u308a\u4f5c\u308a\u8fbc\u3080\u6642\u9593\u3092\u304b\u3051\u3089\u308c\u308b\u305f\u3050\u3044\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306f\u306a\u3044\u306e\u3067\u3001\u4e0b\u624b\u3059\u308b\u3068(\u3044\u3064\u3082\u306f)\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u5185\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u90e8\u5206\u3092\u66f8\u304d\u63db\u3048\u3066\u30b9\u30af\u30ea\u30d7\u30c8\u8d70\u3089\u305b\u308b\u30b1\u30fc\u30b9\u304c\u5927\u534a\u3060\u3063\u305f\u3002<\/p>\n<p>&#160;<\/p>\n<p>\u3057\u304b\u3057\u3057\u304b\u3057\u3001\u3053\u308c\u3092\u4f7f\u3048\u3070\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u90e8\u5206\u3092\u5bfe\u8a71\u7684\u306b\u8a2d\u5b9a\u3055\u305b\u3066\u3001\u6c4e\u7528\u7684(\u81ea\u5206\u4ee5\u5916\u304c\u4f7f\u3048\u308b\u30c4\u30fc\u30eb)\u306b\u3059\u308b\u30cf\u30fc\u30c9\u30eb\u304c\u304b\u306a\u308a\u4e0b\u304c\u308b\u3062\u3083\u306a\u3044\u304b\uff01\uff01<\/p>\n<p>\u8fd4\u3059\u8fd4\u3059\u3082\u3063\u3068\u65e9\u304f\u304b\u3089\u8a66\u3057\u3066\u304a\u3051\u3070\u3088\u304b\u3063\u305f\uff01<\/p>\n<p>&#160;<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u3061\u3087\u3063\u3068\u5fc5\u8981\u306a\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u3092\u3001\u7c21\u6613(\u5b89\u6613)\u306b\u4f5c\u6210\u3057\u3066\u307f\u308b\u3002<\/p>\n<p>&#160;<\/p>\n<p>\u30c6\u30ad\u30b9\u30c8\u306e\u6587\u5b57\u6570\u3068\u30a8\u30f3\u30b3\u30fc\u30c9\u5225\u306e\u30d0\u30a4\u30c8\u6570\u3092\u8a08\u6e2c\u3059\u308b\u30c4\u30fc\u30eb\u3002<\/p>\n<p>\u3061\u3083\u3093\u3068\u3057\u305fGUI\u304c\u3001HTML\u66f8\u304f\u3088\u308a\u7c21\u5358\u306b\u5b9f\u88c5\u3067\u304d\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2ea824d03c93_345\/pyqt_char_counter.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"pyqt_char_counter\" style=\"border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px\" border=\"0\" alt=\"pyqt_char_counter\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/2ea824d03c93_345\/pyqt_char_counter_thumb.jpg\" width=\"260\" height=\"317\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p>\u3053\u308c\u306f\u4f7f\u3048\u3059\u304e\u308b\u3002\u5f90\u3005\u306b\u5e45\u3092\u5e83\u3052\u3066\u3044\u3053\u3046\u3002<\/p>\n<pre class=\"prettyprint linenums\"># -*- coding:utf-8 -*-\r\n\r\nimport sys\r\nimport math\r\nfrom PyQt4 import QtGui as gui\r\nfrom PyQt4 import QtCore as qt\r\n\r\nclass Hoge(gui.QWidget):\r\n    def __init__(self):\r\n        super(Hoge, self).__init__()\r\n        self.initUi()\r\n\r\n    def initUi(self):\r\n        grid = gui.QGridLayout()\r\n        self.setLayout(grid)\r\n\r\n        form = gui.QFormLayout()\r\n        grid.addLayout(form,1,0)\r\n\r\n        self.cmbCharCd = gui.QComboBox()\r\n        self.cmbCharCd.addItems(('utf-8','shift-jis','euc-jp','utf-16'))\r\n        form.addRow(u&quot;\u6587\u5b57\u30b3\u30fc\u30c9&quot;, self.cmbCharCd)\r\n\r\n        boxCtrl = gui.QHBoxLayout()\r\n        self.chkFullByte = gui.QCheckBox(u&quot;\u8a73\u7d30(Byte)&quot;)\r\n        self.chkFullByte.setCheckState(qt.Qt.Unchecked)\r\n        boxCtrl.addWidget(self.chkFullByte)\r\n\r\n        self.chkCountWs = gui.QCheckBox(u&quot;\u7a7a\u767d\u8a08\u6e2c&quot;)\r\n        self.chkCountWs.setCheckState(qt.Qt.Checked)\r\n        boxCtrl.addWidget(self.chkCountWs)\r\n\r\n        self.btnConv = gui.QPushButton(u&quot;\u8a08\u6e2c&quot;)\r\n        self.btnConv.clicked.connect(self.doCount)\r\n        boxCtrl.addWidget(self.btnConv)\r\n\r\n        form.addRow(boxCtrl)\r\n\r\n        self.txtChCnt = gui.QLineEdit()\r\n        self.txtChCnt.setAlignment(qt.Qt.AlignRight)\r\n        self.txtByteCnt = gui.QLineEdit()\r\n        self.txtByteCnt.setAlignment(qt.Qt.AlignRight)\r\n\r\n        form.addRow(u&quot;\u6587\u5b57\u6570&quot;, self.txtChCnt)\r\n        form.addRow(u&quot;\u30d0\u30a4\u30c8\u6570&quot;, self.txtByteCnt)\r\n\r\n        boxBtn = gui.QHBoxLayout()\r\n        grid.addLayout(boxBtn,2,0)\r\n\r\n        self.txtSource = gui.QTextEdit()\r\n        grid.addWidget(self.txtSource, 3, 0)\r\n\r\n        self.setWindowTitle('CharCounter')\r\n        self.show()\r\n\r\n    def doCount(self):\r\n\r\n        uc_text = unicode(self.txtSource.toPlainText())\r\n        encoding = unicode(self.cmbCharCd.currentText())\r\n\r\n        is_omit_byte = not self.chkFullByte.isChecked()\r\n        is_ignore_ws = not self.chkCountWs.isChecked()\r\n\r\n        ch_cnt = 0\r\n        byte_len = 0\r\n        for uc_char in uc_text:\r\n\r\n            if is_ignore_ws and uc_char.isspace():\r\n                continue\r\n\r\n            byte_len = byte_len + len(bytearray(uc_char, encoding))\r\n            ch_cnt = ch_cnt + 1\r\n\r\n        self.txtChCnt.setText(&quot;{:,}&quot;.format(ch_cnt))\r\n        self.txtByteCnt.setText(self.formatByte(byte_len, is_omit_byte))\r\n\r\n    def formatByte(self, byte_len, is_omit_byte):\r\n        SI_KILO = 1024.0\r\n        SI_PREFIX = ('','KB','MB','GB','TB')\r\n\r\n        if is_omit_byte:\r\n            lc = math.log(byte_len, SI_KILO)\r\n            byte_omit_len = byte_len\r\n\r\n            byte_omit_len = byte_omit_len \/ math.pow(SI_KILO,int(lc))\r\n\r\n            print unicode(byte_omit_len)\r\n            return &quot;{:.1f}&quot;.format(byte_omit_len) + SI_PREFIX[int(lc)]\r\n        else:\r\n            return &quot;{:,}&quot;.format(byte_len)\r\n\r\ndef main():\r\n    app = gui.QApplication(sys.argv)\r\n    hoge = Hoge()\r\n    sys.exit(app.exec_())\r\n\r\nif __name__ == '__main__':\r\n    main()<\/pre>\n<p><iframe style=\"height: 240px; width: 120px\" marginheight=\"0\" src=\"http:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?lt1=_blank&amp;bc1=FFFFFF&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=typea09-22&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=ss_til&amp;asins=4777516504\" frameborder=\"0\" marginwidth=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PyQt\u3092\u77e5\u3063\u3066\u3055\u308f\u308a\u59cb\u3081\u305f\u306e\u3060\u304c\u3001\u4fbf\u5229\u3059\u304e\u308b\u3002 \u3061\u3087\u3063\u3068\u3057\u305f\u30c4\u30fc\u30eb\u3065\u304f\u308a\u306b\u6700\u9069\u3002 &#160; \u81ea\u5206\u306e\u4e3b\u306a\u4ed5\u4e8b\u306f\u696d\u52d9\u30a2\u30d7\u30ea\u3065\u304f\u308a\u306a\u306e\u3060\u304c\u3001\u958b\u767a\u306e\u306a\u304b\u3067\u3061\u3087\u3063\u3068\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u5fc5\u8981\u306a\u6642\u306f\u3001\u3060\u3044\u305f\u3044Python\u3067\u30b9\u30af\u30ea\u30d7\u30c8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[76,20],"tags":[],"class_list":["post-419","post","type-post","status-publish","format-standard","hentry","category-pyqt","category-python"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=419"}],"version-history":[{"count":0,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/419\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}