{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Table widget\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\nimport random\n\n\nclass TableWidgetDemo(ItomUi):\n def __init__(self): # constructor\n ItomUi.__init__(self, \"tableWidgetDemo.ui\", ui.TYPEWINDOW)\n self.filled = False\n\n @ItomUi.autoslot(\"\") # the signal is clicked()\n def on_btnSetValues_clicked(self):\n for c in range(0, 3):\n for r in range(0, 3):\n self.gui.table.call(\"setItem\", r, c, \"row %i, col %i\" % (r, c))\n self.gui.table.call(\"resizeColumnsToContents\")\n self.filled = True\n\n @ItomUi.autoslot(\"\") # the signal is clicked()\n def on_btnSetHeaders_clicked(self):\n self.gui.table.call(\n \"setHorizontalHeaderLabels\", (\"label 1\", \"label 2\", \"label 3\")\n )\n self.gui.table.call(\n \"setVerticalHeaderLabels\", (\"text 1\", \"text 2\", \"text 3\")\n )\n\n @ItomUi.autoslot(\"\") # the signal is clicked()\n def on_btnGetStatus_clicked(self):\n currentRow = self.gui.table.call(\"currentRow\")\n currentColumn = self.gui.table.call(\"currentColumn\")\n currentText = self.gui.table.call(\"getItem\", currentRow, currentColumn)\n ui.msgInformation(\n \"Status\",\n \"Row: %i, Col: %i, Text: %s\"\n % (currentRow, currentColumn, currentText),\n parent=self.gui,\n )\n\n @ItomUi.autoslot(\"bool\")\n def on_checkReadOnly_clicked(self, value):\n if not value:\n self.gui.table[\n \"editTriggers\"\n ] = \"DoubleClicked;EditKeyPressed;AnyKeyPressed\"\n else:\n self.gui.table[\"editTriggers\"] = 0\n\n @ItomUi.autoslot(\"int,int\")\n def on_table_cellClicked(self, row, column):\n self.gui.call(\"statusBar\").call(\n \"showMessage\", \"Cell %i,%i clicked\" % (row, column), 1000\n )\n\n @ItomUi.autoslot(\"int,int\")\n def on_table_cellChanged(self, row, column):\n checkState = self.gui.table.call(\n \"checkState\", row, column\n ) # -> special method call\n checkStateStr = [\"unchecked\", \"partially\", \"checked\"][checkState]\n currentText = self.gui.table.call(\"getItem\", row, column)\n print(\n \"Cell %i,%i (%s) changed: %s\"\n % (row, column, currentText, checkStateStr)\n )\n\n @ItomUi.autoslot(\"\") # the signal is clicked()\n def on_btnAddCheckboxes_clicked(self):\n\n if not self.filled:\n ui.msgCritical(\"empty table\", \"fill the content first\")\n return\n\n # define the flags which parameterize every item in the list (individually, if desired)\n # the flag is an OR-combination of the enumeration Qt::ItemFlag\n flagSelectable = 1 # Qt::ItemIsSelectable\n flagCheckable = 16 # Qt::ItemIsUserCheckable\n flagEnabled = 32 # Qt::ItemIsEnabled\n flagTristate = 256 # Qt::ItemIsUserTristate\n flag1 = (\n flagSelectable | flagCheckable | flagEnabled\n ) # only checkable with on/off state\n flag2 = flag1 | flagTristate # checkable with on/off/partially state\n\n # the check state is the state of the checkbox, according Qt::CheckState enumeration\n checked = 2 # checked\n partially = 1 # partially\n unchecked = 0 # unchecked\n\n # tuple of possible combinations between flags and check state\n flags = [\n [flag1, checked],\n [flag1, unchecked],\n [flag2, checked],\n [flag2, partially],\n [flag2, unchecked],\n ]\n\n for m in range(self.gui.table[\"rowCount\"]):\n for n in range(self.gui.table[\"columnCount\"]):\n f = flags[random.randint(0, len(flags) - 1)]\n self.gui.table.call(\n \"setFlags\", m, n, f[0]\n ) # -> special method call\n self.gui.table.call(\n \"setCheckState\", m, n, f[1]\n ) # -> special method call\n self.gui.table.call(\"resizeColumnsToContents\")\n\n\nwin1 = TableWidgetDemo()\nwin1.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 }