[Ap-python-commits] python/aptk control.py,1.7,1.8 playlist.py,1.10,1.11
Status: Beta
Brought to you by:
sjah
From: <sj...@us...> - 2002-07-28 13:32:24
|
Update of /cvsroot/ap-python/python/aptk In directory usw-pr-cvs1:/tmp/cvs-serv26913/aptk Modified Files: control.py playlist.py Log Message: Simplerify playlist widget structure. Index: control.py =================================================================== RCS file: /cvsroot/ap-python/python/aptk/control.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** control.py 23 Jul 2002 09:01:55 -0000 1.7 --- control.py 28 Jul 2002 13:32:12 -0000 1.8 *************** *** 248,252 **** gtk.VBox.__init__ (self) ! _Box.__init__ (self, pl, prop, relief = relief) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # --- 248,252 ---- gtk.VBox.__init__ (self) ! _Box.__init__ (self, pl, prop, prefix) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Index: playlist.py =================================================================== RCS file: /cvsroot/ap-python/python/aptk/playlist.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** playlist.py 27 Jul 2002 16:23:32 -0000 1.10 --- playlist.py 28 Jul 2002 13:32:12 -0000 1.11 *************** *** 232,235 **** --- 232,381 ---- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + class ClearButton (aptk.misc.Button): + """Start playback. + """ + + # Defualt properties + __properties = aptk.misc.WidgetProperties ([ + ('*.clear.button.label', 'Clear'), + ('*.clear.warning', 'Do you want to clear playlist?'), + ('*.clear.confirm', 1) + ]) + + def __init__ (self, pl, prop = None, prefix = ""): + """Initializer.""" + + # Create new properties whth our defaults added + prop = prop and (prop + self.__properties) or self.__properties + prefix += ".clear" + + # Properties + self.__warning = prop.get_value (prefix + ".warning") + self.__confirm = prop.get_value (prefix + ".confirm") + + # Call base contructor + aptk.misc.Button.__init__ (self, prop, prefix) + + self.connect ("clicked", self.__gtkcb_clicked) + self.__pl = pl + + def __gtkcb_clicked (self, w): + """Handler for clicked signal.""" + + # Confirm this action if user warries about its data + if self.__confirm: + d = gtk.MessageDialog (self.get_toplevel (), + gtk.DIALOG_DESTROY_WITH_PARENT, + gtk.MESSAGE_QUESTION, + gtk.BUTTONS_YES_NO, + self.__warning) + + rc = d.run () + d.destroy () + + if rc != gtk.RESPONSE_YES: return + + # Clear if answer is Yes + gtk.threads_leave () + self.__pl.clear () + gtk.threads_enter () + + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + class RemoveButton (aptk.misc.Button): + """Start playback. + """ + + # Defualt properties + __properties = aptk.misc.WidgetProperties ([ + ('*.remove.button.label', 'Remove'), + ('*.remove.warning', 'Do you want to remove selected items from the playlist?'), + ('*.remove.confirm', 1) + ]) + + def __init__ (self, pl, list, prop = None, prefix = ""): + """Initializer.""" + + # Create new properties whth our defaults added + prop = prop and (prop + self.__properties) or self.__properties + prefix += ".remove" + + # Properties + self.__warning = prop.get_value (prefix + ".warning") + self.__confirm = prop.get_value (prefix + ".confirm") + + # Call base contructor + aptk.misc.Button.__init__ (self, prop, prefix) + + self.connect ("clicked", self.__gtkcb_clicked) + self.__pl = pl + self.__list = list + + def __gtkcb_clicked (self, w): + """Handler for remove button clicked signal.""" + + # Confirm this action if user warries about its data + if self.__confirm: + d = gtk.MessageDialog (self.get_toplevel (), + gtk.DIALOG_DESTROY_WITH_PARENT, + gtk.MESSAGE_QUESTION, + gtk.BUTTONS_YES_NO, + self.__warning) + + rc = d.run () + d.destroy () + + if rc != gtk.RESPONSE_YES: return + + selection = self.__list.get_treeview ().get_selection () + + # Create list of items + list = [] + selection.selected_foreach (lambda model, path, iter: list.append (path [0])) + + list.sort () + list.reverse () + + # TODO: FIx this dumb algorithm + gdk.threads_leave () + for n in list: + self.__pl.remove (n+1, n+1) + gdk.threads_enter () + + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + class _ButtonsBox: + """Internal.""" + + def __init__ (self, pl, list, prop = None, prefix = ""): + """Initializeer.""" + + # Create buttons + self.clear_button = ClearButton (pl, prop, prefix) + self.remove_button = RemoveButton (pl, list, prop, prefix) + + # Pack buttons + self.pack_end (self.clear_button, expand = gtk.FALSE) + self.pack_end (self.remove_button, expand = gtk.FALSE) + + # Show these buttons + self.remove_button.show () + self.clear_button.show () + + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + class ButtonsHBox (gtk.HBox, _ButtonsBox): + def __init__ (self, pl, list, prop = None, prefix = ""): + """Initializer.""" + + gtk.HBox.__init__ (self) + _ButtonsBox.__init__ (self, pl, list, prop, prefix) + + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + class ButtonsVBox (gtk.VBox, _ButtonsBox): + def __init__ (self, pl, list, prop = None, prefix = ""): + """Initializer""" + + gtk.VBox.__init__ (self) + _ButtonsBox.__init__ (self, pl, list, prop, prefix) + + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # class PlaylistWindow (gtk.Window): __properties = aptk.misc.WidgetProperties ([ *************** *** 237,244 **** ('*.playlist.remove.button.label', 'Remove'), ('*.playlist.add.button.label', 'Add'), - ('*.playlist.sort.button.label', 'Sort'), ('*.playlist.load.button.label', 'Load'), ! ('*.playlist.save.button.label', 'Save'), ! ('*.playlist.clear.confirm', 'Do you want to clear playlist?') ]) --- 383,388 ---- ('*.playlist.remove.button.label', 'Remove'), ('*.playlist.add.button.label', 'Add'), ('*.playlist.load.button.label', 'Load'), ! ('*.playlist.save.button.label', 'Save') ]) *************** *** 254,260 **** prefix += '.playlist' - # Properties - self.__clear_confirm = prop.get_value (prefix + ".clear.confirm") - # Init base class gtk.Window.__init__ (self) --- 398,401 ---- *************** *** 272,304 **** self.__list.show () ! # Create hbox for buttons ! hbox = gtk.HBox () ! vbox.pack_end (hbox, expand = gtk.FALSE) ! hbox.show () ! ! # Create buttons ! self.add_button = aptk.misc.Button (prop, prefix + ".add") ! hbox.pack_start (self.add_button, expand = gtk.FALSE) ! self.add_button.show () ! ! self.remove_button = aptk.misc.Button (prop, prefix + ".remove") ! hbox.pack_start (self.remove_button, expand = gtk.FALSE) ! self.remove_button.show () ! ! self.sort_button = aptk.misc.Button (prop, prefix + ".sort") ! hbox.pack_start (self.sort_button, expand = gtk.FALSE) ! self.sort_button.show () ! ! self.clear_button = aptk.misc.Button (prop, prefix + ".clear") ! hbox.pack_start (self.clear_button, expand = gtk.FALSE) ! self.clear_button.show () ! ! self.load_button = aptk.misc.Button (prop, prefix + ".load") ! hbox.pack_start (self.load_button, expand = gtk.FALSE) ! self.load_button.show () ! ! self.save_button = aptk.misc.Button (prop, prefix + ".save") ! hbox.pack_start (self.save_button, expand = gtk.FALSE) ! self.save_button.show () # Register this object as the playlist notifier --- 413,420 ---- self.__list.show () ! # Create and add buttons box ! self.__bbox = ButtonsHBox (pl, self.__list, prop, prefix) ! vbox.pack_start (self.__bbox, expand = gtk.FALSE) ! self.__bbox.show () # Register this object as the playlist notifier *************** *** 306,311 **** # Connect signals - self.clear_button.connect ("clicked", self.__gtkcb_clear_clicked) - self.remove_button.connect ("clicked", self.__gtkcb_remove_clicked) self.connect ("destroy", self.__gtkcb_destroy) self.__list.get_treeview ().connect ("row-activated", self.__gtkcb_list_row_activated) --- 422,425 ---- *************** *** 375,414 **** self.__pl.play (path [0] + 1) gdk.threads_enter () - - def __gtkcb_clear_clicked (self, w): - """Handler for clear button clicked signal.""" - - # Confirm this action - d = gtk.MessageDialog (self, - gtk.DIALOG_DESTROY_WITH_PARENT, - gtk.MESSAGE_QUESTION, - gtk.BUTTONS_YES_NO, - self.__clear_confirm) - - rc = d.run () - d.destroy () - - # Clear if answer is Yes - if rc == gtk.RESPONSE_YES: - gtk.threads_leave () - self.__pl.clear () - gtk.threads_enter () - - def __gtkcb_remove_clicked (self, w): - """Handler for remove button clicked signal.""" - - selection = self.__list.get_treeview ().get_selection () - - # Create list of items - list = [] - selection.selected_foreach (lambda model, path, iter: list.append (path [0])) - - list.sort () - list.reverse () - - gdk.threads_leave () - for n in list: - self.__pl.remove (n+1, n+1) - gdk.threads_enter () def __gtkcb_destroy (self, widget): --- 489,492 ---- |