PySide ãã¥ã¼ããªã¢ã« - helloworld ãã ã¦ããããã¹ãã¾ã§
ãã 2 ã¶æã»ã© PySide ã§ãä»äºãã¦ã¾ãã。ãã¨ã㨠PyQt ã§åãã¦ãã¢ããªã±ã¼ã·ã§ã³ã ã£ãã®ã§ãã、ãã£ããä»æ§å¤æ´ã大ããã£ããã¨ããã、ã©ãããªã®ã§ PySide ã§ä½ãç´ãã¦ã¿ããã¨ã«ãã¾ãã。両ãã¬ã¼ã ã¯ã¼ã¯ã®å·®ç°ã¯ãã®ãã¼ã¸ã«ã¾ã¨ã¾ã£ã¦ãã¾ã (id:doloopwhile ããã翻訳ããã¦ãã¾ã)。大ããã¯、
- ã¢ã¸ã¥ã¼ã«åã PyQt ãã PySide ã«
- PyQt ã® API 㯠QString ã QVariants ç Qt ãæä¾ããåã¨、unicode ç Python ã®ãã¼ã¿åã®ä¸¡æ¹ããµãã¼ããã¦ãã¾ããã、PySide ã§ã¯ Python ã®ãã¼ã¿åã®ã¿ããµãã¼ã
- ç»åçã®ãªã½ã¼ã¹ãã¡ã¤ã«ããã¤ããªã«å¤æããããããã¼ã«é¡ã®å称ãããããå¤æ´
-
- pyuic4 -> pyside-uic
- pyrcc4 -> pyside-rcc4
- pylupdate4 -> pyside-lupdate
PySide ã¸ã®å¤æ´ã¯ãããªã«åé¡ã§ã¯ããã¾ããã、ã¾ã éçºä¸ã¨ãããã¨ããã、pyside-rcc4 ã«ãã°ããã£ãã、signal-slot ãé ãã¨ãããã¨ãããããã§ã。ãã®è¾ºãã¯ä»å¾ã«æå¾ ã§ã。
ã¨ãããã¨ã§èªåã®å¾©ç¿ & ã¡ã¢ã¨、PySide ãã¡ãã£ã¨ã§ãæ®åããã°ãããªã¨ãããã¨ã§、PySide ã®ãã¥ã¼ããªã¢ã«ãä½ã£ã¦ã¿ã¾ãã。helloworld ã¨ãããã¨ã§、ãã¿ã³ãããããããã¹ãããã¯ã¹ã« "Hello world" ã¨è¡¨ç¤ºããã ãã®ãªãã®é¢ç½å³ããªãã¦ã£ã¸ã§ããã¨、ãã®ã¦ããããã¹ããä½ã£ã¦ã¿ã¾ã。ã½ã¼ã¹ã¯ bitbucket ã«å ¬éãã¾ãã。
- ç°å¢ãæ´ãã
- ã¤ã³ã¹ãã¼ã«ãããã®
-
- Python
- Python for Windows extensions (Windows ã¦ã¼ã¶ã®ã¿)
- PySide
- æ¨å¥¨
-
- virtualenv - py2exe ã§ããªã¼ã¸ã³ã° (å®è¡ãã¡ã¤ã«å½¢å¼ã«å¤æ) ããéã«ä½è¨ãªã©ã¤ãã©ãªãå«ã¾ããã®ãé²ããã
- ã¦ã£ã¸ã§ããã表示ãã¦ã¿ã
Python ã¤ã³ã¿ããªã¿ãã以ä¸ã®ããã«æã¤ã¨、ãã¤ã¢ãã°ã表示ãããã¨ãã§ãã¾ã。import sys from PySide import QtGui app = QtGui.QApplication(sys.argv) dialog = QtGui.QDialog() dialog.exec_()
- UI ãä½ã
ä»åä½ã helloworld ã¢ããªã±ã¼ã·ã§ã³ã¯ããã¹ãããã¯ã¹ã¨ãã¿ã³ã®ã¿ã®ã¦ã£ã¸ã§ããã§ã。 ãµã³ãã«ã³ã¼ãã® setup_ui ã®é¨å㧠UI ãè¨å®ãã¦ãã¾ã。 Qt ãã¶ã¤ã㨠pyside-uic ã使ãæ¹æ³ãããã¾ãã、ç§ã¯ä½¿ã£ããã¨ããªãã§ã。。。UI ãä½ã£ã¦ãããã¤ã³ããæç²ããã¨、- åã¦ã£ã¸ã§ãã (QWidget åã³ãµãã¯ã©ã¹) ã«、ã¬ã¤ã¢ã¦ã (QLayout ã®ãµãã¯ã©ã¹) ãè¨å®ãã
- QVBoxLayout: 縦ã«é åãã¦ãã
- QHBoxLayout: 横ã«é åãã¦ãã
- QGridLayout: ã°ãªããç¶ã«é åãã¦ãã
- ä»ã«ã QFormLayout ã QStackedLayout çãããã¾ã
- åã¬ã¤ã¢ã¦ãã«åä¾ã®ã¦ã£ã¸ã§ããã追å ãã¦ãã
- ã¦ã£ã¸ã§ããããã¹ãããããã¨ã§、ããè¤é㪠UI ã表ç¾ã§ãã¾ã
- åãæ示ãã
- settar ãå¼ã³åºãããå¾ã« signal ãéåºãããã¨ãã§ãã (Python ã® property ã§æ¸ãã¦、setattr æã« emit ãã¡ãã£ã¦ããããã©・・・)
- åã¦ã£ã¸ã§ãã (QWidget åã³ãµãã¯ã©ã¹) ã«、ã¬ã¤ã¢ã¦ã (QLayout ã®ãµãã¯ã©ã¹) ãè¨å®ãã
- ã¦ããããã¹ããæ¸ã
UI ãã§ããã、ã¦ããããã¹ããæ¸ãã¾ã (ãã¹ããã¡ã¼ã¹ã :-)。Qt ã«ã¯ QtTest ã¨ãããã¹ãç¨ã®ãã¬ã¼ã ã¯ã¼ã¯ãç¨æããã¦ãã¾ã。PySide ã§ã¯、ãã®ãã¼ã¸ã«ãè¨è¼ããã¦ããããã«、Python ã® unittest ã¢ã¸ã¥ã¼ã«ã使ã£ã¦ã¦ããããã¹ããã¾ã。Qt ã¯ãã¹ãã signal-slot ãã¼ã¹ã§ã。ã¦ã£ã¸ã§ããã«ãã signal ãåµåºãã、slot ãå¦çããå¾ã«、ã¦ã£ã¸ã§ãããã©ããªã£ã¦ããã。QTest ã«ããã¤ãã®åºæ¬çãªã¤ãã³ããçºçãããã¡ã½ãããç¨æããã¦ãã¾ã。ãµã³ãã«ã³ã¼ãã§ã¯ãã¿ã³ãã¯ãªãã¯ããéã®ããã¹ãããã¯ã¹ã®ç¶æ ããã¹ããã¦ãã¾ã。ã¾ã signal-slot ãå®è£ ãã¦ããªãã®ã§、ãã¹ãã¯å¤±æããã¯ã。 - ã¤ãã³ã (signal-slot) ãå®è£
ãã
ã¦ããããã¹ããééã§ããããã« signal-slot ãå®è£ ãã¦ããã¾ã。signal-slot ã®æ¸ãæ¹ã¯ä½ç¨®é¡ãããã¾ã。ãµã³ãã«ã³ã¼ãã® setup_events ã®ç®æã§ã¤ãã³ããã»ããã¢ãããã¦ãã¾ã。ããã« connect ãããããæ¸ãã¦ãããã§ãã、åã¦ã£ã¸ã§ããã®ã¤ãã³ããå帰çã«ã³ãã¯ããã connectSlotsByName ãæå®ããã®ã好ãã§ã。ã³ã¼ãéãå°ãªããªãã®ã§ãã®æ¸ãæ¹ãå¤ç¨ãã¦ãã¾ã (ã¤ãã³ããã³ãã©ã®è¿½å ããããã³ã« connect ã¨ãæ¸ããããªã)。
connectSlotsByName ãå©ç¨ããã¨、slot ã¡ã½ãããdef on_<object name>_<signal name>(<signal parameters>)
ã¨ãã風ã«æ¸ããããã«ãªãã¾ã。 ãã® object name ã¯、ååã¦ã£ã¸ã§ããã«å¯¾ã setObjectname ã§æå®ãã¦ãããå¿ è¦ãããã¾ã。ãµã³ãã«ã³ã¼ãã§ã¯、base_layout, lineedit, button ãã¹ã¦ã«ã»ãããã¦ãã¾ãã、ä»åã®è¦ä»¶ãæºããã«ã¯ button ã¦ã£ã¸ã§ããã ãã»ããããã°ããã§ã。ããã§ãµã³ãã«ã³ã¼ãã®ããã«on_button_clicked
㧠button ã® clicked ã¤ãã³ãã® slot ãä½æã§ãã¾ã。
以ä¸、ãªãã®é¢ç½ãããªããã¥ã¼ããªã¢ã«ã§ãã、 PySide ã§ã®éçºã®æµããå°ãã§ãè¦ãããè¯ãããªã¼ã¨。
ã³ã¡ã³ã
ã³ã¡ã³ããæ稿