← Back to team overview

cairo-dock-team team mailing list archive

[Merge] lp:~mycompostpile/cairo-dock-plug-ins-extras/YoutubeDl into lp:cairo-dock-plug-ins-extras

 

Brian has proposed merging lp:~mycompostpile/cairo-dock-plug-ins-extras/YoutubeDl into lp:cairo-dock-plug-ins-extras.

Requested reviews:
  Cairo-Dock Team (cairo-dock-team)

For more details, see:
https://code.launchpad.net/~mycompostpile/cairo-dock-plug-ins-extras/YoutubeDl/+merge/109474

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.

-- 
https://code.launchpad.net/~mycompostpile/cairo-dock-plug-ins-extras/YoutubeDl/+merge/109474
Your team Cairo-Dock Team is requested to review the proposed merge of lp:~mycompostpile/cairo-dock-plug-ins-extras/YoutubeDl into lp:cairo-dock-plug-ins-extras.
=== modified file 'YoutubeDl/YoutubeDl'
--- YoutubeDl/YoutubeDl	2012-06-04 21:56:31 +0000
+++ YoutubeDl/YoutubeDl	2012-06-09 04:25:29 +0000
@@ -29,6 +29,7 @@
 
 # if tkinter is available use it otherwise use popup messages.
 import fileDialogs as dialogs
+from urlListEdit import urlListEditor
 
 # all constant types are placed in one file and used as needed.
 from constantTypes import PopupTypes
@@ -37,9 +38,7 @@
 class Applet(CDApplet):
 
 	def __init__(self):
-	    #super(YoutubeDlPlugin, self).__init__()
 	    self.__interval = 60000 # 1 minute (in millisecondes)
-	    #self.__config = Configuration(os.path.basename(os.path.abspath(".")))
 	    self.__timerId = None
             self.work_queue = multiprocessing.Queue(1)
             self.result_queue = multiprocessing.Queue(2)
@@ -73,7 +72,6 @@
             else:
 	        self.icon.SetQuickInfo('')
             if self.__showStatusOnIcon:
-                #self.icon.SetLabel(self.resultSummary)
                 self.icon.SetLabel("YoutubeDl")
             self.reload()
 	    self.__setTimer()
@@ -94,7 +92,6 @@
 
             tempString = '          Current Download' + endingCharacter
             if self.activeDownload:
-                #tempString = tempString + '\n      -> '.join(self.urlList[0]) + endingCharacter
                 tempString = tempString + '\n      -> '.join(self.urlList[0]) 
                 rangeStart = 1
             else:
@@ -122,18 +119,27 @@
                  "values" : tempString})
             else:
                 self.icon.PopupDialog( {"message" : tempString,
-                "icon" : "gtk-stock-edit"},
+                "icon" : "gtk-edit"},
                 {"visible" : True,
                  "multi-lines" : True,
                  "editable" : False, })
             self.currentDialog = PopupTypes.infoDialog
+
+        def editURLs(self):
+            urlEdit=urlListEditor(self.urlList).run()
+            if urlEdit:
+                self.urlList[:] = urlEdit
+            else:
+                if urlEdit is None:
+                    self.icon.PopupDialog( {"message" : "python-tk not installed, Editing not possible",
+                    "icon" : "gtk-dialog-info"},
+                    {"visible" : True,
+                     "multi-lines" : True,
+                     "editable" : False, })
+                    self.currentDialog = PopupTypes.infoDialog
 	    return True
 
 	def on_middle_click(self):
-	    """
-	    I set my icon always vissible flag
-	    """
-	    #super(YoutubeDlPlugin, self).onMiddleClick()
             if self.__actionOnMiddleClick == 'Open Video Folder':
                 subprocess.call(['xdg-open',self.__videos_directory], shell=False)
             else:
@@ -273,6 +279,10 @@
                     {"label": "Clear current URL list", 
                      "icon" : "gtk-delete",
                      "id"   : menuEntries.clearURLs })
+                    items.append(
+                    {"label": "Edit current URL list", 
+                     "icon" : "gtk-edit",
+                     "id"   : menuEntries.editURLs })
             if len(self.urlList) == 0:
                 items.append(
                 {"label": "Load URL list from file", 
@@ -305,6 +315,8 @@
              "icon" : "gtk-delete"},  
              {"visible" : True } )
                 self.currentDialog = PopupTypes.delList
