-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller.py
70 lines (62 loc) · 1.77 KB
/
controller.py
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
import sys
import thread
import Tkinter as tk
import pygame as pg
import optionsModel
import optView
import tickerView
class Controller(object):
def __init__(self):
self.optModel = optionsModel.OptionsModel()
self.optView = optView.OptView(self)
try:
thread.start_new_thread(self.startPG,())
except:
print "Unable to start ticker"
tk.mainloop()
def startPG(self):
pg.init()
self.tickerView = tickerView.TickerView(self)
self.tickerView.notify(1)
self.tickerView.runEventLoop()
def setNewOptions(self):
self.optModel.setLeft(self.optView.getLeft())
self.optModel.setLaunch(self.optView.getLaunch())
self.optModel.setStop(self.optView.getStop())
self.optModel.setSync(self.optView.getSync())
self.optModel.setSpeed(self.optView.getSpeed())
self.tickerView.notify(1)
def getCurrentOptions(self):
options = {}
options["Left"] = self.optModel.getLeft()
options["Launch"] = self.optModel.getLaunch()
options["Stop"] = self.optModel.getStop()
options["Sync"] = self.optModel.getSync()
options["Speed"] = self.optModel.getSpeed()
options["URL"] = self.optModel.getURLs()
return options
def appendURL(self):
self.optModel.getURLs().append( \
self.optView.getURL())
self.optView.feedEntry.delete(0,tk.END)
def save(self):
file = open('options.xml', 'w')
print >> file, '<options>'
self.setNewOptions()
opts = self.getCurrentOptions()
for key in opts:
if key != "URL":
print >> file, ' <' + str(key) + '>' + \
str(opts[key]) + '</' + str(key) + '>'
else:
print >> file, ' <urls>'
for entry in opts[key]:
print >> file, ' <url>' + \
entry + '</url>'
print >> file, ' </urls>'
print >> file, '</options>'
file.close()
def quit(self):
sys.exit()
if __name__ == "__main__":
control = Controller()