Code cleanup
[klaudia.git] / src / tb_apps.py
blob559f7d02ce128711de8af5032e02353b3680035e
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
5 # Imports
6 import os
7 from commands import getoutput
8 from random import randint
9 from PyQt4.QtCore import Qt, SIGNAL
10 from PyQt4.QtGui import QTableWidgetItem, QWidget
11 from PyKDE4.kdeui import KIcon
12 import shared, tb_main, ui_tb_apps, find_plugins
15 # Main Window
16 class AppsW(QWidget, ui_tb_apps.Ui_AppsW):
17 def __init__(self, *args):
18 QWidget.__init__(self, *args)
19 self.setupUi(self)
21 self.b_add.setEnabled(False)
22 self.b_add.setIcon(KIcon("list-add"))
23 #self.b_addc.setEnabled(False)
24 self.b_addc.setIcon(KIcon("list-add"))
25 self.b_refresh.setIcon(KIcon("view-refresh"))
27 self.listDAW.setColumnWidth(0, 32)
28 self.listDAW.setColumnWidth(1, 400)
29 self.listDAW.setColumnWidth(2, 100)
30 self.listDAW.setColumnWidth(3, 75)
31 self.listDAW.setColumnWidth(4, 75)
33 self.connect(self.b_refresh, SIGNAL("clicked()"), self.refreshFull)
34 self.connect(self.b_add, SIGNAL("clicked()"), self.addApplication)
35 self.connect(self.b_addc, SIGNAL("clicked()"), self.addCustom)
36 self.connect(self.listDAW, SIGNAL("currentCellChanged(int, int, int, int)"), self.updateButtons)
38 self.refreshFull()
41 def addApplication(self):
42 tab = self.tabWidget.currentIndex()
43 if (tab == 0):
44 listSel = self.listDAW
45 elif (tab == 1):
46 listSel = self.listHosts
47 elif (tab == 2):
48 listSel = self.listSynths
49 elif (tab == 3):
50 listSel = self.listEffects
51 elif (tab == 4):
52 listSel = self.listTools
53 elif (tab == 5):
54 listSel = self.listBristol
55 elif (tab == 6):
56 listSel = self.listVSTs
58 app = listSel.item(listSel.currentRow(), 1).text()
60 if (app == "Renoise"):
61 ran_check = str(randint(1, 99999))
62 os.mkdir(shared.p_folder+"/tmp_bu")
63 os.system("cp "+shared.Path+"/../templates/Renoise.xml "+shared.p_folder+"/tmp_bu")
64 os.system('sed -i "s/X_BPM_X-KLAUDIA-X_BPM_X/'+str(shared.p_bpm)+'/" '+str(shared.p_folder)+'/tmp_bu/Renoise.xml')
65 os.system("cd "+str(shared.p_folder)+"/tmp_bu && mv Renoise.xml Song.xml && zip ../Renoise_"+ran_check+".xrns Song.xml")
66 os.system("rm -rf "+str(shared.p_folder)+"/tmp_bu")
67 shared.appBus.RunCustom(False, "renoise "+str(shared.p_folder)+"/Renoise_"+ran_check+".xrns", "Renoise", 0)
69 def addCustom(self):
70 tb_main.NewAppW().exec_()
72 def refreshFull(self):
73 self.listDAW.clearContents()
74 for i in range(self.listDAW.rowCount()):
75 self.listDAW.removeRow(i)
77 plugins = find_plugins.findAll()
78 #print plugins
80 for h in range(len(plugins)):
81 if (plugins[h][5] == "DAW"):
82 name = QTableWidgetItem(plugins[h][0])
83 binary = QTableWidgetItem(plugins[h][1])
84 icon = QTableWidgetItem("")
85 icon.setIcon(KIcon(plugins[h][2]))
86 version = QTableWidgetItem(plugins[h][3])
87 level = QTableWidgetItem(plugins[h][4])
88 path = QTableWidgetItem(plugins[h][6])
89 self.listDAW.insertRow(h)
90 self.listDAW.setItem(h, 0, icon)
91 self.listDAW.setItem(h, 1, name)
92 self.listDAW.setItem(h, 2, path)
93 self.listDAW.setItem(h, 3, binary)
94 self.listDAW.setItem(h, 4, version)
95 self.listDAW.setItem(h, 5, level)
97 for g in range(self.listDAW.rowCount()):
98 if (self.listDAW.item(g, 0) == None):
99 self.listDAW.removeRow(g)
101 self.listDAW.sortByColumn(1, Qt.AscendingOrder)
104 def updateButtons(self, a, b, c, d):
105 if (a >= 0):
106 self.b_add.setEnabled(True)
107 else:
108 self.b_add.setEnabled(False)