spacepaste

  1.  
  2. ###
  3. from PySide2.QtWidgets import QMainWindow, QApplication
  4. from uiLoader import load_ui
  5. import sys
  6. class MainWindow(QMainWindow):
  7. def __init__(self, parent=None):
  8. self.pos1 = [0,0]
  9. self.pos2 = [0,0]
  10. control=" "
  11. QMainWindow.__init__(self, parent)
  12. load_ui('generator.ui', self)
  13. self.konButton.actionTriggered(self.konToolBar.konButton).connect(addaButton)
  14. #def newLayout()
  15. def handleToolbar(self):
  16. if control == "button":
  17. print ("button")
  18. def addaButton(self):
  19. print ('clicked')
  20. #control = "button"
  21. #handleToolbar
  22. def main():
  23. app = QApplication(sys.argv)
  24. window = MainWindow()
  25. window.show()
  26. app.exec_()
  27. if __name__ == '__main__':
  28. main()
  29. ###
  30. ###
  31. uiloader.py
  32. from PySide2.QtUiTools import QUiLoader
  33. from PySide2.QtCore import QMetaObject
  34. from PySide2.QtWidgets import QMainWindow
  35. class UiLoader(QUiLoader):
  36. def __init__(self, base_instance):
  37. QUiLoader.__init__(self, base_instance)
  38. self.base_instance = base_instance
  39. def createWidget(self, class_name, parent=None, name=''):
  40. if parent is None and self.base_instance:
  41. return self.base_instance
  42. else:
  43. # create a new widget for child widgets
  44. widget = QUiLoader.createWidget(self, class_name, parent, name)
  45. if self.base_instance:
  46. setattr(self.base_instance, name, widget)
  47. return widget
  48. def load_ui(ui_file, base_instance=None):
  49. loader = UiLoader(base_instance)
  50. widget = loader.load(ui_file)
  51. QMetaObject.connectSlotsByName(widget)
  52. return widget
  53. ###
  54. ###
  55. generator.ui
  56. <?xml version="1.0" encoding="UTF-8"?>
  57. <ui version="4.0">
  58. <class>MainWindow</class>
  59. <widget class="QMainWindow" name="MainWindow">
  60. <property name="geometry">
  61. <rect>
  62. <x>0</x>
  63. <y>0</y>
  64. <width>800</width>
  65. <height>727</height>
  66. </rect>
  67. </property>
  68. <property name="windowTitle">
  69. <string>MainWindow</string>
  70. </property>
  71. <widget class="QWidget" name="centralwidget"/>
  72. <widget class="QToolBar" name="konToolBar">
  73. <property name="windowTitle">
  74. <string>toolBar</string>
  75. </property>
  76. <attribute name="toolBarArea">
  77. <enum>TopToolBarArea</enum>
  78. </attribute>
  79. <attribute name="toolBarBreak">
  80. <bool>false</bool>
  81. </attribute>
  82. <addaction name="konButton"/>
  83. <addaction name="kontoggle"/>
  84. <addaction name="kondial"/>
  85. <addaction name="kondiscreteDial"/>
  86. <addaction name="konControl"/>
  87. <addaction name="konvFader"/>
  88. <addaction name="konhfader"/>
  89. <addaction name="konScratcher"/>
  90. <addaction name="konWaveform"/>
  91. </widget>
  92. <widget class="QStatusBar" name="statusBar"/>
  93. <action name="button">
  94. <property name="checkable">
  95. <bool>true</bool>
  96. </property>
  97. <property name="text">
  98. <string>button</string>
  99. </property>
  100. <property name="toolTip">
  101. <string>Momentary button</string>
  102. </property>
  103. <property name="shortcut">
  104. <string>Alt+B</string>
  105. </property>
  106. </action>
  107. <action name="toggle">
  108. <property name="checkable">
  109. <bool>true</bool>
  110. </property>
  111. <property name="text">
  112. <string>switch</string>
  113. </property>
  114. <property name="toolTip">
  115. <string>Momentary button</string>
  116. </property>
  117. <property name="shortcut">
  118. <string>Alt+B</string>
  119. </property>
  120. </action>
  121. <action name="dial">
  122. <property name="checkable">
  123. <bool>true</bool>
  124. </property>
  125. <property name="text">
  126. <string>dial</string>
  127. </property>
  128. <property name="toolTip">
  129. <string>continuous dial</string>
  130. </property>
  131. <property name="shortcut">
  132. <string>Alt+B</string>
  133. </property>
  134. </action>
  135. <action name="discreteDial">
  136. <property name="checkable">
  137. <bool>true</bool>
  138. </property>
  139. <property name="text">
  140. <string>multiswitch</string>
  141. </property>
  142. <property name="toolTip">
  143. <string>multi-position switch</string>
  144. </property>
  145. <property name="shortcut">
  146. <string>Alt+B</string>
  147. </property>
  148. </action>
  149. <action name="xyControl">
  150. <property name="checkable">
  151. <bool>true</bool>
  152. </property>
  153. <property name="text">
  154. <string>xyControl</string>
  155. </property>
  156. <property name="toolTip">
  157. <string>XY position control</string>
  158. </property>
  159. <property name="shortcut">
  160. <string>Alt+B</string>
  161. </property>
  162. </action>
  163. <action name="vFader">
  164. <property name="checkable">
  165. <bool>true</bool>
  166. </property>
  167. <property name="text">
  168. <string>vFader</string>
  169. </property>
  170. <property name="toolTip">
  171. <string>one ormore vertical faders</string>
  172. </property>
  173. <property name="shortcut">
  174. <string>Alt+B</string>
  175. </property>
  176. </action>
  177. <action name="hfader">
  178. <property name="checkable">
  179. <bool>true</bool>
  180. </property>
  181. <property name="text">
  182. <string>hfader</string>
  183. </property>
  184. <property name="toolTip">
  185. <string>one or more horizontal faders</string>
  186. </property>
  187. <property name="shortcut">
  188. <string>Alt+B</string>
  189. </property>
  190. </action>
  191. <action name="scratcher">
  192. <property name="checkable">
  193. <bool>true</bool>
  194. </property>
  195. <property name="text">
  196. <string>scratcher</string>
  197. </property>
  198. <property name="toolTip">
  199. <string>circular control which tracks distance and position from center</string>
  200. </property>
  201. <property name="shortcut">
  202. <string>Alt+B</string>
  203. </property>
  204. </action>
  205. <action name="waveform">
  206. <property name="checkable">
  207. <bool>true</bool>
  208. </property>
  209. <property name="text">
  210. <string>waveform</string>
  211. </property>
  212. <property name="toolTip">
  213. <string>waveform display with time markers</string>
  214. </property>
  215. <property name="shortcut">
  216. <string>Alt+B</string>
  217. </property>
  218. </action>
  219. </widget>
  220. <resources/>
  221. <connections/>
  222. </ui>
  223. ###
  224.