-
- ###
- from PySide2.QtWidgets import QMainWindow, QApplication
- from uiLoader import load_ui
- import sys
-
- class MainWindow(QMainWindow):
- def __init__(self, parent=None):
- self.pos1 = [0,0]
- self.pos2 = [0,0]
- control=" "
- QMainWindow.__init__(self, parent)
- load_ui('generator.ui', self)
- self.konButton.actionTriggered(self.konToolBar.konButton).connect(addaButton)
- #def newLayout()
-
- def handleToolbar(self):
- if control == "button":
- print ("button")
-
- def addaButton(self):
- print ('clicked')
- #control = "button"
- #handleToolbar
-
- def main():
- app = QApplication(sys.argv)
- window = MainWindow()
- window.show()
- app.exec_()
-
- if __name__ == '__main__':
- main()
- ###
- ###
- uiloader.py
- from PySide2.QtUiTools import QUiLoader
- from PySide2.QtCore import QMetaObject
- from PySide2.QtWidgets import QMainWindow
-
-
- class UiLoader(QUiLoader):
- def __init__(self, base_instance):
- QUiLoader.__init__(self, base_instance)
- self.base_instance = base_instance
-
- def createWidget(self, class_name, parent=None, name=''):
- if parent is None and self.base_instance:
- return self.base_instance
- else:
- # create a new widget for child widgets
- widget = QUiLoader.createWidget(self, class_name, parent, name)
- if self.base_instance:
- setattr(self.base_instance, name, widget)
- return widget
-
- def load_ui(ui_file, base_instance=None):
- loader = UiLoader(base_instance)
- widget = loader.load(ui_file)
- QMetaObject.connectSlotsByName(widget)
- return widget
-
- ###
- ###
- generator.ui
- <?xml version="1.0" encoding="UTF-8"?>
- <ui version="4.0">
- <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>800</width>
- <height>727</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>MainWindow</string>
- </property>
- <widget class="QWidget" name="centralwidget"/>
- <widget class="QToolBar" name="konToolBar">
- <property name="windowTitle">
- <string>toolBar</string>
- </property>
- <attribute name="toolBarArea">
- <enum>TopToolBarArea</enum>
- </attribute>
- <attribute name="toolBarBreak">
- <bool>false</bool>
- </attribute>
- <addaction name="konButton"/>
- <addaction name="kontoggle"/>
- <addaction name="kondial"/>
- <addaction name="kondiscreteDial"/>
- <addaction name="konControl"/>
- <addaction name="konvFader"/>
- <addaction name="konhfader"/>
- <addaction name="konScratcher"/>
- <addaction name="konWaveform"/>
- </widget>
- <widget class="QStatusBar" name="statusBar"/>
- <action name="button">
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>button</string>
- </property>
- <property name="toolTip">
- <string>Momentary button</string>
- </property>
- <property name="shortcut">
- <string>Alt+B</string>
- </property>
- </action>
- <action name="toggle">
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>switch</string>
- </property>
- <property name="toolTip">
- <string>Momentary button</string>
- </property>
- <property name="shortcut">
- <string>Alt+B</string>
- </property>
- </action>
- <action name="dial">
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>dial</string>
- </property>
- <property name="toolTip">
- <string>continuous dial</string>
- </property>
- <property name="shortcut">
- <string>Alt+B</string>
- </property>
- </action>
- <action name="discreteDial">
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>multiswitch</string>
- </property>
- <property name="toolTip">
- <string>multi-position switch</string>
- </property>
- <property name="shortcut">
- <string>Alt+B</string>
- </property>
- </action>
- <action name="xyControl">
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>xyControl</string>
- </property>
- <property name="toolTip">
- <string>XY position control</string>
- </property>
- <property name="shortcut">
- <string>Alt+B</string>
- </property>
- </action>
- <action name="vFader">
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>vFader</string>
- </property>
- <property name="toolTip">
- <string>one ormore vertical faders</string>
- </property>
- <property name="shortcut">
- <string>Alt+B</string>
- </property>
- </action>
- <action name="hfader">
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>hfader</string>
- </property>
- <property name="toolTip">
- <string>one or more horizontal faders</string>
- </property>
- <property name="shortcut">
- <string>Alt+B</string>
- </property>
- </action>
- <action name="scratcher">
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>scratcher</string>
- </property>
- <property name="toolTip">
- <string>circular control which tracks distance and position from center</string>
- </property>
- <property name="shortcut">
- <string>Alt+B</string>
- </property>
- </action>
- <action name="waveform">
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>waveform</string>
- </property>
- <property name="toolTip">
- <string>waveform display with time markers</string>
- </property>
- <property name="shortcut">
- <string>Alt+B</string>
- </property>
- </action>
- </widget>
- <resources/>
- <connections/>
- </ui>
- ###
-