+            elif iNumEntry == menuEntries.editURLs:
+                self.editURLs()
             elif iNumEntry == menuEntries.saveURLs:
                 self.saveURLs()
             elif iNumEntry == menuEntries.loadURLs:
@@ -441,15 +453,16 @@
 
         def debug(self):
             """
-            Call me one time in the beginning of your script. If you are running Cairo-Dock
-            from a console window, you'll be able to see what I'm doing.
+            Call me one time in the beginning of your script. 
+            If you are running Cairo-Dock from a console window, 
+            you'll be able to see what I'm doing.
             """
             self.__debugMode = True
 
 
 	def get_config(self, keyfile):
 	    """
-	    I reload the configuration.
+	    Reload the configuration.
 	    """
 	    interval = keyfile.getint('User Interface', 'interval')
 	    self.__interval = interval * 1000 # convert in millisecondes.
@@ -479,7 +492,7 @@
 	
 	def __setTimer(self):
 	    """
-	    I set the time between two checks.
+	    Set the time between two checks.
 	    """
 	    self.__removeTimer()
 	    #self.__timerId = timeout_add(self.__interval, self.doUpdate)
@@ -487,7 +500,7 @@
 		
 	def __removeTimer(self):
 	    """
-	    I properly remove the timer.
+	    Properly remove the timer.
 	    """
 	    if self.__timerId != None:
 	    	gobject.source_remove(self.__timerId)

=== modified file 'YoutubeDl/constantTypes.py'
--- YoutubeDl/constantTypes.py	2012-05-31 00:01:58 +0000
+++ YoutubeDl/constantTypes.py	2012-06-09 04:25:29 +0000
@@ -2,7 +2,7 @@
     (infoDialog, confirmAbort, saveListFilename, getListFilename, delList, showUrlList) = range(0, 6)
 
 class menuEntries:
