[go: up one dir, main page]

Menu

[r2]: / moblrcClientS60.py  Maximize  Restore  History

Download this file

244 lines (207 with data), 6.6 kB

  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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# MobLRC PyS60 Client - Mobile Linux Remote Control PyS60 Client
# Copyright (C) 2006 PoisoneR
# Author: PoisoneR
# License: GPL
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Todo
# smenq proramata edin put i podawa komanda
# return song name and artist
# login password
# volume repeat command some times, w dict-a da ima list i da se izpulnqwat wsi4ki elementi
# start program if it is not
# proper quit
# choose better port than 7777
# log with date from now() function, all print messages to have date
__author__ = "PoisoneR"
__version__ = "0.1.1"
__copyright__ = "(c) 2006 PoisoneR <poisonerbg@gmail.com>"
__projecthome__ = "http://moblrc.sourceforge.net"
# Todo
# reciving current song
# listen sus select, i send ednowremmeno
# shortcut keys
from socket import socket, AF_INET, SOCK_STREAM
import e32
import appuifw
from os import path
PORT = 7777
class client:
def __init__(self):
self.confFile = u'c:\\moblrc.conf'
self.getHost()
def newHost(self):
self.hostname = appuifw.query(u'Type hostname with your MobLRC server', 'text')
self.saveHost()
def connect(self):
if (self.hostname == ''):
self.newHost()
if (self.hostname == u''):
self.newHost()
self.sockobj = socket(AF_INET, SOCK_STREAM)
self.sockobj.connect((self.hostname, PORT))
self.readsocks = [self.sockobj]
self.writesocks = [self.sockobj]
appuifw.note(u'Connected', 'info')
def getHost(self):
if path.exists(self.confFile):
f = open(self.confFile, 'r')
self.hostname = f.readline()
f.close()
else:
return False
if self.hostname == '':
return False
else:
return True
def saveHost(self):
# problem here cant save it
f = open(self.confFile, 'w')
f.write(self.hostname)
f.close()
def loop(self):
done = False
while not done:
#cmd = appuifw.query(u'Type your command', 'text')
cmd = appuifw.popup_menu(self.menu, u'Send command')
cmd = self.commands[cmd]
data = self.send(cmd)
appuifw.note(u'Command sent:' + data, 'info')
if cmd == 'quit':
done = True
break
def send(self, cmd):
self.sockobj.send(cmd)
data = self.sockobj.recv(1024)
return data
def disconnect(self):
self.sockobj.close()
def __del__(self):
self.disconnect()
class amarok:
def __init__(self):
self.prev = ['aV', u'Prev']
self.pause = ['aA', u'Pause']
self.play = ['aP', u'Play']
self.stop = ['aS', u'Stop']
self.next = ['aN', u'Next']
self.mute = ['aM', u'Mute']
self.volUp = ['aU', u'Volume Up']
self.volDown = ['aD', u'Volume DOwn']
self.quit = ['aQ', u'Quit']
class MobLRCApp:
def __init__(self):
self.lock = e32.Ao_lock()
appuifw.app.title = u'MobLRC'
self.text = appuifw.Text()
self.text.style = appuifw.STYLE_BOLD
self.text.color = (0, 64, 204)
self.text.font = u'albi17b'
self.exitFlag = False
self.amarok = amarok()
# can be added fast forward and fast rewind
self.menu = [(u'Control Amarok', ((u'Play [1]', self.handlePlay),
(u'Pause [2]', self.handlePause),
(u'Stop [3]', self.handleStop),
(u'Previous song [4]', self.handlePrev),
(u'Volume Up [5]', self.handleVolUp),
(u'Next song [6]', self.handleNext),
(u'Volume Down [8]', self.handleVolDown),
(u'Mute On/Off[0]', self.handleMute),
(u'Quit', self.handleQuit) )),
(u'Change host', self.handleConnect),
(u'About', self.handleClose),
(u'Exit', self.handleClose)
]
appuifw.app.menu = []
self.amarokApp = appuifw.Text(u'Amarok')
self.kaffeineApp = appuifw.Text(u'Kaffeine')
appuifw.app.set_tabs([u'Amarok', u'Kaffeine'], self.handleTab)
appuifw.app.body = self.amarokApp
self.connect()
def connect(self):
try:
self.client = client()
self.client.connect()
except:
appuifw.note(u'Cannot connect to server. Is it running?', 'info')
# must be error, intstead info
def handleTab(self, index):
global lb
if index == 0:
appuifw.app.body = self.amarokApp
elif index == 1:
appuifw.app.body = self.kaffeineApp
def loop(self):
try:
#self.lock.wait()
while not self.exitFlag:
self.refresh()
self.lock.wait()
finally:
self.handleClose()
def close(self):
appuifw.app.menu = []
appuifw.app.body = None
appuifw.app.exit_key_handler = None
appuifw.app.title = u'Closing...'
def abort(self):
# Exit-key hanler.
self.exitFlag = True
self.lock.signal()
def refresh(self):
#currentItem = self.getCurrentItem()
#appuifw.app.body = appuifw.Listbox(self.list, self.load)
appuifw.app.menu = self.menu
def execCmd(self, cmdlist):
output = self.client.send(cmdlist[0])
appuifw.note(cmdlist[1] + output, 'info')
def handlePrev(self):
self.execCmd(self.amarok.prev)
def handlePlay(self):
self.execCmd(self.amarok.play)
def handlePause(self):
self.execCmd(self.amarok.pause)
def handleStop(self):
self.execCmd(self.amarok.stop)
def handleNext(self):
self.execCmd(self.amarok.next)
def handleMute(self):
self.execCmd(self.amarok.mute)
def handleVolUp(self):
self.execCmd(self.amarok.volUp)
def handleVolDown(self):
self.execCmd(self.amarok.volDown)
def handleQuit(self):
self.execCmd(self.amarok.quit)
def handleClose(self):
self.client.disconnect()
self.close()
self.abort()
appuifw.app.set_exit()
def handleConnect(self):
self.connect()
def handleTest(self):
print u'Test print'
def getCurrentItem(self):
current = appuifw.app.body.current()
return self.list[current]
def getCurrentId(self):
return appuifw.app.body.current()
def main():
app = MobLRCApp()
try:
app.loop()
finally:
app.close()
if __name__ == '__main__':
main()