Merge lp:~mycompostpile/cairo-dock-plug-ins-extras/YoutubeDl into lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party
- YoutubeDl
- Merge into third-party
Proposed by
Brian
Status: | Merged |
---|---|
Merged at revision: | 279 |
Proposed branch: | lp:~mycompostpile/cairo-dock-plug-ins-extras/YoutubeDl |
Merge into: | lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party |
Diff against target: |
314 lines (+184/-16) 4 files modified
YoutubeDl/YoutubeDl (+27/-14) YoutubeDl/constantTypes.py (+1/-1) YoutubeDl/fileDialogs.py (+1/-1) YoutubeDl/urlListEdit.py (+155/-0) |
To merge this branch: | bzr merge lp:~mycompostpile/cairo-dock-plug-ins-extras/YoutubeDl |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthieu Baerts | Approve | ||
Review via email: mp+109474@code.launchpad.net |
Commit message
Description of the change
Fixed a bug I created when copying and pasting the file dialog for saving the url list.
Cleaned up the menu entries removing the constants for the help menus and adding a right click entry to allow the user to edit the url list.
Added functionality to allow the url list to be edited with a tkinter app. If tkinter is not available then the user is presented with a dialog stating that editing is not possible and why. The editor allows the user to move urls up/down in the list and delete them.
To post a comment you must log in.
Revision history for this message
Brian (mycompostpile) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'YoutubeDl/YoutubeDl' | |||
2 | --- YoutubeDl/YoutubeDl 2012-06-04 21:56:31 +0000 | |||
3 | +++ YoutubeDl/YoutubeDl 2012-06-09 04:25:29 +0000 | |||
4 | @@ -29,6 +29,7 @@ | |||
5 | 29 | 29 | ||
6 | 30 | # if tkinter is available use it otherwise use popup messages. | 30 | # if tkinter is available use it otherwise use popup messages. |
7 | 31 | import fileDialogs as dialogs | 31 | import fileDialogs as dialogs |
8 | 32 | from urlListEdit import urlListEditor | ||
9 | 32 | 33 | ||
10 | 33 | # all constant types are placed in one file and used as needed. | 34 | # all constant types are placed in one file and used as needed. |
11 | 34 | from constantTypes import PopupTypes | 35 | from constantTypes import PopupTypes |
12 | @@ -37,9 +38,7 @@ | |||
13 | 37 | class Applet(CDApplet): | 38 | class Applet(CDApplet): |
14 | 38 | 39 | ||
15 | 39 | def __init__(self): | 40 | def __init__(self): |
16 | 40 | #super(YoutubeDlPlugin, self).__init__() | ||
17 | 41 | self.__interval = 60000 # 1 minute (in millisecondes) | 41 | self.__interval = 60000 # 1 minute (in millisecondes) |
18 | 42 | #self.__config = Configuration(os.path.basename(os.path.abspath("."))) | ||
19 | 43 | self.__timerId = None | 42 | self.__timerId = None |
20 | 44 | self.work_queue = multiprocessing.Queue(1) | 43 | self.work_queue = multiprocessing.Queue(1) |
21 | 45 | self.result_queue = multiprocessing.Queue(2) | 44 | self.result_queue = multiprocessing.Queue(2) |
22 | @@ -73,7 +72,6 @@ | |||
23 | 73 | else: | 72 | else: |
24 | 74 | self.icon.SetQuickInfo('') | 73 | self.icon.SetQuickInfo('') |
25 | 75 | if self.__showStatusOnIcon: | 74 | if self.__showStatusOnIcon: |
26 | 76 | #self.icon.SetLabel(self.resultSummary) | ||
27 | 77 | self.icon.SetLabel("YoutubeDl") | 75 | self.icon.SetLabel("YoutubeDl") |
28 | 78 | self.reload() | 76 | self.reload() |
29 | 79 | self.__setTimer() | 77 | self.__setTimer() |
30 | @@ -94,7 +92,6 @@ | |||
31 | 94 | 92 | ||
32 | 95 | tempString = ' Current Download' + endingCharacter | 93 | tempString = ' Current Download' + endingCharacter |
33 | 96 | if self.activeDownload: | 94 | if self.activeDownload: |
34 | 97 | #tempString = tempString + '\n -> '.join(self.urlList[0]) + endingCharacter | ||
35 | 98 | tempString = tempString + '\n -> '.join(self.urlList[0]) | 95 | tempString = tempString + '\n -> '.join(self.urlList[0]) |
36 | 99 | rangeStart = 1 | 96 | rangeStart = 1 |
37 | 100 | else: | 97 | else: |
38 | @@ -122,18 +119,27 @@ | |||
39 | 122 | "values" : tempString}) | 119 | "values" : tempString}) |
40 | 123 | else: | 120 | else: |
41 | 124 | self.icon.PopupDialog( {"message" : tempString, | 121 | self.icon.PopupDialog( {"message" : tempString, |
43 | 125 | "icon" : "gtk-stock-edit"}, | 122 | "icon" : "gtk-edit"}, |
44 | 126 | {"visible" : True, | 123 | {"visible" : True, |
45 | 127 | "multi-lines" : True, | 124 | "multi-lines" : True, |
46 | 128 | "editable" : False, }) | 125 | "editable" : False, }) |
47 | 129 | self.currentDialog = PopupTypes.infoDialog | 126 | self.currentDialog = PopupTypes.infoDialog |
48 | 127 | |||
49 | 128 | def editURLs(self): | ||
50 | 129 | urlEdit=urlListEditor(self.urlList).run() | ||
51 | 130 | if urlEdit: | ||
52 | 131 | self.urlList[:] = urlEdit | ||
53 | 132 | else: | ||
54 | 133 | if urlEdit is None: | ||
55 | 134 | self.icon.PopupDialog( {"message" : "python-tk not installed, Editing not possible", | ||
56 | 135 | "icon" : "gtk-dialog-info"}, | ||
57 | 136 | {"visible" : True, | ||
58 | 137 | "multi-lines" : True, | ||
59 | 138 | "editable" : False, }) | ||
60 | 139 | self.currentDialog = PopupTypes.infoDialog | ||
61 | 130 | return True | 140 | return True |
62 | 131 | 141 | ||
63 | 132 | def on_middle_click(self): | 142 | def on_middle_click(self): |
64 | 133 | """ | ||
65 | 134 | I set my icon always vissible flag | ||
66 | 135 | """ | ||
67 | 136 | #super(YoutubeDlPlugin, self).onMiddleClick() | ||
68 | 137 | if self.__actionOnMiddleClick == 'Open Video Folder': | 143 | if self.__actionOnMiddleClick == 'Open Video Folder': |
69 | 138 | subprocess.call(['xdg-open',self.__videos_directory], shell=False) | 144 | subprocess.call(['xdg-open',self.__videos_directory], shell=False) |
70 | 139 | else: | 145 | else: |
71 | @@ -273,6 +279,10 @@ | |||
72 | 273 | {"label": "Clear current URL list", | 279 | {"label": "Clear current URL list", |
73 | 274 | "icon" : "gtk-delete", | 280 | "icon" : "gtk-delete", |
74 | 275 | "id" : menuEntries.clearURLs }) | 281 | "id" : menuEntries.clearURLs }) |
75 | 282 | items.append( | ||
76 | 283 | {"label": "Edit current URL list", | ||
77 | 284 | "icon" : "gtk-edit", | ||
78 | 285 | "id" : menuEntries.editURLs }) | ||
79 | 276 | if len(self.urlList) == 0: | 286 | if len(self.urlList) == 0: |
80 | 277 | items.append( | 287 | items.append( |
81 | 278 | {"label": "Load URL list from file", | 288 | {"label": "Load URL list from file", |
82 | @@ -305,6 +315,8 @@ | |||
83 | 305 | "icon" : "gtk-delete"}, | 315 | "icon" : "gtk-delete"}, |
84 | 306 | {"visible" : True } ) | 316 | {"visible" : True } ) |
85 | 307 | self.currentDialog = PopupTypes.delList | 317 | self.currentDialog = PopupTypes.delList |
86 | 318 | elif iNumEntry == menuEntries.editURLs: | ||
87 | 319 | self.editURLs() | ||
88 | 308 | elif iNumEntry == menuEntries.saveURLs: | 320 | elif iNumEntry == menuEntries.saveURLs: |
89 | 309 | self.saveURLs() | 321 | self.saveURLs() |
90 | 310 | elif iNumEntry == menuEntries.loadURLs: | 322 | elif iNumEntry == menuEntries.loadURLs: |
91 | @@ -441,15 +453,16 @@ | |||
92 | 441 | 453 | ||
93 | 442 | def debug(self): | 454 | def debug(self): |
94 | 443 | """ | 455 | """ |
97 | 444 | Call me one time in the beginning of your script. If you are running Cairo-Dock | 456 | Call me one time in the beginning of your script. |
98 | 445 | from a console window, you'll be able to see what I'm doing. | 457 | If you are running Cairo-Dock from a console window, |
99 | 458 | you'll be able to see what I'm doing. | ||
100 | 446 | """ | 459 | """ |
101 | 447 | self.__debugMode = True | 460 | self.__debugMode = True |
102 | 448 | 461 | ||
103 | 449 | 462 | ||
104 | 450 | def get_config(self, keyfile): | 463 | def get_config(self, keyfile): |
105 | 451 | """ | 464 | """ |
107 | 452 | I reload the configuration. | 465 | Reload the configuration. |
108 | 453 | """ | 466 | """ |
109 | 454 | interval = keyfile.getint('User Interface', 'interval') | 467 | interval = keyfile.getint('User Interface', 'interval') |
110 | 455 | self.__interval = interval * 1000 # convert in millisecondes. | 468 | self.__interval = interval * 1000 # convert in millisecondes. |
111 | @@ -479,7 +492,7 @@ | |||
112 | 479 | 492 | ||
113 | 480 | def __setTimer(self): | 493 | def __setTimer(self): |
114 | 481 | """ | 494 | """ |
116 | 482 | I set the time between two checks. | 495 | Set the time between two checks. |
117 | 483 | """ | 496 | """ |
118 | 484 | self.__removeTimer() | 497 | self.__removeTimer() |
119 | 485 | #self.__timerId = timeout_add(self.__interval, self.doUpdate) | 498 | #self.__timerId = timeout_add(self.__interval, self.doUpdate) |
120 | @@ -487,7 +500,7 @@ | |||
121 | 487 | 500 | ||
122 | 488 | def __removeTimer(self): | 501 | def __removeTimer(self): |
123 | 489 | """ | 502 | """ |
125 | 490 | I properly remove the timer. | 503 | Properly remove the timer. |
126 | 491 | """ | 504 | """ |
127 | 492 | if self.__timerId != None: | 505 | if self.__timerId != None: |
128 | 493 | gobject.source_remove(self.__timerId) | 506 | gobject.source_remove(self.__timerId) |
129 | 494 | 507 | ||
130 | === modified file 'YoutubeDl/constantTypes.py' | |||
131 | --- YoutubeDl/constantTypes.py 2012-05-31 00:01:58 +0000 | |||
132 | +++ YoutubeDl/constantTypes.py 2012-06-09 04:25:29 +0000 | |||
133 | @@ -2,7 +2,7 @@ | |||
134 | 2 | (infoDialog, confirmAbort, saveListFilename, getListFilename, delList, showUrlList) = range(0, 6) | 2 | (infoDialog, confirmAbort, saveListFilename, getListFilename, delList, showUrlList) = range(0, 6) |
135 | 3 | 3 | ||
136 | 4 | class menuEntries: | 4 | class menuEntries: |
138 | 5 | (abortDownload, saveURLs, loadURLs, pauseDownload, enableDownload, clearURLs,helpSubMenu,downloaderHelp,pluginHelp) = range(1,10) | 5 | (abortDownload, saveURLs, loadURLs, pauseDownload, enableDownload, clearURLs, editURLs) = range(7) |
139 | 6 | 6 | ||
140 | 7 | class youtube: | 7 | class youtube: |
141 | 8 | videoFormats = {"H264 - MP4 at 480p":'18', | 8 | videoFormats = {"H264 - MP4 at 480p":'18', |
142 | 9 | 9 | ||
143 | === modified file 'YoutubeDl/fileDialogs.py' | |||
144 | --- YoutubeDl/fileDialogs.py 2012-06-04 21:56:31 +0000 | |||
145 | +++ YoutubeDl/fileDialogs.py 2012-06-09 04:25:29 +0000 | |||
146 | @@ -23,7 +23,7 @@ | |||
147 | 23 | options['initialdir'] = initialDirectory | 23 | options['initialdir'] = initialDirectory |
148 | 24 | options['title'] = 'Please select a url list file to save' | 24 | options['title'] = 'Please select a url list file to save' |
149 | 25 | options['parent'] = rootDialog | 25 | options['parent'] = rootDialog |
151 | 26 | fileName = tkFileDialog.askopenfilename(**file_opt) | 26 | fileName = tkFileDialog.asksaveasfilename(**file_opt) |
152 | 27 | rootDialog.destroy() | 27 | rootDialog.destroy() |
153 | 28 | return fileName | 28 | return fileName |
154 | 29 | 29 | ||
155 | 30 | 30 | ||
156 | === added file 'YoutubeDl/urlListEdit.py' | |||
157 | --- YoutubeDl/urlListEdit.py 1970-01-01 00:00:00 +0000 | |||
158 | +++ YoutubeDl/urlListEdit.py 2012-06-09 04:25:29 +0000 | |||
159 | @@ -0,0 +1,155 @@ | |||
160 | 1 | #!/usr/bin/env python | ||
161 | 2 | |||
162 | 3 | try: | ||
163 | 4 | from Tkinter.junk import * | ||
164 | 5 | import tkFont | ||
165 | 6 | |||
166 | 7 | class urlListEditor(Frame): | ||
167 | 8 | |||
168 | 9 | def __init__(self,urlList): | ||
169 | 10 | self.root = Tk() | ||
170 | 11 | Frame.__init__(self) | ||
171 | 12 | self.urlList = False | ||
172 | 13 | self.root.title("Listbox Operations") | ||
173 | 14 | self.root.rowconfigure(0, weight=1) | ||
174 | 15 | self.root.columnconfigure(0, weight=1) | ||
175 | 16 | |||
176 | 17 | RWidth=self.root.winfo_screenwidth() | ||
177 | 18 | RHeight=self.root.winfo_screenheight() | ||
178 | 19 | self.root.geometry("550x350+300+100") | ||
179 | 20 | # create the listbox (note that size is in characters) | ||
180 | 21 | myFont = tkFont.Font ( family="Courier",size=10) | ||
181 | 22 | self.listbox1 = Listbox(self.root, width=50, height=6, font=myFont) | ||
182 | 23 | self.listbox1.grid(row=0, column=0,rowspan=2, columnspan=2, sticky=N+S+E+W) | ||
183 | 24 | |||
184 | 25 | # create a vertical scrollbar to the right of the listbox | ||
185 | 26 | self.yscroll = Scrollbar(command=self.listbox1.yview, orient=VERTICAL) | ||
186 | 27 | #self.yscroll.grid(row=0, column=1, sticky=N+S) | ||
187 | 28 | self.yscroll.grid(row=0,rowspan=2, column=2, sticky=N+S) | ||
188 | 29 | self.listbox1.configure(yscrollcommand=self.yscroll.set) | ||
189 | 30 | # create a horizontal scrollbar to the bottom of the listbox | ||
190 | 31 | self.xscroll = Scrollbar(command=self.listbox1.xview, orient=HORIZONTAL) | ||
191 | 32 | self.xscroll.grid(row=2, column=0, columnspan=2, sticky=E+W) | ||
192 | 33 | self.listbox1.configure(xscrollcommand=self.xscroll.set) | ||
193 | 34 | |||
194 | 35 | # button to move a line up in the list box | ||
195 | 36 | self.button1 = Button(self.root, text='Move Up', command=self.move_up) | ||
196 | 37 | self.button1.grid(row=0, column=3, sticky=W+N) | ||
197 | 38 | # button to move a line down in the list box | ||
198 | 39 | self.button2 = Button(self.root, text='Move Down', command=self.move_down) | ||
199 | 40 | #self.button2.grid(row=4, column=0, sticky=W) | ||
200 | 41 | self.button2.grid(row=1, column=3, sticky=W+N) | ||
201 | 42 | # button to delete a line from the listbox | ||
202 | 43 | self.button3 = Button(self.root, text='Delete Selected', command=self.delete_item) | ||
203 | 44 | #self.button3.grid(row=3, column=0, sticky=E) | ||
204 | 45 | self.button3.grid(row=3, column=0,sticky=W+N) | ||
205 | 46 | # button to commit changes and close | ||
206 | 47 | self.button4 = Button(self.root, text='Commit Changes', command=self.save_list) | ||
207 | 48 | #self.button4.grid(row=4, column=0, sticky=E) | ||
208 | 49 | self.button4.grid(row=3, column=1,sticky=E+N) | ||
209 | 50 | |||
210 | 51 | # left mouse click on a list item to display selection | ||
211 | 52 | #self.listbox1.bind('<ButtonRelease-1>', self.get_list) | ||
212 | 53 | |||
213 | 54 | for item in range(len(urlList)): | ||
214 | 55 | tempString = ' -> '.join(urlList[item]) | ||
215 | 56 | self.listbox1.insert(END, tempString) | ||
216 | 57 | |||
217 | 58 | def run(self): | ||
218 | 59 | self.mainloop() | ||
219 | 60 | return self.urlList | ||
220 | 61 | |||
221 | 62 | def delete_item(self): | ||
222 | 63 | """ | ||
223 | 64 | delete a selected line from the listbox | ||
224 | 65 | """ | ||
225 | 66 | try: | ||
226 | 67 | # get selected line index | ||
227 | 68 | index = self.listbox1.curselection()[0] | ||
228 | 69 | self.listbox1.delete(index) | ||
229 | 70 | except IndexError: | ||
230 | 71 | pass | ||
231 | 72 | |||
232 | 73 | #def get_list(self,event): | ||
233 | 74 | #""" | ||
234 | 75 | #function to read the listbox selection | ||
235 | 76 | #""" | ||
236 | 77 | # get selected line index | ||
237 | 78 | #index = self.listbox1.curselection()[0] | ||
238 | 79 | |||
239 | 80 | def set_list(self,event): | ||
240 | 81 | """ | ||
241 | 82 | insert an edited line from the entry widget | ||
242 | 83 | back into the listbox | ||
243 | 84 | """ | ||
244 | 85 | try: | ||
245 | 86 | index = self.listbox1.curselection()[0] | ||
246 | 87 | # delete old listbox line | ||
247 | 88 | self.listbox1.delete(index) | ||
248 | 89 | except IndexError: | ||
249 | 90 | index = END | ||
250 | 91 | |||
251 | 92 | def move_up(self): | ||
252 | 93 | """ | ||
253 | 94 | function to sort listbox items case insensitive | ||
254 | 95 | """ | ||
255 | 96 | try: | ||
256 | 97 | index = self.listbox1.curselection()[0] | ||
257 | 98 | if index > 0: | ||
258 | 99 | newindex = str(int(index) - 1) | ||
259 | 100 | self.listbox1.insert((int(index) - 1), self.listbox1.get(index)) | ||
260 | 101 | # delete old listbox line | ||
261 | 102 | self.listbox1.delete(int(index)+1) | ||
262 | 103 | self.listbox1.select_set(int(index)-1) | ||
263 | 104 | #self.listbox1.yview(int(index)-1) | ||
264 | 105 | else: | ||
265 | 106 | self.listbox1.select_set(0) | ||
266 | 107 | self.listbox1.yview(0) | ||
267 | 108 | except IndexError: | ||
268 | 109 | index = END | ||
269 | 110 | |||
270 | 111 | def move_down(self): | ||
271 | 112 | """ | ||
272 | 113 | function to sort listbox items case insensitive | ||
273 | 114 | """ | ||
274 | 115 | try: | ||
275 | 116 | index = self.listbox1.curselection()[0] | ||
276 | 117 | if index < END: | ||
277 | 118 | self.listbox1.insert((int(index) + 2), self.listbox1.get(index)) | ||
278 | 119 | # delete old listbox line | ||
279 | 120 | self.listbox1.delete(index) | ||
280 | 121 | self.listbox1.select_set(int(index)+1) | ||
281 | 122 | self.listbox1.yview(int(index)+1) | ||
282 | 123 | else: | ||
283 | 124 | self.listbox1.select_set(END) | ||
284 | 125 | self.listbox1.yview(END) | ||
285 | 126 | except IndexError: | ||
286 | 127 | index = END | ||
287 | 128 | |||
288 | 129 | def save_list(self): | ||
289 | 130 | """ | ||
290 | 131 | save the current listbox contents to a file | ||
291 | 132 | """ | ||
292 | 133 | self.urlList = list() | ||
293 | 134 | # get a list of listbox lines | ||
294 | 135 | temp_list = list(self.listbox1.get(0, END)) | ||
295 | 136 | for item in temp_list: | ||
296 | 137 | tempItem = item.split(" -> ",1) | ||
297 | 138 | self.urlList.append([tempItem[0].lstrip(),tempItem[1].lstrip()]) | ||
298 | 139 | self.root.destroy() | ||
299 | 140 | |||
300 | 141 | def onClose(): | ||
301 | 142 | print "closing" | ||
302 | 143 | self.root.destroy() | ||
303 | 144 | |||
304 | 145 | except ImportError: | ||
305 | 146 | class urlListEditor(): | ||
306 | 147 | def __init__(self,myUrlList): | ||
307 | 148 | self.urlList = None | ||
308 | 149 | |||
309 | 150 | def run(self): | ||
310 | 151 | return self.urlList | ||
311 | 152 | |||
312 | 153 | if __name__ == "__main__": | ||
313 | 154 | root=urlListEditor([['test','1'],['test','2'],['test','3']]).run() | ||
314 | 155 |
Forgot to add the editor file. branch 279 has the file.