| 2 | | import os, ConfigParser |
|---|
| | 2 | import tkSimpleDialog, tkFileDialog |
|---|
| | 3 | import os, sys, ConfigParser |
|---|
| | 4 | |
|---|
| | 5 | class EditShare(tkSimpleDialog.Dialog): |
|---|
| | 6 | |
|---|
| | 7 | def __init__(self, parent, title=None, name='', path='', plugin='', |
|---|
| | 8 | subshares=0): |
|---|
| | 9 | self.name = name |
|---|
| | 10 | self.path = path |
|---|
| | 11 | self.plugin = StringVar() |
|---|
| | 12 | self.plugin.set(plugin) |
|---|
| | 13 | self.subshares = IntVar() |
|---|
| | 14 | self.subshares.set(subshares) |
|---|
| | 15 | tkSimpleDialog.Dialog.__init__(self, parent, title) |
|---|
| | 16 | |
|---|
| | 17 | def get_dir(self): |
|---|
| | 18 | self.e2.delete(0, END) |
|---|
| | 19 | self.e2.insert(0, os.path.normpath(tkFileDialog.askdirectory())) |
|---|
| | 20 | |
|---|
| | 21 | def sub_show(self): |
|---|
| | 22 | if self.plugin.get() == 'video': |
|---|
| | 23 | self.subbutt.grid(row=2, column=1) |
|---|
| | 24 | else: |
|---|
| | 25 | self.subbutt.grid_forget() |
|---|
| | 26 | |
|---|
| | 27 | def body(self, master): |
|---|
| | 28 | Label(master, text="Name:").grid(row=0) |
|---|
| | 29 | Label(master, text="Path:").grid(row=1) |
|---|
| | 30 | |
|---|
| | 31 | self.e1 = Entry(master) |
|---|
| | 32 | self.e2 = Entry(master) |
|---|
| | 33 | |
|---|
| | 34 | if self.name: |
|---|
| | 35 | self.e1.insert(0, self.name) |
|---|
| | 36 | if self.path: |
|---|
| | 37 | self.e2.insert(0, self.path) |
|---|
| | 38 | |
|---|
| | 39 | browse = Button(master, text="Browse", command=self.get_dir) |
|---|
| | 40 | |
|---|
| | 41 | self.e1.grid(row=0, column=1, columnspan=2, sticky=W+E) |
|---|
| | 42 | self.e2.grid(row=1, column=1, sticky=W+E) |
|---|
| | 43 | browse.grid(row=1, column=2) |
|---|
| | 44 | |
|---|
| | 45 | self.subbutt = Checkbutton(master, text='Auto subshares', |
|---|
| | 46 | variable=self.subshares) |
|---|
| | 47 | |
|---|
| | 48 | if not self.plugin.get(): |
|---|
| | 49 | self.plugin.set('video') |
|---|
| | 50 | |
|---|
| | 51 | self.sub_show() |
|---|
| | 52 | |
|---|
| | 53 | for i, name in zip(xrange(3), ('video', 'music', 'photo')): |
|---|
| | 54 | b = Radiobutton(master, text=name, variable=self.plugin, |
|---|
| | 55 | value=name, command=self.sub_show).grid(row=i, column=3) |
|---|
| | 56 | |
|---|
| | 57 | return self.e1 # initial focus |
|---|
| | 58 | |
|---|
| | 59 | def apply(self): |
|---|
| | 60 | name = self.e1.get() |
|---|
| | 61 | path = self.e2.get() |
|---|
| | 62 | self.result = name, path, self.plugin.get(), self.subshares.get() |
|---|
| 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) |
|---|
| | 68 | def buildContainerList(self): |
|---|
| | 69 | header = Frame(self) |
|---|
| | 70 | header.pack(fill=X) |
|---|
| | 71 | Label(header, text='Shares').pack(side=LEFT) |
|---|
| | 72 | frame = Frame(self) |
|---|
| | 73 | frame.pack(fill=BOTH, expand=1) |
|---|
| | 74 | scrollbar = Scrollbar(frame, orient=VERTICAL) |
|---|
| | 75 | self.container_list = Listbox(frame, yscrollcommand=scrollbar.set) |
|---|
| | 76 | scrollbar.config(command=self.container_list.yview) |
|---|
| | 77 | scrollbar.pack(side=RIGHT, fill=Y) |
|---|
| | 78 | self.container_list.pack(side=LEFT, fill=BOTH, expand=1) |
|---|
| | 79 | self.container_list.bind("<Double-Button-1>", self.selected) |
|---|
| 46 | | self.config.set(sharename, 'type', 'video') |
|---|
| 47 | | self.config.set(sharename, 'path', '<Pick A Path>') |
|---|
| | 112 | self.config.set(sharename, 'type', plugin) |
|---|
| | 113 | self.config.set(sharename, 'path', path) |
|---|
| | 114 | if subshares and plugin == 'video': |
|---|
| | 115 | self.config.set(name, 'auto_subshares', 'True') |
|---|
| 69 | | def setPath(self): |
|---|
| 70 | | if not self.section: |
|---|
| 71 | | return |
|---|
| 72 | | import tkFileDialog |
|---|
| 73 | | dir = os.path.normpath(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 |
|---|
| 81 | | |
|---|
| 82 | | self.path.delete(0, END) |
|---|
| 83 | | self.path.insert(0, self.config.get(self.section, 'path')) |
|---|
| 84 | | |
|---|
| 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) |
|---|
| 90 | | |
|---|
| 91 | | def readConfig(self): |
|---|
| 92 | | self.config = ConfigParser.ConfigParser() |
|---|
| 93 | | self.config.read(self.config_file) |
|---|
| 94 | | |
|---|
| 95 | | def writeConfig(self): |
|---|
| 96 | | self.config.write(open(self.config_file, 'w')) |
|---|
| 97 | | |
|---|
| 98 | | def __init__(self, master=None): |
|---|
| 99 | | Frame.__init__(self, master) |
|---|
| 100 | | self.master.title('pyTivoConfigurator') |
|---|
| 101 | | self.pack(fill=BOTH, expand=1) |
|---|
| 102 | | |
|---|
| 103 | | import os |
|---|
| 104 | | p = os.path.dirname(__file__) |
|---|
| 105 | | self.config_file = os.path.join(p, 'pyTivo.conf') |
|---|
| 106 | | |
|---|
| 107 | | self.readConfig() |
|---|
| 108 | | |
|---|
| 109 | | self.buildContainerList() |
|---|
| 110 | | self.buildPath() |
|---|
| 111 | | self.buildButtons() |
|---|
| | 146 | share = EditShare(self, title='Edit Share', name=name, path=path, |
|---|
| | 147 | plugin=plugin, subshares=subshares) |
|---|
| | 148 | if share.result: |
|---|
| | 149 | name, path, plugin, subshares = share.result |
|---|
| | 150 | if name != self.section: |
|---|
| | 151 | self.config.remove_section(self.section) |
|---|
| | 152 | self.config.add_section(name) |
|---|
| | 153 | self.section = name |
|---|
| | 154 | self.config.set(name, 'type', plugin) |
|---|
| | 155 | self.config.set(name, 'path', path) |
|---|
| | 156 | if subshares and plugin == 'video': |
|---|
| | 157 | self.config.set(name, 'auto_subshares', 'True') |
|---|
| | 158 | else: |
|---|
| | 159 | self.config.remove_option(name, 'auto_subshares') |
|---|
| | 170 | def readConfig(self): |
|---|
| | 171 | self.config = ConfigParser.ConfigParser() |
|---|
| | 172 | self.config.read(self.config_file) |
|---|
| | 173 | |
|---|
| | 174 | def writeConfig(self): |
|---|
| | 175 | self.config.write(open(self.config_file, 'w')) |
|---|
| | 176 | |
|---|
| | 177 | def __init__(self, master=None): |
|---|
| | 178 | Frame.__init__(self, master) |
|---|
| | 179 | self.master.title('pyTivoConfigurator') |
|---|
| | 180 | self.pack(fill=BOTH, expand=1) |
|---|
| | 181 | |
|---|
| | 182 | p = os.path.dirname(__file__) |
|---|
| | 183 | self.config_file = os.path.join(p, 'pyTivo.conf') |
|---|
| | 184 | |
|---|
| | 185 | self.readConfig() |
|---|
| | 186 | |
|---|
| | 187 | self.buildContainerList() |
|---|
| | 188 | self.buildButtons() |
|---|
| | 189 | |
|---|
| | 190 | self.updateContainerList() |
|---|