-    (abortDownload, saveURLs, loadURLs, pauseDownload, enableDownload, clearURLs,helpSubMenu,downloaderHelp,pluginHelp) = range(1,10)
+    (abortDownload, saveURLs, loadURLs, pauseDownload, enableDownload, clearURLs, editURLs) = range(7)
 
 class youtube:
     videoFormats = {"H264 - MP4 at 480p":'18',

=== modified file 'YoutubeDl/fileDialogs.py'
--- YoutubeDl/fileDialogs.py	2012-06-04 21:56:31 +0000
+++ YoutubeDl/fileDialogs.py	2012-06-09 04:25:29 +0000
@@ -23,7 +23,7 @@
         options['initialdir'] = initialDirectory
         options['title'] = 'Please select a url list file to save'
         options['parent'] = rootDialog
-        fileName = tkFileDialog.askopenfilename(**file_opt)
+        fileName = tkFileDialog.asksaveasfilename(**file_opt)
         rootDialog.destroy()
         return fileName
 

=== added file 'YoutubeDl/urlListEdit.py'
--- YoutubeDl/urlListEdit.py	1970-01-01 00:00:00 +0000
+++ YoutubeDl/urlListEdit.py	2012-06-09 04:25:29 +0000
@@ -0,0 +1,155 @@
+#!/usr/bin/env python
+ 
+try:
+    from Tkinter.junk import *
+    import tkFont
+
+    class  urlListEditor(Frame):
+
+        def __init__(self,urlList):
+            self.root = Tk()
+            Frame.__init__(self)
+            self.urlList = False
+            self.root.title("Listbox Operations")
+            self.root.rowconfigure(0, weight=1)
+            self.root.columnconfigure(0, weight=1)
+
+            RWidth=self.root.winfo_screenwidth()
+            RHeight=self.root.winfo_screenheight()
+            self.root.geometry("550x350+300+100")
+            # create the listbox (note that size is in characters)
+            myFont = tkFont.Font ( family="Courier",size=10)
+            self.listbox1 = Listbox(self.root, width=50, height=6, font=myFont)
+            self.listbox1.grid(row=0, column=0,rowspan=2, columnspan=2, sticky=N+S+E+W)
+ 
+            # create a vertical scrollbar to the right of the listbox
+            self.yscroll = Scrollbar(command=self.listbox1.yview, orient=VERTICAL)
+            #self.yscroll.grid(row=0, column=1, sticky=N+S)
+            self.yscroll.grid(row=0,rowspan=2, column=2, sticky=N+S)
+            self.listbox1.configure(yscrollcommand=self.yscroll.set)
+            # create a horizontal scrollbar to the bottom of the listbox
+            self.xscroll = Scrollbar(command=self.listbox1.xview, orient=HORIZONTAL)
+            self.xscroll.grid(row=2, column=0, columnspan=2, sticky=E+W)
+            self.listbox1.configure(xscrollcommand=self.xscroll.set)
+ 
+            # button to move a line up in the list box
+            self.button1 = Button(self.root, text='Move Up', command=self.move_up)
+            self.button1.grid(row=0, column=3, sticky=W+N)
+            # button to move a line down in the list box
+            self.button2 = Button(self.root, text='Move Down', command=self.move_down)
+            #self.button2.grid(row=4, column=0, sticky=W)
+            self.button2.grid(row=1, column=3, sticky=W+N)
+            # button to delete a line from the listbox
+            self.button3 = Button(self.root, text='Delete Selected', command=self.delete_item)
+            #self.button3.grid(row=3, column=0, sticky=E)
+            self.button3.grid(row=3, column=0,sticky=W+N)
+            # button to commit changes and close
+            self.button4 = Button(self.root, text='Commit Changes', command=self.save_list)
+            #self.button4.grid(row=4, column=0, sticky=E)
+            self.button4.grid(row=3, column=1,sticky=E+N)
+ 
+            # left mouse click on a list item to display selection
+            #self.listbox1.bind('<ButtonRelease-1>', self.get_list)
+ 
+            for item in range(len(urlList)):
+                tempString = ' -> '.join(urlList[item])
+                self.listbox1.insert(END, tempString)
+
+        def run(self):
+            self.mainloop()
+            return self.urlList
+
+        def delete_item(self):
+            """
+            delete a selected line from the listbox
+            """
+            try:
+                # get selected line index
+                index = self.listbox1.curselection()[0]
+                self.listbox1.delete(index)
+            except IndexError:
+                pass
+ 
+        #def get_list(self,event):
+            #"""
+            #function to read the listbox selection
+            #"""
+            # get selected line index
+            #index = self.listbox1.curselection()[0]
+
+        def set_list(self,event):
+            """
+            insert an edited line from the entry widget
+            back into the listbox
+            """
+            try:
+                index = self.listbox1.curselection()[0]
+                # delete old listbox line
+                self.listbox1.delete(index)
+            except IndexError:
+                index = END
+
+        def move_up(self):
+            """
+            function to sort listbox items case insensitive
+            """
+            try:
+                index = self.listbox1.curselection()[0]
+                if index > 0:
+                    newindex = str(int(index) - 1)
+                    self.listbox1.insert((int(index) - 1), self.listbox1.get(index))
+                    # delete old listbox line
+                    self.listbox1.delete(int(index)+1)
+                    self.listbox1.select_set(int(index)-1)
+                    #self.listbox1.yview(int(index)-1)
+                else:
+                    self.listbox1.select_set(0)
+                    self.listbox1.yview(0)
+            except IndexError:
+                index = END
+
+        def move_down(self):
+            """
+            function to sort listbox items case insensitive
+            """
+            try:
+                index = self.listbox1.curselection()[0]
+                if index < END:
+                    self.listbox1.insert((int(index) + 2), self.listbox1.get(index))
+                    # delete old listbox line
+                    self.listbox1.delete(index)
+                    self.listbox1.select_set(int(index)+1)
+                    self.listbox1.yview(int(index)+1)
+                else:
+                    self.listbox1.select_set(END)
+                    self.listbox1.yview(END)
+            except IndexError:
+                index = END
+
+        def save_list(self):
+            """
+            save the current listbox contents to a file
+            """
+            self.urlList = list()
+            # get a list of listbox lines
+            temp_list = list(self.listbox1.get(0, END))
+            for item in temp_list:
+                tempItem = item.split(" -> ",1)
+                self.urlList.append([tempItem[0].lstrip(),tempItem[1].lstrip()])
+            self.root.destroy()
+
+        def onClose():
+            print "closing"
+            self.root.destroy()
+    
+except ImportError:
+    class  urlListEditor():
+        def __init__(self,myUrlList):
+            self.urlList = None
+
+        def run(self):
+            return self.urlList
+
+if __name__ == "__main__":
+    root=urlListEditor([['test','1'],['test','2'],['test','3']]).run()
+


Follow ups