{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Auto connect signals\n\nThis demo shows how to use the auto-connection feature\nfor automatically connecting signals from widgets to methods.\n\nThe base requirement for this is, that the ui-file is wrapped\nby a class in Python.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from itomUi import (\n ItomUi,\n) # import the base class ItomUi from the module itomUi in the itom-packages subfolder\nfrom itom import ui\n\n\nclass AutoConnectExample(ItomUi): # AutoConnectExample is inherited from ItomUi\n def __init__(self): # constructor\n\n # call constructor of ItomUi like it would be the constructor of the class itom.ui:\n ItomUi.__init__(self, \"autoConnectDemo.ui\", ui.TYPEWINDOW)\n self.counter = 0 # create a counter variable for this instance\n\n # initialize the captions of the labels:\n self.gui.lblCheckResult[\"text\"] = \"not checked\"\n self.gui.lblSpinResult[\"text\"] = \"current value: 0\"\n\n @ItomUi.autoslot(\"\") # the signal is clicked()\n def on_btnDemo_clicked(self):\n # increment the counter\n self.counter += 1\n ui.msgInformation(\n \"button clicked\",\n \"The button was clicked %i times\" % self.counter,\n parent=self.gui,\n )\n self.gui.btnDemo[\"text\"] = \"click me again\"\n\n @ItomUi.autoslot(\"bool\") # the signal is clicked(bool checked)\n def on_checkDemo_clicked(self, checked):\n if checked:\n self.gui.lblCheckResult[\"text\"] = \"checked\"\n else:\n self.gui.lblCheckResult[\"text\"] = \"not checked\"\n\n @ItomUi.autoslot(\"int\") # the signal is valueChanged ( int i )\n def on_spinDemo_valueChanged(self, value):\n self.gui.lblSpinResult[\"text\"] = \"current value: %i\" % value\n\n\n# create a first instance of AutoConnectExample and the gui\nwin1 = AutoConnectExample()\nwin1.gui.show() # show the gui\nwin1.gui[\"geometry\"] = (100, 100, 412, 157)\n\n# create a second instance (due to the class based approach, both windows have different counter variables (among others)\nwin2 = AutoConnectExample()\nwin2.gui.show() # show the gui" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }