2 # -*- coding: utf-8 -*-
6 from PyQt4
.QtCore
import Qt
, QSettings
, QString
, QVariant
, SIGNAL
7 from PyQt4
.QtGui
import QFileDialog
, QIcon
, QMainWindow
, QMessageBox
11 from klaudia_launcher
import KlaudiaLauncher
13 # Properly convert QString to str
14 def QStringStr(string
):
15 return str(unicode(string
).encode('utf-8'))
17 # QLineEdit and QPushButtom combo
18 def getAndSetPath(parent
, current_path
, lineEdit
):
19 new_path
= QFileDialog
.getExistingDirectory(parent
, parent
.tr("Set Path"), current_path
, QFileDialog
.ShowDirsOnly
)
20 if not new_path
.isEmpty():
21 lineEdit
.setText(new_path
)
36 class KlaudiaMainW(QMainWindow
, ui_klaudia
.Ui_KlaudiaMainW
):
37 def __init__(self
, parent
=None):
38 super(KlaudiaMainW
, self
).__init
__(parent
)
42 if DBus
.jackBus
and not bool(DBus
.jackBus
.IsStarted()):
44 DBus
.jackBus
.StartServer()
48 # Load Settings (GUI state)
49 self
.settings
= QSettings()
52 self
.launcher
= KlaudiaLauncher(self
, self
.settings
)
55 self
.b_start
.setIcon(self
.getIcon("go-next"))
56 self
.b_add
.setIcon(self
.getIcon("list-add"))
57 self
.b_refresh
.setIcon(self
.getIcon("view-refresh"))
58 self
.b_open
.setIcon(self
.getIcon("document-open"))
59 self
.b_start
.setEnabled(False)
60 self
.b_add
.setEnabled(False)
61 self
.setWindowIcon(self
.getIcon("klaudia"))
64 self
.test_selected
= False
65 self
.studio_root_folder
= QString(os
.getenv("HOME"))
67 self
.le_url
.setText(self
.studio_root_folder
)
68 self
.co_sample_rate
.addItem(str(DBus
.jackBus
.GetSampleRate()) if DBus
.jackBus
else "44100")
69 self
.b_refresh
.setText("")
71 self
.refreshStudioList()
74 self
.enableLADISH(True)
76 for path
in os
.getenv("PATH").split(":"):
77 if (os
.path
.exists(os
.path
.join(path
, "ladishd"))):
80 self
.enableLADISH(False)
82 self
.connect(self
.b_start
, SIGNAL("clicked()"), self
.launcher
.startApp
)
83 self
.connect(self
.b_add
, SIGNAL("clicked()"), self
.launcher
.addAppToLADISH
)
84 self
.connect(self
.b_refresh
, SIGNAL("clicked()"), self
.refreshStudioList
)
86 self
.connect(self
.co_ladi_room
, SIGNAL("currentIndexChanged(int)"), self
.checkSelectedRoom
)
87 self
.connect(self
.groupLADISH
, SIGNAL("toggled(bool)"), self
.enableLADISH
)
89 self
.connect(self
.le_url
, SIGNAL("textChanged(QString)"), self
.checkFolderUrl
)
91 self
.connect(self
.b_open
, SIGNAL("clicked()"), lambda: getAndSetPath(self
, self
.le_url
.text(), self
.le_url
))
93 def refreshStudioList(self
):
94 self
.co_ladi_room
.clear()
95 self
.co_ladi_room
.addItem("<Studio Root>")
97 studio_bus
= DBus
.loopBus
.get_object("org.ladish", "/org/ladish/Studio")
98 studio_list_dump
= studio_bus
.GetRoomList()
99 for i
in range(len(studio_list_dump
)):
100 self
.co_ladi_room
.addItem(str(studio_list_dump
[i
][0]).replace("/org/ladish/Room","")+" - "+studio_list_dump
[i
][1]['name'])
102 def checkSelectedRoom(self
, co_n
):
103 if (co_n
== -1 or not DBus
.controlBus
):
106 DBus
.studioBus
= DBus
.loopBus
.get_object("org.ladish", "/org/ladish/Studio")
107 DBus
.appBus
= dbus
.Interface(DBus
.studioBus
, 'org.ladish.AppSupervisor')
108 self
.b_open
.setEnabled(True)
109 self
.le_url
.setEnabled(True)
110 self
.le_url
.setText(self
.studio_root_folder
)
112 room_number
= QStringStr(self
.co_ladi_room
.currentText()).split(" ")[0]
113 room_name
= "/org/ladish/Room"+room_number
114 DBus
.studioBus
= DBus
.loopBus
.get_object("org.ladish", room_name
)
115 DBus
.appBus
= dbus
.Interface(DBus
.studioBus
, 'org.ladish.AppSupervisor')
116 room_properties
= DBus
.studioBus
.GetProjectProperties()
117 if (len(room_properties
[1]) > 0):
118 self
.b_open
.setEnabled(False)
119 self
.le_url
.setEnabled(False)
120 self
.le_url
.setText(QString(room_properties
[1]['dir']))
122 self
.b_open
.setEnabled(True)
123 self
.le_url
.setEnabled(True)
124 self
.studio_root_folder
= self
.le_url
.text()
126 def enableLADISH(self
, yesno
):
127 self
.groupLADISH
.setCheckable(False)
131 DBus
.controlBus
= DBus
.loopBus
.get_object("org.ladish", "/org/ladish/Control")
132 self
.groupLADISH
.setTitle(self
.tr("LADISH is enabled"))
134 self
.groupLADISH
.setEnabled(False)
135 self
.groupLADISH
.setTitle(self
.tr("LADISH is sick"))
138 DBus
.studioBus
= DBus
.loopBus
.get_object("org.ladish", "/org/ladish/Studio")
139 DBus
.appBus
= dbus
.Interface(DBus
.studioBus
, 'org.ladish.AppSupervisor')
141 self
.refreshStudioList()
145 self
.groupLADISH
.setEnabled(False)
146 self
.groupLADISH
.setTitle(self
.tr("LADISH is not available"))
148 def checkGUI(self
, test_selected
=None):
149 if (test_selected
!= None):
150 self
.test_selected
= test_selected
152 if (self
.test_url
and self
.test_selected
):
153 self
.b_add
.setEnabled(bool(DBus
.controlBus
))
154 self
.b_start
.setEnabled(True)
156 self
.b_add
.setEnabled(False)
157 self
.b_start
.setEnabled(False)
159 def checkFolderUrl(self
, qurl
):
160 url
= QStringStr(qurl
)
161 if (os
.path
.exists(url
)):
163 if (self
.le_url
.isEnabled()):
164 self
.studio_root_folder
= url
166 self
.test_url
= False
170 return not self
.le_url
.isEnabled()
172 def isOldLadish(self
):
174 DBus
.loopBus
.get_object("org.ladish", "/org/ladish/LashServer")
183 def getSampleRate(self
):
184 srate_try
= self
.co_sample_rate
.currentText().toInt()
185 return srate_try
[0] if srate_try
[1] else 44100
188 bpm_try
= self
.sb_bpm
.text().toInt()
189 return bpm_try
[0] if bpm_try
[1] else 130.0
191 def getProjectFolder(self
):
192 return self
.le_url
.text()
194 def getIcon(self
, icon
):
195 return QIcon
.fromTheme(icon
, QIcon(""))
197 def saveSettings(self
):
198 self
.settings
.setValue("Geometry", QVariant(self
.saveGeometry()))
199 self
.launcher
.saveSettings()
201 def loadSettings(self
):
202 self
.restoreGeometry(self
.settings
.value("Geometry").toByteArray())
204 def closeEvent(self
, event
):
206 return QMainWindow
.closeEvent(self
, event
)