Removed unneeded HDtivosonly setting
[pyTivo/wmcbrine.git] / pyTivoConfigurator.pyw
blobaa69216705e42669731aac838d2c81ac21370d4c
1 from Tkinter import *
2 import ConfigParser
4 class pyTivoConfigurator(Frame):
6         section = None
7         
8         def buildContainerList(self):
9             frame = Frame(self)
10             frame.pack(fill=BOTH, expand=1)
11             scrollbar = Scrollbar(frame, orient=VERTICAL)
12             self.container_list = Listbox(frame, yscrollcommand=scrollbar.set)
13             scrollbar.config(command=self.container_list.yview)
14             scrollbar.pack(side=RIGHT, fill=Y)
15             self.container_list.pack(side=LEFT, fill=BOTH, expand=1)
16             self.container_list.bind("<Double-Button-1>", self.selected)
18         def selected(self, e):
19             if not self.container_list.curselection(): 
20                 return
21             index = self.container_list.curselection()[0]
22             self.section = self.container_list.get(index)
24             self.updatePath()
26         def buildButtons(self):
27             frame = Frame(self)
28             frame.pack(fill=X)
30             save_button = Button(frame, text="Save", command=self.save)
31             save_button.pack(side=RIGHT)
33             add_button = Button(frame, text="Add", command=self.add)
34             add_button.pack(side=RIGHT)
36             restart_button = Button(frame, text="Restart pyTivo", command=self.restart)
37             restart_button.pack(side=RIGHT)
39         def save(self):
40             self.writeConfig()
42         def add(self):
43             import tkSimpleDialog
44             sharename = tkSimpleDialog.askstring('Add share', 'Share Name')
45             self.config.add_section(sharename)
46             self.config.set(sharename, 'type', 'video')
47             self.config.set(sharename, 'path', '<Pick A Path>')
49             self.updateContainerList()
51         def restart(self):
52             import win32serviceutil
53             self.writeConfig()
54             win32serviceutil.RestartService('pyTivo')
56         def buildPath(self):
57             frame = Frame(self)
58             frame.pack(fill=X)
59             l = Label(frame, text="Path")
60             l.pack(side=LEFT)
62             button = Button(frame, text="Browse", command=self.setPath)
63             button.pack(side=RIGHT)
65             self.path = Entry(frame)
66             self.path.pack(side=RIGHT, fill=X, expand=1)
69         def setPath(self):
70             if not self.section:
71                 return
72             import tkFileDialog
73             dir = tkFileDialog.askdirectory()
74             
75             self.config.set(self.section, 'path', dir)
76             self.updatePath()
77             
78         def updatePath(self):
79             if not self.section or not self.config.get(self.section, 'path'):
80                 return
82             self.path.delete(0, END)
83             self.path.insert(0, self.config.get(self.section, 'path'))
85         def updateContainerList(self):
86             self.container_list.delete(0, END)
87             for section in self.config.sections():
88                 if not section == 'Server':
89                     self.container_list.insert(END, section)
91         def readConfig(self):
92             self.config = ConfigParser.ConfigParser()
93             self.config.read(self.config_file)
95         def writeConfig(self):
96             self.config.write(open(self.config_file, 'w'))
98         def __init__(self, master=None):
99             Frame.__init__(self, master)
100             self.master.title('pyTivoConfigurator')
101             self.pack(fill=BOTH, expand=1)
103             import os
104             p = os.path.dirname(__file__)
105             self.config_file = os.path.join(p, 'pyTivo.conf')
107             self.readConfig()
109             self.buildContainerList()
110             self.buildPath()
111             self.buildButtons()
113             self.updateContainerList()
117 if __name__ == '__main__':
118     root = Tk()
119     app = pyTivoConfigurator(master=root)
120     app.mainloop()