2 # -*- coding: utf-8 -*-
7 from functools
import partial
8 from PyQt4
.QtCore
import Qt
, QThread
, QTime
, QTimer
, SIGNAL
9 from PyQt4
.QtGui
import QCursor
, QDialog
, QDialogButtonBox
, QMenu
, QTableWidgetItem
, QWidget
10 from PyKDE4
.kdecore
import i18n
11 import ui_tb_main
, ui_dia_properties
, shared
18 class MainW(QWidget
, ui_tb_main
.Ui_MainW
):
19 def __init__(self
, *args
):
20 QWidget
.__init
__(self
, *args
)
24 t_start
= shared
.p_time_start
.split(":")
25 t_end
= shared
.p_time_end
.split(":")
26 self
.timeStart
.setTime(QTime(int(t_start
[0]), int(t_start
[1]), int(t_start
[2])))
27 self
.timeEnd
.setTime(QTime(int(t_end
[0]), int(t_end
[1]), int(t_end
[2])))
28 self
.b_icon
.setIcon(shared
.p_icon
)
29 self
.lp_name
.setText(shared
.p_name
)
30 self
.lp_author
.setText(shared
.p_author
)
31 self
.lp_composer
.setText(shared
.p_composer
)
32 self
.lp_album
.setText(shared
.p_album
)
33 self
.spin_track
.setValue(int(shared
.p_track
))
35 self
.listLadish
.setColumnWidth(0, 25)
36 self
.listLadish
.setColumnWidth(1, 200)
37 self
.listLadish
.setColumnWidth(2, 60)
38 self
.listLadish
.setColumnWidth(3, 60)
39 self
.listLadish
.setColumnWidth(4, 50)
41 self
.listLadish
.setContextMenuPolicy(Qt
.CustomContextMenu
)
43 self
.updateTotalTime()
44 self
.updateLadishApps()
46 shared
.sliderMinValue
= (int(t_start
[0])*3600) + (int(t_start
[1])*60) + int(t_start
[2])
47 shared
.sliderMaxValue
= (int(t_end
[0])*3600) + (int(t_end
[1])*60) + int(t_end
[2])
49 self
.connect(self
.b_SetStart
, SIGNAL("clicked()"), partial(self
.setTime
, "start"))
50 self
.connect(self
.b_SetEnd
, SIGNAL("clicked()"), partial(self
.setTime
, "end"))
51 self
.connect(self
.timeStart
, SIGNAL("timeChanged(const QTime)"), self
.updateTotalTime
)
52 self
.connect(self
.timeEnd
, SIGNAL("timeChanged(const QTime)"), self
.updateTotalTime
)
53 self
.connect(self
.listLadish
, SIGNAL("customContextMenuRequested(QPoint)"), self
.showLadishMenu
)
55 self
.connect(self
.lp_name
, SIGNAL("textChanged(const QString)"), self
.updateSharedVars
)
56 self
.connect(self
.lp_author
, SIGNAL("textChanged(const QString)"), self
.updateSharedVars
)
57 self
.connect(self
.lp_composer
, SIGNAL("textChanged(const QString)"), self
.updateSharedVars
)
58 self
.connect(self
.lp_album
, SIGNAL("textChanged(const QString)"), self
.updateSharedVars
)
59 self
.connect(self
.spin_track
, SIGNAL("valueChanged(int)"), self
.updateSharedVars
)
60 self
.connect(self
.b_icon
, SIGNAL("iconChanged(QString)"), self
.updateSharedVars
)
62 shared
.loopBus
.add_signal_receiver(self
.updateLadishApps
, sender_keyword
='sender', destination_keyword
='dest', interface_keyword
='interface',
63 member_keyword
='member', path_keyword
='path')
66 def setTime(self
, which
):
67 time
= jack
.get_current_transport_frame() / jack
.get_sample_rate()
69 mins
= (time
/ 60) % 60
70 hrs
= (time
/ 3600) % 60
71 timeQ
= QTime(hrs
, mins
, secs
)
73 if (which
== "start"):
74 self
.timeStart
.setTime(timeQ
)
75 elif (which
== "end"):
76 self
.timeEnd
.setTime(timeQ
)
78 self
.updateSharedVars()
80 def updateTotalTime(self
):
81 timeStart
= self
.timeStart
.time()
82 timeEnd
= self
.timeEnd
.time()
83 timeStartFull
= (timeStart
.hour()*3600)+(timeStart
.minute()*60)+(timeStart
.second())
84 timeEndFull
= (timeEnd
.hour()*3600)+(timeEnd
.minute()*60)+(timeEnd
.second())
85 if (timeEndFull
>= timeStartFull
):
86 totalTime
= QTime(0, 0, 0).addSecs( timeEndFull
- timeStartFull
)
87 self
.l_totalTime
.setStyleSheet("")
89 totalTime
= QTime(0, 0, 0).addSecs( timeStartFull
- timeEndFull
)
90 self
.l_totalTime
.setStyleSheet("color: rgb(255, 0, 0);")
91 self
.l_totalTime
.setText(totalTime
.toString())
93 shared
.Globals
.sliderMinValue
= timeStartFull
94 shared
.Globals
.sliderMaxValue
= timeEndFull
96 self
.updateSharedVars()
98 def updateSharedVars(self
):
99 shared
.p_name
= self
.lp_name
.text()
100 shared
.p_author
= self
.lp_author
.text()
101 shared
.p_composer
= self
.lp_composer
.text()
102 shared
.p_album
= self
.lp_album
.text()
103 shared
.p_track
= self
.spin_track
.text()
104 shared
.p_time_start
= self
.timeStart
.time().toString()
105 shared
.p_time_end
= self
.timeEnd
.time().toString()
106 shared
.p_icon
= self
.b_icon
.icon()
108 def updateLadishApps(self
, *args
, **kwds
):
111 elif (kwds
['interface'] == "org.ladish.AppSupervisor"):
116 self
.listLadish
.setCurrentCell(-1, -1)
117 self
.listLadish
.clearContents()
118 for i
in range(self
.listLadish
.rowCount()):
119 self
.listLadish
.removeRow(i
)
121 ladi_apps
= shared
.appBus
.GetAll()
123 for i
in range(len(ladi_apps
[1])):
124 number
= QTableWidgetItem(str(ladi_apps
[1][i
][0]))
125 name
= QTableWidgetItem(str(ladi_apps
[1][i
][1]))
126 #name.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled)
127 if (int(ladi_apps
[1][i
][2])):
128 started
= QTableWidgetItem(i18n("Yes"))
130 started
= QTableWidgetItem(i18n("No"))
131 if (int(ladi_apps
[1][i
][3])):
132 terminal
= QTableWidgetItem(i18n("Yes"))
134 terminal
= QTableWidgetItem(i18n("No"))
135 level
= QTableWidgetItem(str(int(ladi_apps
[1][i
][4])))
136 self
.listLadish
.insertRow(i
)
137 self
.listLadish
.setItem(i
, 0, number
)
138 self
.listLadish
.setItem(i
, 1, name
)
139 self
.listLadish
.setItem(i
, 2, started
)
140 self
.listLadish
.setItem(i
, 3, terminal
)
141 self
.listLadish
.setItem(i
, 4, level
)
143 for g
in range(self
.listLadish
.rowCount()):
144 if (self
.listLadish
.item(g
, 0) == None):
145 self
.listLadish
.removeRow(g
)
147 def showLadishMenu(self
, pos
):
150 act_x_start
= cMenu
.addAction("&Start")
151 act_x_stop
= cMenu
.addAction("&Stop")
152 act_x_kill
= cMenu
.addAction("&Kill")
153 act_x_properties
= cMenu
.addAction("&Properties")
154 act_x_separator1
= cMenu
.addSeparator()
155 act_x_remove
= cMenu
.addAction("&Remove")
156 act_x_separator2
= cMenu
.addSeparator()
157 act_x_add
= cMenu
.addAction("&Add New...")
159 row
= self
.listLadish
.currentRow()
162 ladn
= int(self
.listLadish
.item(self
.listLadish
.currentRow(), 0).text())
167 act_x_start
.setVisible(False)
168 act_x_stop
.setVisible(False)
169 act_x_kill
.setVisible(False)
170 act_x_properties
.setVisible(False)
171 act_x_separator1
.setVisible(False)
172 act_x_separator2
.setVisible(False)
173 act_x_remove
.setVisible(False)
175 if (self
.listLadish
.item(row
, 2).text() == i18n("Yes")):
176 act_x_start
.setVisible(False)
178 act_x_stop
.setVisible(False)
179 act_x_kill
.setVisible(False)
182 self
.connect(act_x_add
, SIGNAL("triggered()"), self
.func_x_add
)
183 self
.connect(act_x_start
, SIGNAL("triggered()"), partial(self
.func_x_start
, ladn
))
184 self
.connect(act_x_stop
, SIGNAL("triggered()"), partial(self
.func_x_stop
, ladn
))
185 self
.connect(act_x_kill
, SIGNAL("triggered()"), partial(self
.func_x_kill
, ladn
))
186 self
.connect(act_x_properties
, SIGNAL("triggered()"), partial(self
.func_x_properties
, ladn
))
187 self
.connect(act_x_remove
, SIGNAL("triggered()"), partial(self
.func_x_remove
, ladn
))
189 # Show Menu at cursor position
190 newPos
= QCursor
.pos()
191 cMenu
.setGeometry(newPos
.x(), newPos
.y(), 0, 0)
194 def func_x_add(self
):
197 def func_x_start(self
, n
):
198 shared
.appBus
.StartApp(n
)
200 def func_x_stop(self
, n
):
201 shared
.appBus
.StopApp(n
)
203 def func_x_kill(self
, n
):
204 shared
.appBus
.KillApp(n
)
206 def func_x_properties(self
, n
):
209 PropertiesW().exec_()
211 def func_x_remove(self
, n
):
212 shared
.appBus
.RemoveApp(n
)
215 class NewAppW(QDialog
, ui_dia_properties
.Ui_PropertiesW
):
216 def __init__(self
, *args
):
217 QDialog
.__init
__(self
, *args
)
220 self
.r_lv0
.setChecked(True)
221 self
.buttonBox
.button(QDialogButtonBox
.Ok
).setEnabled(False)
223 self
.connect(self
.line_cmd
, SIGNAL("textChanged(QString)"), self
.checkText
)
224 self
.connect(self
, SIGNAL("accepted()"), self
.Done
)
226 def checkText(self
, text
):
228 self
.buttonBox
.button(QDialogButtonBox
.Ok
).setEnabled(False)
230 self
.buttonBox
.button(QDialogButtonBox
.Ok
).setEnabled(True)
233 if (self
.r_lv0
.isChecked()):
235 elif (self
.r_lv1
.isChecked()):
237 elif (self
.r_lv2
.isChecked()):
239 elif (self
.r_lv3
.isChecked()):
242 shared
.appBus
.RunCustom(False, str(self
.line_cmd
.text()), str(self
.line_name
.text()), int(lvl
))
245 class PropertiesW(QDialog
, ui_dia_properties
.Ui_PropertiesW
):
246 def __init__(self
, *args
):
247 QDialog
.__init
__(self
, *args
)
251 props
= shared
.appBus
.GetAppProperties(global_n
)
253 self
.line_name
.setText(str(props
[0]))
254 self
.line_cmd
.setText(str(props
[1]))
256 self
.ch_terminal
.setChecked(True)
257 if (int(props
[4]) == 0):
258 self
.r_lv0
.setChecked(True)
259 elif (int(props
[4]) == 1):
260 self
.r_lv1
.setChecked(True)
261 elif (int(props
[4]) == 2):
262 self
.r_lv2
.setChecked(True)
263 elif (int(props
[4]) == 3):
264 self
.r_lv3
.setChecked(True)
267 #self.line_name.setEnabled(False)
268 self
.line_cmd
.setEnabled(False)
269 self
.ch_terminal
.setEnabled(False)
270 self
.r_lv0
.setEnabled(False)
271 self
.r_lv1
.setEnabled(False)
272 self
.r_lv2
.setEnabled(False)
273 self
.r_lv3
.setEnabled(False)
275 self
.connect(self
, SIGNAL("accepted()"), self
.Done
)
278 if (self
.r_lv0
.isChecked()):
280 elif (self
.r_lv1
.isChecked()):
282 elif (self
.r_lv2
.isChecked()):
284 elif (self
.r_lv3
.isChecked()):
287 shared
.appBus
.SetAppProperties(global_n
, str(self
.line_name
.text()), str(self
.line_cmd
.text()), self
.ch_terminal
.isChecked(), lvl
)