2 # -*- coding: utf-8 -*-
7 from functools
import partial
8 from PyQt4
.QtCore
import Qt
, QSize
, QTimer
, SIGNAL
, SLOT
9 from PyQt4
.QtGui
import QWidget
10 from PyKDE4
.kdecore
import i18n
11 from PyKDE4
.kdeui
import KAction
, KIcon
, KMessageBox
, KStandardAction
, KXmlGuiWindow
12 import jacklib
, ui_katia
, ui_katia_audio
16 class AudioW(QWidget
, ui_katia_audio
.Ui_AudioW
):
17 def __init__(self
, *args
):
18 QWidget
.__init
__(self
, *args
)
21 self
.b_connect
.setIcon(KIcon("network-connect"))
22 self
.b_disconnect
.setIcon(KIcon("network-disconnect"))
23 self
.b_disconnect_all
.setIcon(KIcon("network-disconnect"))
24 self
.b_refresh
.setIcon(KIcon("view-refresh"))
26 self
.b_connect
.setEnabled(False)
27 self
.b_disconnect
.setEnabled(False)
28 self
.b_disconnect_all
.setEnabled(False)
34 class KatiaMainW(KXmlGuiWindow
, ui_katia
.Ui_KatiaMainW
):
35 def __init__(self
, *args
):
36 KXmlGuiWindow
.__init
__(self
, *args
)
40 self
.jack_client
= jacklib
.client_open("Katia", 0, 0)
43 self
.act_tw_audio
= KAction(i18n("Audio"), self
)
44 self
.act_tw_midi
= KAction(i18n("MIDI"), self
)
45 self
.act_tw_canvas
= KAction(i18n("Canvas"), self
)
46 self
.act_bf_16
= KAction(i18n("16"), self
)
47 self
.act_bf_32
= KAction(i18n("32"), self
)
48 self
.act_bf_64
= KAction(i18n("64"), self
)
49 self
.act_bf_128
= KAction(i18n("128"), self
)
50 self
.act_bf_256
= KAction(i18n("256"), self
)
51 self
.act_bf_512
= KAction(i18n("512"), self
)
52 self
.act_bf_1024
= KAction(i18n("1024"), self
)
53 self
.act_bf_2048
= KAction(i18n("2048"), self
)
54 self
.act_bf_4096
= KAction(i18n("4096"), self
)
55 self
.act_bf_8192
= KAction(i18n("8192"), self
)
57 self
.act_bf_list
= ( self
.act_bf_16
, self
.act_bf_32
, self
.act_bf_64
, self
.act_bf_128
, self
.act_bf_256
, self
.act_bf_512
,
58 self
.act_bf_1024
, self
.act_bf_2048
, self
.act_bf_4096
, self
.act_bf_8192
)
60 buffer_size
= str(jacklib
.get_buffer_size(self
.jack_client
))
61 for i
in range(len(self
.act_bf_list
)):
62 self
.act_bf_list
[i
].setCheckable(True)
63 if (self
.act_bf_list
[i
].text().replace("&","") == buffer_size
):
64 self
.act_bf_list
[i
].setChecked(True)
66 self
.act_tw_audio
.setCheckable(True)
67 self
.act_tw_midi
.setCheckable(True)
68 self
.act_tw_canvas
.setCheckable(True)
71 KStandardAction
.close(self
.close
, self
.actionCollection())
74 self
.actionCollection().addAction("tw_audio", self
.act_tw_audio
)
75 self
.actionCollection().addAction("tw_midi", self
.act_tw_midi
)
76 self
.actionCollection().addAction("tw_canvas", self
.act_tw_canvas
)
77 self
.actionCollection().addAction("bf_16", self
.act_bf_16
)
78 self
.actionCollection().addAction("bf_32", self
.act_bf_32
)
79 self
.actionCollection().addAction("bf_64", self
.act_bf_64
)
80 self
.actionCollection().addAction("bf_128", self
.act_bf_128
)
81 self
.actionCollection().addAction("bf_256", self
.act_bf_256
)
82 self
.actionCollection().addAction("bf_512", self
.act_bf_512
)
83 self
.actionCollection().addAction("bf_1024", self
.act_bf_1024
)
84 self
.actionCollection().addAction("bf_2048", self
.act_bf_2048
)
85 self
.actionCollection().addAction("bf_4096", self
.act_bf_4096
)
86 self
.actionCollection().addAction("bf_4096", self
.act_bf_8192
)
88 # Connect actions to functions
89 self
.connect(self
.act_tw_audio
, SIGNAL("triggered()"), partial(self
.changeTabButton
, "audio"))
90 self
.connect(self
.act_tw_midi
, SIGNAL("triggered()"), partial(self
.changeTabButton
, "midi"))
91 self
.connect(self
.act_tw_canvas
, SIGNAL("triggered()"), partial(self
.changeTabButton
, "canvas"))
92 self
.connect(self
.act_bf_16
, SIGNAL("triggered()"), partial(self
.setBufferSize
, 16))
93 self
.connect(self
.act_bf_32
, SIGNAL("triggered()"), partial(self
.setBufferSize
, 32))
94 self
.connect(self
.act_bf_64
, SIGNAL("triggered()"), partial(self
.setBufferSize
, 64))
95 self
.connect(self
.act_bf_128
, SIGNAL("triggered()"), partial(self
.setBufferSize
, 128))
96 self
.connect(self
.act_bf_256
, SIGNAL("triggered()"), partial(self
.setBufferSize
, 256))
97 self
.connect(self
.act_bf_512
, SIGNAL("triggered()"), partial(self
.setBufferSize
, 512))
98 self
.connect(self
.act_bf_1024
, SIGNAL("triggered()"), partial(self
.setBufferSize
, 1024))
99 self
.connect(self
.act_bf_2048
, SIGNAL("triggered()"), partial(self
.setBufferSize
, 2048))
100 self
.connect(self
.act_bf_4096
, SIGNAL("triggered()"), partial(self
.setBufferSize
, 4096))
101 self
.connect(self
.act_bf_4096
, SIGNAL("triggered()"), partial(self
.setBufferSize
, 8192))
103 # Connect tab-buttons to pages
104 self
.connect(self
.tb_audio
, SIGNAL("clicked()"), partial(self
.changeTabButton
, "audio"))
105 self
.connect(self
.tb_midi
, SIGNAL("clicked()"), partial(self
.changeTabButton
, "midi"))
106 self
.connect(self
.tb_canvas
, SIGNAL("clicked()"), partial(self
.changeTabButton
, "canvas"))
108 # Set-up the GUI (Part 1, create the KDE stuff)
109 self
.setupGUI(QSize(600, 400), KXmlGuiWindow
.Default
, path
[0]+"/katia.rc")
111 # Set-up the GUI (Part 2, set custom menu and status-bar, delete toolbar)
112 self
.menuLayout
.addWidget(self
.menuBar())
113 self
.toolBar().deleteLater()
114 self
.statusBar().setVisible(False)
115 self
.actionCollection().action(u
'options_configure_toolbars').setVisible(False)
116 self
.actionCollection().action(u
'options_show_statusbar').setVisible(False)
117 self
.connect(self
.statusBar(), SIGNAL("messageChanged(QString)"), self
.sbW_msg_label
, SLOT("setText(QString)"))
119 # Set-up the GUI (Part 3, Load pages)
120 self
.tw_audio
= AudioW()
121 #self.tw_midi = w_katia_midi.MidiW()
122 #self.tw_canvas = w_katia_canvas.CanvasW()
123 self
.tw_audio
.setVisible(False)
124 #self.tw_midi.setVisible(False)
125 #self.tw_canvas.setVisible(False)
127 # Set-up the GUI (Part 4, set default page)
128 self
.tw_audio
.setVisible(True)
129 self
.tb_audio
.setChecked(True)
130 self
.act_tw_audio
.setChecked(True)
131 self
.act_tw_audio
.setEnabled(False)
132 self
.centralW
.layout().addWidget(self
.tw_audio
)
133 self
.currentTabPage
= "audio"
135 # Set-up the GUI (Part 5, update variables)
136 self
.sbW_jack_SampleRate
.setText(str(jacklib
.get_sample_rate(self
.jack_client
))+" Hz")
137 self
.sbW_jack_BufferSize
.setText(str(jacklib
.get_buffer_size(self
.jack_client
)))
139 if (jacklib
.is_realtime(self
.jack_client
)):
140 self
.sbW_jack_RT
.setText("RT")
142 self
.sbW_jack_RT
.setText("")
148 print "going for ports"
150 def setBufferSize(self
, buffer_size
):
151 if (jacklib
.set_buffer_size(self
.jack_client
, buffer_size
) > 0):
152 for i
in range(len(self
.act_bf_list
)):
153 if (self
.act_bf_list
[i
].text().replace("&","") == str(buffer_size
)):
154 self
.act_bf_list
[i
].setChecked(True)
156 self
.act_bf_list
[i
].setChecked(False)
158 KMessageBox
.error(self
, i18n("Failed to set buffer size!"), i18n("Katia - Error"))
160 def changeTabButton(self
, button
):
161 if (button
!= self
.currentTabPage
):
162 self
.currentTabPage
= button
163 # Remove central widget
164 #self.centralW.layout().takeAt(0)
165 # Restore all button states
166 self
.tb_audio
.setChecked(False)
167 self
.tb_midi
.setChecked(False)
168 self
.tb_canvas
.setChecked(False)
169 # Hide all pages (we only need one)
170 #self.tw_audio.setVisible(False)
171 #self.tw_midi.setVisible(False)
172 #self.tw_canvas.setVisible(False)
174 self
.act_tw_audio
.setChecked(False)
175 self
.act_tw_audio
.setEnabled(True)
176 self
.act_tw_midi
.setChecked(False)
177 self
.act_tw_midi
.setEnabled(True)
178 self
.act_tw_canvas
.setChecked(False)
179 self
.act_tw_canvas
.setEnabled(True)
180 if (button
== "audio"):
181 self
.tb_audio
.setChecked(True)
182 wToLoad
= self
.tw_audio
183 selMenu
= self
.act_tw_audio
184 elif (button
== "midi"):
185 self
.tb_midi
.setChecked(True)
186 #wToLoad = self.tw_midi
187 selMenu
= self
.act_tw_midi
188 elif (button
== "canvas"):
189 self
.tb_canvas
.setChecked(True)
190 #wToLoad = self.tw_canvas
191 selMenu
= self
.act_tw_canvas
192 #self.centralW.layout().addWidget(wToLoad)
193 #wToLoad.setVisible(True)
194 selMenu
.setChecked(True)
195 selMenu
.setEnabled(False)
197 def updateSizes(self
):
198 self
.sbW_msg
.setMinimumSize(self
.width()/4, 16)
199 self
.sbW_msg
.setMaximumSize(self
.width()/4, 16)
200 self
.sbW_jack
.setMaximumSize(self
.width()/3, 16)
201 self
.sbW_cpu
.setMaximumSize(self
.width()/4, 16)
202 self
.sbW_drops
.setMaximumSize(self
.width()/8, 16)
204 def resizeEvent(self
, event
):