Merge lp:~mycompostpile/cairo-dock-plug-ins-extras/YoutubeDl into lp:~cairo-dock-team/cairo-dock-plug-ins-extras/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
Reviewer Review Type Date Requested Status
Matthieu Baerts Approve
Review via email: mp+109474@code.launchpad.net

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 :

Forgot to add the editor file. branch 279 has the file.

Revision history for this message
Matthieu Baerts (matttbe) wrote :

Thank you :)

review: Approve

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
6 # if tkinter is available use it otherwise use popup messages.
7 import fileDialogs as dialogs
8+from urlListEdit import urlListEditor
9
10 # all constant types are placed in one file and used as needed.
11 from constantTypes import PopupTypes
12@@ -37,9 +38,7 @@
13 class Applet(CDApplet):
14
15 def __init__(self):
16- #super(YoutubeDlPlugin, self).__init__()
17 self.__interval = 60000 # 1 minute (in millisecondes)
18- #self.__config = Configuration(os.path.basename(os.path.abspath(".")))
19 self.__timerId = None
20 self.work_queue = multiprocessing.Queue(1)
21 self.result_queue = multiprocessing.Queue(2)
22@@ -73,7 +72,6 @@
23 else:
24 self.icon.SetQuickInfo('')
25 if self.__showStatusOnIcon:
26- #self.icon.SetLabel(self.resultSummary)
27 self.icon.SetLabel("YoutubeDl")
28 self.reload()
29 self.__setTimer()
30@@ -94,7 +92,6 @@
31
32 tempString = ' Current Download' + endingCharacter
33 if self.activeDownload:
34- #tempString = tempString + '\n -> '.join(self.urlList[0]) + endingCharacter
35 tempString = tempString + '\n -> '.join(self.urlList[0])
36 rangeStart = 1
37 else:
38@@ -122,18 +119,27 @@
39 "values" : tempString})
40 else:
41 self.icon.PopupDialog( {"message" : tempString,
42- "icon" : "gtk-stock-edit"},
43+ "icon" : "gtk-edit"},
44 {"visible" : True,
45 "multi-lines" : True,
46 "editable" : False, })
47 self.currentDialog = PopupTypes.infoDialog
48+
49+ def editURLs(self):
50+ urlEdit=urlListEditor(self.urlList).run()
51+ if urlEdit:
52+ self.urlList[:] = urlEdit
53+ else:
54+ if urlEdit is None:
55+ self.icon.PopupDialog( {"message" : "python-tk not installed, Editing not possible",
56+ "icon" : "gtk-dialog-info"},
57+ {"visible" : True,
58+ "multi-lines" : True,
59+ "editable" : False, })
60+ self.currentDialog = PopupTypes.infoDialog
61 return True
62
63 def on_middle_click(self):
64- """
65- I set my icon always vissible flag
66- """
67- #super(YoutubeDlPlugin, self).onMiddleClick()
68 if self.__actionOnMiddleClick == 'Open Video Folder':
69 subprocess.call(['xdg-open',self.__videos_directory], shell=False)
70 else:
71@@ -273,6 +279,10 @@
72 {"label": "Clear current URL list",
73 "icon" : "gtk-delete",
74 "id" : menuEntries.clearURLs })
75+ items.append(
76+ {"label": "Edit current URL list",
77+ "icon" : "gtk-edit",
78+ "id" : menuEntries.editURLs })
79 if len(self.urlList) == 0:
80 items.append(
81 {"label": "Load URL list from file",
82@@ -305,6 +315,8 @@
83 "icon" : "gtk-delete"},
84 {"visible" : True } )
85 self.currentDialog = PopupTypes.delList
86+ elif iNumEntry == menuEntries.editURLs:
87+ self.editURLs()
88 elif iNumEntry == menuEntries.saveURLs:
89 self.saveURLs()
90 elif iNumEntry == menuEntries.loadURLs:
91@@ -441,15 +453,16 @@
92
93 def debug(self):
94 """
95- Call me one time in the beginning of your script. If you are running Cairo-Dock
96- from a console window, you'll be able to see what I'm doing.
97+ Call me one time in the beginning of your script.
98+ If you are running Cairo-Dock from a console window,
99+ you'll be able to see what I'm doing.
100 """
101 self.__debugMode = True
102
103
104 def get_config(self, keyfile):
105 """
106- I reload the configuration.
107+ Reload the configuration.
108 """
109 interval = keyfile.getint('User Interface', 'interval')
110 self.__interval = interval * 1000 # convert in millisecondes.
111@@ -479,7 +492,7 @@
112
113 def __setTimer(self):
114 """
115- I set the time between two checks.
116+ Set the time between two checks.
117 """
118 self.__removeTimer()
119 #self.__timerId = timeout_add(self.__interval, self.doUpdate)
120@@ -487,7 +500,7 @@
121
122 def __removeTimer(self):
123 """
124- I properly remove the timer.
125+ Properly remove the timer.
126 """
127 if self.__timerId != None:
128 gobject.source_remove(self.__timerId)
129
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 (infoDialog, confirmAbort, saveListFilename, getListFilename, delList, showUrlList) = range(0, 6)
135
136 class menuEntries:
137- (abortDownload, saveURLs, loadURLs, pauseDownload, enableDownload, clearURLs,helpSubMenu,downloaderHelp,pluginHelp) = range(1,10)
138+ (abortDownload, saveURLs, loadURLs, pauseDownload, enableDownload, clearURLs, editURLs) = range(7)
139
140 class youtube:
141 videoFormats = {"H264 - MP4 at 480p":'18',
142
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 options['initialdir'] = initialDirectory
148 options['title'] = 'Please select a url list file to save'
149 options['parent'] = rootDialog
150- fileName = tkFileDialog.askopenfilename(**file_opt)
151+ fileName = tkFileDialog.asksaveasfilename(**file_opt)
152 rootDialog.destroy()
153 return fileName
154
155
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+#!/usr/bin/env python
161+
162+try:
163+ from Tkinter.junk import *
164+ import tkFont
165+
166+ class urlListEditor(Frame):
167+
168+ def __init__(self,urlList):
169+ self.root = Tk()
170+ Frame.__init__(self)
171+ self.urlList = False
172+ self.root.title("Listbox Operations")
173+ self.root.rowconfigure(0, weight=1)
174+ self.root.columnconfigure(0, weight=1)
175+
176+ RWidth=self.root.winfo_screenwidth()
177+ RHeight=self.root.winfo_screenheight()
178+ self.root.geometry("550x350+300+100")
179+ # create the listbox (note that size is in characters)
180+ myFont = tkFont.Font ( family="Courier",size=10)
181+ self.listbox1 = Listbox(self.root, width=50, height=6, font=myFont)
182+ self.listbox1.grid(row=0, column=0,rowspan=2, columnspan=2, sticky=N+S+E+W)
183+
184+ # create a vertical scrollbar to the right of the listbox
185+ self.yscroll = Scrollbar(command=self.listbox1.yview, orient=VERTICAL)
186+ #self.yscroll.grid(row=0, column=1, sticky=N+S)
187+ self.yscroll.grid(row=0,rowspan=2, column=2, sticky=N+S)
188+ self.listbox1.configure(yscrollcommand=self.yscroll.set)
189+ # create a horizontal scrollbar to the bottom of the listbox
190+ self.xscroll = Scrollbar(command=self.listbox1.xview, orient=HORIZONTAL)
191+ self.xscroll.grid(row=2, column=0, columnspan=2, sticky=E+W)
192+ self.listbox1.configure(xscrollcommand=self.xscroll.set)
193+
194+ # button to move a line up in the list box
195+ self.button1 = Button(self.root, text='Move Up', command=self.move_up)
196+ self.button1.grid(row=0, column=3, sticky=W+N)
197+ # button to move a line down in the list box
198+ self.button2 = Button(self.root, text='Move Down', command=self.move_down)
199+ #self.button2.grid(row=4, column=0, sticky=W)
200+ self.button2.grid(row=1, column=3, sticky=W+N)
201+ # button to delete a line from the listbox
202+ self.button3 = Button(self.root, text='Delete Selected', command=self.delete_item)
203+ #self.button3.grid(row=3, column=0, sticky=E)
204+ self.button3.grid(row=3, column=0,sticky=W+N)
205+ # button to commit changes and close
206+ self.button4 = Button(self.root, text='Commit Changes', command=self.save_list)
207+ #self.button4.grid(row=4, column=0, sticky=E)
208+ self.button4.grid(row=3, column=1,sticky=E+N)
209+
210+ # left mouse click on a list item to display selection
211+ #self.listbox1.bind('<ButtonRelease-1>', self.get_list)
212+
213+ for item in range(len(urlList)):
214+ tempString = ' -> '.join(urlList[item])
215+ self.listbox1.insert(END, tempString)
216+
217+ def run(self):
218+ self.mainloop()
219+ return self.urlList
220+
221+ def delete_item(self):
222+ """
223+ delete a selected line from the listbox
224+ """
225+ try:
226+ # get selected line index
227+ index = self.listbox1.curselection()[0]
228+ self.listbox1.delete(index)
229+ except IndexError:
230+ pass
231+
232+ #def get_list(self,event):
233+ #"""
234+ #function to read the listbox selection
235+ #"""
236+ # get selected line index
237+ #index = self.listbox1.curselection()[0]
238+
239+ def set_list(self,event):
240+ """
241+ insert an edited line from the entry widget
242+ back into the listbox
243+ """
244+ try:
245+ index = self.listbox1.curselection()[0]
246+ # delete old listbox line
247+ self.listbox1.delete(index)
248+ except IndexError:
249+ index = END
250+
251+ def move_up(self):
252+ """
253+ function to sort listbox items case insensitive
254+ """
255+ try:
256+ index = self.listbox1.curselection()[0]
257+ if index > 0:
258+ newindex = str(int(index) - 1)
259+ self.listbox1.insert((int(index) - 1), self.listbox1.get(index))
260+ # delete old listbox line
261+ self.listbox1.delete(int(index)+1)
262+ self.listbox1.select_set(int(index)-1)
263+ #self.listbox1.yview(int(index)-1)
264+ else:
265+ self.listbox1.select_set(0)
266+ self.listbox1.yview(0)
267+ except IndexError:
268+ index = END
269+
270+ def move_down(self):
271+ """
272+ function to sort listbox items case insensitive
273+ """
274+ try:
275+ index = self.listbox1.curselection()[0]
276+ if index < END:
277+ self.listbox1.insert((int(index) + 2), self.listbox1.get(index))
278+ # delete old listbox line
279+ self.listbox1.delete(index)
280+ self.listbox1.select_set(int(index)+1)
281+ self.listbox1.yview(int(index)+1)
282+ else:
283+ self.listbox1.select_set(END)
284+ self.listbox1.yview(END)
285+ except IndexError:
286+ index = END
287+
288+ def save_list(self):
289+ """
290+ save the current listbox contents to a file
291+ """
292+ self.urlList = list()
293+ # get a list of listbox lines
294+ temp_list = list(self.listbox1.get(0, END))
295+ for item in temp_list:
296+ tempItem = item.split(" -> ",1)
297+ self.urlList.append([tempItem[0].lstrip(),tempItem[1].lstrip()])
298+ self.root.destroy()
299+
300+ def onClose():
301+ print "closing"
302+ self.root.destroy()
303+
304+except ImportError:
305+ class urlListEditor():
306+ def __init__(self,myUrlList):
307+ self.urlList = None
308+
309+ def run(self):
310+ return self.urlList
311+
312+if __name__ == "__main__":
313+ root=urlListEditor([['test','1'],['test','2'],['test','3']]).run()
314+

Subscribers

People subscribed via source and target branches

to all changes: