1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
import sys,time,os
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QFileDialog, QListView, QStringListModel, QButtonGroup, QPushButton
class ParterMainwidget(QtGui.QWidget):
def __init__(self, parent=None, muse=None, partsdir=None):
QtGui.QWidget.__init__(self, parent)
self.muse = muse
self.partsdir = partsdir
self.lcurdir = QtGui.QLabel(partsdir)
moveupbutton = QPushButton("Parent dir")
appendbutton = QPushButton("Append")
putbutton = QPushButton("Put")
blayout = QtGui.QGridLayout()
blayout.addWidget(self.lcurdir)
blayout.addWidget(moveupbutton)
blayout.addWidget(appendbutton)
blayout.addWidget(putbutton)
self.tree = QtGui.QTreeView()
self.dirmodel = QtGui.QDirModel()
self.tree.setModel(self.dirmodel)
self.tree.setRootIndex(self.dirmodel.index(self.partsdir))
layout = QtGui.QGridLayout()
self.setLayout(layout)
layout.addWidget(self.tree, 0, 0)
layout.addLayout(blayout, 0, 1)
self.connect(moveupbutton, QtCore.SIGNAL('clicked()'), self.parentDir)
self.connect(appendbutton, QtCore.SIGNAL('clicked()'), self.appendPressed)
self.connect(putbutton, QtCore.SIGNAL('clicked()'), self.putPressed)
self.connect(self.tree, QtCore.SIGNAL('activated(QModelIndex)'), self.activated)
def parentDir(self):
f = QtCore.QFileInfo(self.partsdir)
self.changeDir(f.canonicalPath())
def changeDir(self, newdir):
self.partsdir = newdir
self.tree.setRootIndex(self.dirmodel.index(self.partsdir))
self.lcurdir.setText(self.partsdir)
def activated(self, s):
fileInfo = self.dirmodel.fileInfo(s)
if fileInfo.isDir():
self.changeDir(fileInfo.absoluteFilePath())
return
fname = str(fileInfo.absoluteFilePath()) # if not str() around it crashes!
self.putPart(fname)
def putPart(self, fname):
trackid = self.muse.getSelectedTrack()
if trackid == None:
return
cpos = self.muse.getCPos()
self.muse.importPart(trackid, fname, cpos)
def getSelectedItem(self):
selectionmodel = self.tree.selectionModel()
for i in selectionmodel.selectedIndexes():
fileInfo = self.dirmodel.fileInfo(i)
return str(fileInfo.absoluteFilePath())
return None
def appendPressed(self):
selected = self.getSelectedItem()
if selected == None:
return
trackid = self.muse.getSelectedTrack()
if trackid == None:
return
parts = self.muse.getParts(trackid)
if parts == None:
return
pos = 0
if len(parts) > 0:
part = parts[len(parts) - 1]
pos = part['tick'] + part['len']
print "Appending " + selected
self.muse.importPart(trackid, selected, pos)
def putPressed(self):
selected = self.getSelectedItem()
if selected == None:
return
trackid = self.muse.getSelectedTrack()
if trackid == None:
return
cpos = self.muse.getCPos()
self.muse.importPart(trackid, selected, cpos)
def testfunc2(self, index):
print str(index.row()) + " " + str(index.column())
print index.data().toString()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
mainw = ParterMainwidget()
mainw.show()
sys.exit(app.exec_())
|