{"id":444,"date":"2015-02-08T09:29:06","date_gmt":"2015-02-08T00:29:06","guid":{"rendered":"http:\/\/www.typea.info\/blog\/index.php\/2015\/02\/08\/pyqt_guipython\/"},"modified":"2015-02-08T09:29:06","modified_gmt":"2015-02-08T00:29:06","slug":"pyqt_guipython","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2015\/02\/08\/pyqt_guipython\/","title":{"rendered":"PyQt \u3092\u4f7f\u3063\u3066 GUI\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u5206\u5272\u30c4\u30fc\u30eb\u3092Python\u3067\u4f5c\u6210\u3059\u308b"},"content":{"rendered":"<p>PyQt\u3092\u4f7f\u3046\u3068\u3001Python\u3067\u4f5c\u6210\u3057\u305f\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u3001\u3072\u3068\u624b\u9593\u52a0\u3048\u308b\u3060\u3051\u3067\u3001GUI\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f5c\u6210\u3067\u304d\u3066\u975e\u5e38\u306b\u4fbf\u5229\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/6d7f1df55176_7E0A\/text_spliter.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"text_spliter\" 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=\"text_spliter\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/6d7f1df55176_7E0A\/text_spliter_thumb.jpg\" width=\"396\" height=\"177\"><\/a><\/p>\n<p>\u3053\u3093\u306a\u7a0b\u5ea6\u306a\u3089\u3001\u3061\u3087\u3044\u3061\u3087\u3044\u3063\u3068\u3001\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u3092\u8abf\u3079\u306a\u304c\u3089\u3001\u30ce\u30ea\u3067\u4f5c\u6210\u3067\u304d\u308b\u624b\u8efd\u3055\u3082\u3088\u3044\u3002<\/p>\n<p><a title=\"http:\/\/pyqt.sourceforge.net\/Docs\/PyQt4\/classes.html\" href=\"http:\/\/pyqt.sourceforge.net\/Docs\/PyQt4\/classes.html\">http:\/\/pyqt.sourceforge.net\/Docs\/PyQt4\/classes.html<\/a><\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/6d7f1df55176_7E0A\/pyqt_cls_reference.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"pyqt_cls_reference\" 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_cls_reference\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/6d7f1df55176_7E0A\/pyqt_cls_reference_thumb.jpg\" width=\"517\" height=\"194\"><\/a><\/p>\n<p>\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u30da\u30fc\u30b8\u3082\u3001\u898b\u3084\u3059\u3044(\u691c\u7d22\u3057\u3084\u3059\u3044)\u306e\u3067\u3001\u3060\u3044\u305f\u3044\u3001\u305d\u308c\u3063\u307d\u3044\u30ad\u30fc\u30ef\u30fc\u30c9\u3067\u691c\u7d22\u3059\u308b\u3068\u305d\u308c\u3063\u307d\u3044\u30af\u30e9\u30b9\u304c\u5f15\u3063\u639b\u304b\u308b\u3002<\/p>\n<pre class=\"prettyprint linenums\">self.txtLimit.setAlignment(core.Qt.AlignRight)<\/pre>\n<p>\u4e0a\u8a18(\u30c6\u30ad\u30b9\u30c8\u306e\u30a2\u30e9\u30a4\u30e1\u30f3\u30c8\u3092\u53f3\u5bc4\u305b\u6307\u5b9a)\u306e\u3088\u3046\u306b\u3001\u30e1\u30bd\u30c3\u30c9\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u6e21\u3059\u5217\u6319\u578b\u306a\u3069\u306f\u3001QtCore\u30e2\u30b8\u30e5\u30fc\u30eb\u306eQt \u30af\u30e9\u30b9\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n<p><strong>\u30e2\u30b8\u30e5\u30fc\u30eb\u4e00\u89a7<\/strong><\/p>\n<p><a title=\"http:\/\/pyqt.sourceforge.net\/Docs\/PyQt4\/modules.html\" href=\"http:\/\/pyqt.sourceforge.net\/Docs\/PyQt4\/modules.html\">http:\/\/pyqt.sourceforge.net\/Docs\/PyQt4\/modules.html<\/a><\/p>\n<p><strong>Qt\u30af\u30e9\u30b9<\/strong><\/p>\n<p><a title=\"http:\/\/pyqt.sourceforge.net\/Docs\/PyQt4\/qt.html\" href=\"http:\/\/pyqt.sourceforge.net\/Docs\/PyQt4\/qt.html\">http:\/\/pyqt.sourceforge.net\/Docs\/PyQt4\/qt.html<\/a><\/p>\n<p><strong>\u30b3\u30fc\u30c9<\/strong><\/p>\n<pre class=\"prettyprint linenums\"># -*- encoding:utf-8 -*-\r\nimport sys\r\nimport re\r\nimport os\r\nfrom datetime import datetime\r\nfrom PyQt4 import QtGui as gui\r\nfrom PyQt4 import QtCore as core\r\nimport re\r\nimport codecs\r\n \r\nclass MainWindow(gui.QWidget):\r\n    def __init__(self):\r\n        super(MainWindow, self).__init__()\r\n        self.initUi()\r\n \r\n    def initUi(self):\r\n        grid = gui.QGridLayout()\r\n \r\n        form = gui.QFormLayout()\r\n        self.txtSepFile = gui.QLineEdit()\r\n        btnSepFile = gui.QPushButton(u'...')\r\n        btnSepFile.setMaximumWidth(40)\r\n        btnSepFile.clicked.connect(self.chooseDbFile)\r\n        boxSepFile = gui.QHBoxLayout()\r\n        boxSepFile.addWidget(self.txtSepFile)\r\n        boxSepFile.addWidget(btnSepFile)\r\n        form.addRow(u'\u5bfe\u8c61\u30d5\u30a1\u30a4\u30eb', boxSepFile)\r\n \r\n        self.txtLimit = gui.QLineEdit()\r\n        self.txtLimit.setText(u'10000')\r\n        self.txtLimit.setAlignment(core.Qt.AlignRight)\r\n        self.txtLimit.setFixedWidth(100)\r\n        form.addRow(u'\u884c\u6570', self.txtLimit)\r\n \r\n        encodes = ('shift_jis','cp932','utf-8')\r\n \r\n        self.cmbSrcEncode = gui.QComboBox(self)\r\n        self.cmbSrcEncode.addItems(encodes)\r\n        self.cmbSrcEncode.setFixedWidth(150)\r\n        boxSrcEncode = gui.QHBoxLayout()\r\n        boxSrcEncode.addWidget(self.cmbSrcEncode)\r\n        form.addRow(u'\u5bfe\u8c61\u30a8\u30f3\u30b3\u30fc\u30c9', boxSrcEncode)\r\n \r\n        boxCtrl = gui.QHBoxLayout()\r\n        btnExec = gui.QPushButton(u'\u5b9f\u884c')\r\n        btnExec.clicked.connect(self.doExec)\r\n        boxCtrl.addWidget(btnExec)\r\n \r\n        msgCtrl = gui.QVBoxLayout()\r\n        msgCtrl.addWidget(gui.QLabel(u\"\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u884c\u6570\u3067\u5206\u5272\u3057\u307e\u3059\u3002\"))\r\n \r\n        grid.addLayout(msgCtrl,0,0)\r\n        grid.addLayout(form,1,0)\r\n        grid.addLayout(boxCtrl,2,0)\r\n        self.setLayout(grid)\r\n        self.resize(400,100)\r\n \r\n        self.setWindowTitle(u\"\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u5206\u5272\")\r\n        self.show()\r\n \r\n    def doExec(self):\r\n        in_file = unicode(self.txtSepFile.text())\r\n \r\n        in_codec = unicode(self.cmbSrcEncode.currentText())\r\n \r\n        s_limit = unicode(self.txtLimit.text())\r\n        if not unicode.isnumeric(s_limit):\r\n            gui.QMessageBox.warning(self,\"Completed\",u\"\u884c\u6570\u306e\u6307\u5b9a\u304c\u4e0d\u6b63\u3067\u3059\u3002\")\r\n            return\r\n \r\n        self.separateFile(in_file, in_codec, int(s_limit))\r\n \r\n        gui.QMessageBox.information(self,\"Completed\",u\"\u4f5c\u6210\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002\",gui.QMessageBox.Ok)\r\n \r\n    def chooseDbFile(self):\r\n        dialog = gui.QFileDialog()\r\n        dialog.setFileMode(gui.QFileDialog.ExistingFile)\r\n        if dialog.exec_():\r\n            fileNames = dialog.selectedFiles()\r\n            for f in fileNames:\r\n                self.txtSepFile.setText(f)\r\n                return\r\n        return self.txtSepFile.setText('')\r\n \r\n \r\n    def separateFile(self, in_file, in_codec, limit):\r\n \r\n        extention = \"\"\r\n        out_file = in_file\r\n        try:\r\n            in_sep_period = in_file.split(\".\")\r\n            extention = in_sep_period[1]\r\n            out_file = \".\".join(in_sep_period[:-1])\r\n        except IndexError:\r\n            pass\r\n \r\n        in_fd = None\r\n        out_fd = None\r\n        try:\r\n            sufix = 0\r\n            line = 0\r\n            in_fd = codecs.open(in_file, 'r', in_codec)\r\n            for l in in_fd:\r\n                if line == 0:\r\n                    if out_fd:\r\n                        out_fd.close()\r\n                    sufix = sufix + 1\r\n                    outf = out_file + '_%05d.%s' % (sufix, extention)\r\n                    out_fd = codecs.open(outf, 'w', in_codec)\r\n                    print \"%s...\" % (outf)\r\n \r\n                out_fd.write(l)\r\n \r\n                # print l\r\n                line = line + 1\r\n                if line &gt;= limit:\r\n                    line = 0\r\n        except UnicodeDecodeError:\r\n            gui.QMessageBox.warning(self,\"Completed\",u\"\u30a8\u30f3\u30b3\u30fc\u30c9\u30a8\u30e9\u30fc\u3002\u30a8\u30f3\u30b3\u30fc\u30c9\u306e\u6307\u5b9a\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002\")\r\n            if out_fd:\r\n                out_fd.close()\r\n            if in_fd:\r\n                in_fd.close()\r\n        pass\r\n \r\n \r\ndef main():\r\n    app = gui.QApplication(sys.argv)\r\n    mainWin = MainWindow()\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><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=B00DDZPC9S\" frameborder=\"0\" marginwidth=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PyQt\u3092\u4f7f\u3046\u3068\u3001Python\u3067\u4f5c\u6210\u3057\u305f\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u3001\u3072\u3068\u624b\u9593\u52a0\u3048\u308b\u3060\u3051\u3067\u3001GUI\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f5c\u6210\u3067\u304d\u3066\u975e\u5e38\u306b\u4fbf\u5229\u3002 \u3053\u3093\u306a\u7a0b\u5ea6\u306a\u3089\u3001\u3061\u3087\u3044\u3061\u3087\u3044\u3063\u3068\u3001\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u3092\u8abf\u3079\u306a\u304c\u3089\u3001\u30ce\u30ea [&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-444","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\/444","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=444"}],"version-history":[{"count":0,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/444\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}