Package: smartside
SmartSide is one of many available ways to have PySide signals connected in a easy way.Example of what it can do for youSuppose you have designed a GUI usingQt DesignerCompile it with:$pyside-uic.exemyform.ui-omyform_ui.py# if you have resources included compile them too$pyside-rcc.exemyresources.qrc-omyresources_rc.pyThen use a code like this to show your form and bind some signals:importsysfrommyform_uiimport*# this will also include `QtCore` and `QtGui`importsmartside.signalassmartsignalclassMyApplication(QtGui.QMainWindow,Ui_MainWindow,smartsignal.SmartSignal):def__init__(self,parent=None):super(MyApplication,self).__init__(parent)self.setupUi(self)# create any local UI object here, so they signal are# going to be auto-connected tooself.auto_connect()# will respond to stateChanged signal from checkBox widget# notice the double underline between widget name and signal namedef_on_checkBox__stateChanged(self):print'check',self.sender().isChecked()# will respond to `pressed` signal of btn_add widgetdef_on_btn_add__pressed(self):print'btn_add was pressed'# list some widgets and use regex `regex`, to select multiples.# starting with underline is mandatory_myfuncs='btn_base, btn_format, `btn_.+log.+`, btn_sqr'# will respond to clicked signal of all widget listed abovedef_when_myfuncs__clicked(self):print'multiples',self.sender()if__name__=="__main__":app=QtGui.QApplication(sys.argv)window=MyApplication()window.show()# uncomment line below to print a list of ALL signals available on your form# window.print_all_signals()sys.exit(app.exec_())Your form is supposed to be calledUi_MainWindowin this example.First we usesetupUias usual to create the interface.Thenauto_connectwill connect member functions to signals when they match.The last case use a multiple connection, so more then one widgets will call the same callback function. You can also use regex to select related widgets. In the example above we have selected a few widgets by its explicit name and also all widget whose name starts with'btn\_'and have'log'in some part of its name. All of them are going to be connected to_when_myfuncs__clicked.Yes, it works with actions too. Likedef _on_actionTest__triggered(self):. This is usefull when you create context menu by code. Just remember to callauto_connectaftermenu creation.Show icon on Windows taskbarUsually Windows 7+ executes Python scripts as a group and put every icon you define to your GUI as a child of Python’s taskbar icon, since python actually hosts your code. This happens even if you give.pywas extension for your python script.To solve this you have to tell Windows your script is an application by callingsmartside.setAsApplication()and pass to this function an unique identifier for your script, like: ‘company.product.version’.# ....if__name__=="__main__":fromsmartsideimportsetAsApplicationsetAsApplication('example_co.exampleProd.'+__version__)app=QtGui.QApplication(sys.argv)window=MyApplication()window.show()sys.exit(app.exec_())Console WidgetUsing Qt Designer promote a QPlainTextEdit toConsoleWidget, and usesmartside.consoleas header (source).Then, inside__init__of this form use:self.name_of_widget.setLocals({'name':object, 'me': self}).This will make the promoted QPlainTextEdit to become a python console with access to two objects:nameandme.LanguageThe functiongetBestTranslationis used to discover the best translation file available for an app.It will look in a folder for a.qmfile in the following order:en-US.qmen_US.qmen.qmYou can specify a list of desired languages or let the function to check the system languages. If no translation is found the native language will be used.# ....if__name__=="__main__":fromsmartsideimportgetBestTranslation# this will look for translations inside folder ./i18n# it will search by system languagestranslator=getBestTranslation('i18n')app=QtGui.QApplication(sys.argv)app.installTranslator(translator)window=MyApp()window.show()sys.exit(app.exec_())# if you want to specify the languagestranslator=getBestTranslation('language',['pt-BR','es'])In this case it will try:language/pt-BR.qmlanguage/pt_BR.qmlanguage/pt.qmlanguage/es.qmChange History0.1.7:Added language locator.0.1.6:Fixed setup typo.0.1.5:Added support to python 3.0.1.4:AddedConsoleWidgetclass.0.1.3:AddedsetAsApplication.0.1.2:Added QAction support; For every QAction created before calling auto_connect() you can usedef _on_action_name__clicked(self):like you do with signals.0.1.1:Small fix.Development:https://github.com/xgvargas/smartside- please use this space if you found a problem or think any other task on PySide can be simplified.