Debian Codegraph @

src/Scripts/Editor/invalues_for_widgets.py

raw symbols SCIP
1 import os
2 import sys
3
4 from xml.dom.minidom import parseString
5 import PythonQt.QtGui as pqt
6
7 # This script creates all the necessary lines to connect widgets to Csound code
8 # Just go to the file you want, select the widgets and run this script from the menu
9
10 widgets_text = q.getSelectedWidgetsText()
11 # parse xml widgets text for current tab
12 widgets = []
13
14 widgets = parseString(widgets_text)
15
16 # Find widget elements
17 widgetList = widgets.getElementsByTagName("bsbObject")
18
19 if len(widgetList) == 0:
20 pqt.QMessageBox.information(0, "Script", "Please select widgets")
21
22 # Create empty set for used channel names. This avoids duplicates.
23 channel_list = set()
24
25 # Go through all the widget list and find the objectName tag which contains the channel
26 for widget in widgetList:
27 ch = widget.getElementsByTagName("objectName")
28 channel_list.add(" ".join(t.nodeValue for t in ch[0].childNodes if t.nodeType == t.TEXT_NODE))
29
30 # Remove empty channels
31 if "" in channel_list:
32 channel_list.remove("")
33 out_text = ''
34
35 # Now make the text to be inserted
36 for channel in channel_list:
37 print(channel)
38 out_text += 'k%s invalue "%s"\n'%(channel, channel)
39
40 # and insert it
41 q.insertText(out_text)
42
43