3 from PyQt4
.QtCore
import SIGNAL
,SLOT
,Qt
4 from PyQt4
.QtCore
import QPoint
5 from PyQt4
.QtCore
import QString
6 from PyQt4
.QtCore
import QSettings
7 from PyQt4
.QtCore
import QDir
8 from PyQt4
.QtCore
import QCoreApplication
10 from PyQt4
.QtGui
import QWidget
11 from PyQt4
.QtGui
import QLabel
12 from PyQt4
.QtGui
import QMainWindow
13 from PyQt4
.QtGui
import QSlider
14 from PyQt4
.QtGui
import QFileDialog
15 from PyQt4
.QtGui
import QIcon
17 from mprocess
import MProcess
18 from ui_mainwindow
import Ui_MainWindow
20 class MainWindow(QMainWindow
,Ui_MainWindow
):
21 def __init__(self
, parent
= None):
22 super(MainWindow
, self
).__init
__(parent
)
25 ##Quit if close this window
26 self
.setAttribute(Qt
.WA_QuitOnClose
)
27 self
.settings
= QSettings(QDir
.home().absolutePath().append(QDir
.separator()) + ".KRepeater",
28 QSettings
.NativeFormat
,self
)
29 self
.currDir
= QDir(self
.settings
.value("LastPath").toString())
31 self
.statusLabel
= QLabel()
32 self
.statusBar
.addWidget(self
.statusLabel
)
34 ##Set up the volume slide widget for setting volume
35 self
.volumeSlide
= QSlider(self
)
36 self
.volumeSlide
.hide()
37 self
.volumeSlide
.setFocusPolicy(Qt
.NoFocus
)
38 self
.volumeSlide
.resize(15,110)
39 self
.volumeSlide
.setRange(0,100)
40 self
.volumeSlide
.setValue(60) # Write to config later
42 #Create a mprocess object to control mplayer process
43 self
.mprocess
= MProcess(self
.videoWidget
.winId(),self
)
45 self
.mprocess
.setSlider(self
.slider
)
47 self
.connect(self
.pauseBtn
, SIGNAL("clicked()"),
50 self
.connect(self
.stopBtn
, SIGNAL("clicked()"),
53 self
.connect(self
.stopBtn
, SIGNAL("clicked()"),
56 self
.connect(self
.volumeBtn
, SIGNAL("toggled(bool)"),
57 self
.volumeBtnToggled
)
59 self
.connect(self
.volumeSlide
, SIGNAL("valueChanged(int)"),
60 self
.mprocess
.setVolume
)
62 self
.connect(self
.openAction
,SIGNAL("triggered()"),
65 self
.connect(self
.openBtn
,SIGNAL("clicked()"),
68 self
.connect(self
.mprocess
,SIGNAL("updateStatus()"),
71 self
.connect(self
.aBtn
, SIGNAL("toggled(bool)"),self
.pointA
)
72 self
.connect(self
.bBtn
, SIGNAL("toggled(bool)"),self
.pointB
)
74 #END def __init__(self, parent = None)
76 def showVolumeSlide(self
):
77 globalPoint
= self
.btnWidget
.mapToGlobal(self
.volumeBtn
.pos())
78 newPoint
= self
.mapFromGlobal(globalPoint
) \
79 + QPoint(self
.volumeBtn
.width(),
80 self
.volumeBtn
.height() - self
.volumeSlide
.height())
81 self
.volumeSlide
.move(newPoint
)
82 self
.volumeSlide
.show()
83 #END def showVolumeSlide(self)
85 def volumeBtnToggled(self
,checked
):
87 self
.volumeBtn
.setChecked(True)
88 self
.showVolumeSlide()
90 self
.volumeBtn
.setChecked(False)
91 self
.volumeSlide
.hide()
92 #END def volumeBtnToggled(self,checked):
94 def mouseReleaseEvent(self
,event
):
95 self
.volumeBtnToggled(False)
96 #END def mouseReleasedEvent(self,event)
99 fileName
= str(QFileDialog
.getOpenFileName(self
,
101 self
.currDir
.path()))
102 if(len(fileName
) == 0):
105 n
= fileName
.rfind(str(QDir
.separator().toAscii()))
106 self
.currDir
.setPath(fileName
[0:n
])
107 self
.settings
.setValue("LastPath",self
.currDir
.path())
109 self
.mprocess
.setFileName(fileName
)
111 #END def openFile(self)
115 self
.pauseBtn
.setEnabled(True)
116 self
.stopBtn
.setEnabled(True)
117 self
.aBtn
.setEnabled(True)
118 self
.pauseBtn
.setIcon(QIcon(":/pause.png"))
122 self
.pauseBtn
.setIcon(QIcon(":/play.png"))
123 self
.pauseBtn
.setEnabled(False)
124 self
.stopBtn
.setEnabled(False)
125 self
.slider
.setValue(0)
126 QCoreApplication
.processEvents()
127 #END def stopped(self):
135 self
.mprocess
.pause()
136 print "self.mprocess.playerState ", self
.mprocess
.playerState
137 if(self
.mprocess
.playerState
== MProcess
.PAUSED
):
138 self
.pauseBtn
.setIcon(QIcon(":/play.png"))
140 self
.pauseBtn
.setIcon(QIcon(":/pause.png"))
141 #END def pause(self):
144 if(self
.aBtn
.isChecked()):
146 self
.bBtn
.setEnabled(True)
148 self
.mprocess
.cleanPoints()
149 self
.bBtn
.setChecked(False)
150 self
.bBtn
.setEnabled(False)
151 #END def pointA(self):
154 if(self
.bBtn
.isChecked()):
157 self
.mprocess
.cleanPoints()
158 self
.aBtn
.setChecked(False)
159 self
.bBtn
.setChecked(False)
161 self
.aBtn
.setEnabled(True)
162 self
.bBtn
.setEnabled(False)
163 #END def pointB(self):
165 def setStatusInfo(self
):
166 colPre
= '<font color="white">'
169 if(self
.mprocess
.timeLength
!= None):
170 message
= str(int(self
.mprocess
.timePos
)*100/int(self
.mprocess
.timeLength
))
175 if(self
.mprocess
.timePos
!= None):
177 message
+= str(self
.mprocess
.timePos
)
180 if(self
.mprocess
.pa
!= None):
181 message
+= "A=" + str(self
.mprocess
.pa
)
183 if(self
.mprocess
.pb
!= None):
184 message
+= "B=" + str(self
.mprocess
.pb
)
186 self
.statusLabel
.setText(QString(colPre
+ message
+ colBak
))
187 #END def setStatusInfo(self, currProcess, pa, pb, status):
189 #END class MainWindow(QMainWindow,Ui_MainWindow)