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
|
from PyQt4 import QtGui, QtCore
import time
from clMonty import monty
from misc import *
from traceback import print_exc
from clSettings import settings
class winConnect(QtGui.QWidget):
txtHost=None
txtPort=None
lblInfo=None
_timerID=None
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.txtHost=QtGui.QLineEdit(settings.get('host', 'localhost'))
self.txtPort=QtGui.QLineEdit(settings.get('port', '6600'))
self.lblInfo=QtGui.QLabel("connecting ...")
frame=QtGui.QVBoxLayout()
inputs=QtGui.QHBoxLayout()
frame.addLayout(inputs)
frame.addWidget(self.lblInfo)
inputs.addWidget(self.txtHost)
inputs.addWidget(self.txtPort)
self.setWindowIcon(appIcon)
self.setWindowTitle('Connect to mpd')
self.setLayout(frame)
self.resize(200,80)
self.center()
doEvents()
monty.addListener('onReady', self.onReady)
monty.addListener('onConnect', self.onConnect)
def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2+100)
def monitor(self):
self.txtHost.setEnabled(True)
self.txtPort.setEnabled(True)
if self._timerID==None:
self._timerID=self.startTimer(200)
if self.isVisible()==False:
self.show()
self.activateWindow()
self.raise_()
doEvents()
def onConnect(self, params):
if self._timerID:
self.killTimer(self._timerID)
self._timerID=None
self.lblInfo.setText('Connected!\nRestoring library and playlist ...')
doEvents()
settings.set('host', str(self.txtHost.text()))
settings.set('port', str(self.txtPort.text()))
self.txtHost.setEnabled(False)
self.txtPort.setEnabled(False)
doEvents()
def onReady(self, params):
self.hide()
def timerEvent(self, event):
host=str(self.txtHost.text())
try:
port=int(self.txtPort.text())
except:
self.lblInfo.setText('Invalid port')
return
self.lblInfo.setText('Trying to connect to '+host+':'+str(port)+' ...')
doEvents()
monty.connect(host, port)
doEvents()
def windowActivationChange(self, bool):
self.activateWindow()
self.raise_()
doEvents()
|