Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 168 lines (130 sloc) 5.332 kB
5bf1bd3 @armooo Fixed new lines
armooo authored
1 from Tkinter import *
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
2 import tkSimpleDialog, tkFileDialog
3 import os, sys, ConfigParser
5bf1bd3 @armooo Fixed new lines
armooo authored
4
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
5 class EditShare(tkSimpleDialog.Dialog):
5bf1bd3 @armooo Fixed new lines
armooo authored
6
cc83d9b @wmcbrine auto_subshares is no longer needed, either.
authored
7 def __init__(self, parent, title=None, name='', path='', plugin=''):
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
8 self.name = name
9 self.path = path
10 self.plugin = StringVar()
11 self.plugin.set(plugin)
12 tkSimpleDialog.Dialog.__init__(self, parent, title)
5bf1bd3 @armooo Fixed new lines
armooo authored
13
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
14 def get_dir(self):
15 self.e2.delete(0, END)
16 self.e2.insert(0, os.path.normpath(tkFileDialog.askdirectory()))
5bf1bd3 @armooo Fixed new lines
armooo authored
17
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
18 def body(self, master):
19 Label(master, text="Name:").grid(row=0)
20 Label(master, text="Path:").grid(row=1)
5bf1bd3 @armooo Fixed new lines
armooo authored
21
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
22 self.e1 = Entry(master)
23 self.e2 = Entry(master)
5bf1bd3 @armooo Fixed new lines
armooo authored
24
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
25 if self.name:
26 self.e1.insert(0, self.name)
27 if self.path:
28 self.e2.insert(0, self.path)
5bf1bd3 @armooo Fixed new lines
armooo authored
29
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
30 browse = Button(master, text="Browse", command=self.get_dir)
5bf1bd3 @armooo Fixed new lines
armooo authored
31
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
32 self.e1.grid(row=0, column=1, columnspan=2, sticky=W+E)
33 self.e2.grid(row=1, column=1, sticky=W+E)
34 browse.grid(row=1, column=2)
5bf1bd3 @armooo Fixed new lines
armooo authored
35
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
36 if not self.plugin.get():
37 self.plugin.set('video')
5bf1bd3 @armooo Fixed new lines
armooo authored
38
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
39 for i, name in zip(xrange(3), ('video', 'music', 'photo')):
40 b = Radiobutton(master, text=name, variable=self.plugin,
cc83d9b @wmcbrine auto_subshares is no longer needed, either.
authored
41 value=name).grid(row=i, column=3)
5bf1bd3 @armooo Fixed new lines
armooo authored
42
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
43 return self.e1 # initial focus
5bf1bd3 @armooo Fixed new lines
armooo authored
44
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
45 def apply(self):
46 name = self.e1.get()
47 path = self.e2.get()
cc83d9b @wmcbrine auto_subshares is no longer needed, either.
authored
48 self.result = name, path, self.plugin.get()
5bf1bd3 @armooo Fixed new lines
armooo authored
49
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
50 class pyTivoConfigurator(Frame):
5bf1bd3 @armooo Fixed new lines
armooo authored
51
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
52 section = None
53
54 def buildContainerList(self):
55 header = Frame(self)
56 header.pack(fill=X)
57 Label(header, text='Shares').pack(side=LEFT)
58 frame = Frame(self)
59 frame.pack(fill=BOTH, expand=1)
60 scrollbar = Scrollbar(frame, orient=VERTICAL)
61 self.container_list = Listbox(frame, yscrollcommand=scrollbar.set)
62 scrollbar.config(command=self.container_list.yview)
63 scrollbar.pack(side=RIGHT, fill=Y)
64 self.container_list.pack(side=LEFT, fill=BOTH, expand=1)
65 self.container_list.bind("<Double-Button-1>", self.selected)
66
67 def selected(self, e):
68 if not self.container_list.curselection():
69 return
70 index = self.container_list.curselection()[0]
71 self.section = self.container_list.get(index)
72
73 self.edit()
74
75 def buildButtons(self):
76 frame = Frame(self)
77 frame.pack(fill=X)
78
79 quit_button = Button(frame, text="Quit", command=self.quit)
80 quit_button.pack(side=RIGHT)
81
82 del_button = Button(frame, text='Del', command=self.delete)
83 del_button.pack(side=RIGHT)
84
85 add_button = Button(frame, text="Add", command=self.add)
86 add_button.pack(side=RIGHT)
87
88 if sys.platform == 'win32':
89 restart_button = Button(frame, text="Restart pyTivo",
90 command=self.restart)
91 restart_button.pack(side=RIGHT)
5bf1bd3 @armooo Fixed new lines
armooo authored
92
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
93 def add(self):
94 share = EditShare(self, title='New Share')
95 if share.result:
cc83d9b @wmcbrine auto_subshares is no longer needed, either.
authored
96 sharename, path, plugin = share.result
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
97 self.config.add_section(sharename)
98 self.config.set(sharename, 'type', plugin)
99 self.config.set(sharename, 'path', path)
100 self.updateContainerList()
101
102 def delete(self):
103 if not self.container_list.curselection():
104 return
105 index = self.container_list.curselection()[0]
106 section = self.container_list.get(index)
107 self.config.remove_section(section)
108 self.updateContainerList()
109
110 def restart(self):
111 import win32serviceutil
112 self.writeConfig()
113 win32serviceutil.RestartService('pyTivo')
114
115 def edit(self):
116 if not self.section:
117 return
118
119 name = self.section
120 path = self.config.get(name, 'path')
121 plugin = self.config.get(name, 'type')
122
123 share = EditShare(self, title='Edit Share', name=name, path=path,
cc83d9b @wmcbrine auto_subshares is no longer needed, either.
authored
124 plugin=plugin)
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
125 if share.result:
cc83d9b @wmcbrine auto_subshares is no longer needed, either.
authored
126 name, path, plugin = share.result
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
127 if name != self.section:
128 self.config.remove_section(self.section)
129 self.config.add_section(name)
130 self.section = name
131 self.config.set(name, 'type', plugin)
132 self.config.set(name, 'path', path)
5bf1bd3 @armooo Fixed new lines
armooo authored
133 self.updateContainerList()
134
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
135 def updateContainerList(self):
136 self.writeConfig()
137 self.container_list.delete(0, END)
138 for section in self.config.sections():
139 if not section == 'Server':
140 self.container_list.insert(END, section)
141
142 def readConfig(self):
143 self.config = ConfigParser.ConfigParser()
144 self.config.read(self.config_file)
145
146 def writeConfig(self):
147 self.config.write(open(self.config_file, 'w'))
148
149 def __init__(self, master=None):
150 Frame.__init__(self, master)
151 self.master.title('pyTivoConfigurator')
152 self.pack(fill=BOTH, expand=1)
153
154 p = os.path.dirname(__file__)
155 self.config_file = os.path.join(p, 'pyTivo.conf')
156
157 self.readConfig()
158
159 self.buildContainerList()
160 self.buildButtons()
5bf1bd3 @armooo Fixed new lines
armooo authored
161
80d8711 @wmcbrine A slightly more sophisticated pyTivoConfigurator. Much more to do.
authored
162 self.updateContainerList()
5bf1bd3 @armooo Fixed new lines
armooo authored
163
164 if __name__ == '__main__':
165 root = Tk()
166 app = pyTivoConfigurator(master=root)
167 app.mainloop()
Something went wrong with that request. Please try again.