Source code for load_folders_gtk

# load_folders_gtk.py
# By MW, Jul 2013
# GPLv3+
#
# Graphical interface to load multi folders data

import gtk, logging, imp
LoadFolders = imp.load_source("LoadFolders", './bin/Movies/Loader/load_folders.py')


[docs]class Loader : def __init__(self) : self.main_label = "Use this tab if your channels are splitted into different folders, one per channel." self.name = "Channels in folders" self.lines_list = [] self.loader = LoadFolders.Loader()
[docs] def get_frames_object(self) : """Queries an object like : [{name: " ", frames: (..., ...)}, ...]""" for line in self.lines_list : self.loader.add_channel(line['path_w'].get_text(), line['name_w'].get_text()) return self.loader.get_frames_object()
[docs] def get_panel(self) : mainbox = gtk.VBox() main_l = gtk.Label(self.main_label) main_l.set_line_wrap_mode(True) mainbox.pack_start(main_l, fill=False, expand=False) frame = gtk.Frame("Folders") mainbox.pack_start(frame, fill=True, expand=False) frame_box = gtk.VBox() self.box = gtk.VBox() frame_box.pack_start(self.box, expand=True, fill=True) frame.add(frame_box) line = self.get_newline() self.box.pack_start(line, expand=False, fill=False) add = gtk.Button() add_i = gtk.Image() add_i.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_SMALL_TOOLBAR) add.add(add_i) add.set_tooltip_text("Add channel") add.connect('clicked', self.add_channel_evt) #add.connect("clicked", self.previous_next_clicked, -1) frame_bottom_box = gtk.HBox() frame_bottom_box.pack_start(gtk.Label(' '), fill=True, expand=True) frame_bottom_box.pack_start(add, fill=False, expand=False) frame_box.pack_start(frame_bottom_box, fill=False, expand=False) mainbox.show_all() return mainbox
[docs] def get_newline(self) : """Returns a new line to open a new folder""" widget = gtk.HBox() chname_l = gtk.Label("Channel name:") chname_e = gtk.Entry() chname_e.set_width_chars(6) path_l = gtk.Label("Folder:") path_e = gtk.Entry() browse_b = gtk.Button("Browse...") browse_b.connect('clicked', self.browse_evt, path_e) delete = gtk.Button() delete_i = gtk.Image() delete_i.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_SMALL_TOOLBAR) delete.add(delete_i) delete.set_tooltip_text("Remove channel") delete.connect('clicked', self.delete_line_evt, widget) #add.connect("clicked", self.previous_next_clicked, -1) widget.pack_start(chname_l, fill=False, expand=False) widget.pack_start(chname_e, fill=False, expand=False) widget.pack_start(path_l, fill=False, expand=False) widget.pack_start(path_e, fill=True, expand=True) widget.pack_start(browse_b, fill=False, expand=False) widget.pack_start(delete, fill=False, expand=False) self.lines_list.append({'line_w':widget, 'name_w':chname_e, 'path_w':path_e, 'delete_b':delete}) #print len(self.lines_list) if len(self.lines_list) == 1 : delete.set_sensitive(False) else : for w in self.lines_list : w['delete_b'].set_sensitive(True) return widget
[docs] def get_name(self) : return self.name
[docs] def add_channel_evt(self, w) : l = self.get_newline() l.show_all() self.box.pack_start(l, fill=False, expand=False)
[docs] def delete_line_evt(self, b, widget) : self.box.remove(widget) line = None i = 0 # remove from list while (i<len(self.lines_list)) and (self.lines_list[i]['line_w'] != widget) : i+=1 self.lines_list.pop(i) if len(self.lines_list) == 1 : self.lines_list[0]['delete_b'].set_sensitive(False)
[docs] def browse_evt(self, w, path_e) : dialog = gtk.FileChooserDialog("Select folder with channels", action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) resp = dialog.run() if resp == gtk.RESPONSE_OK : f = dialog.get_filename() logging.info("Folder selected %s", f) path_e.set_text(f) dialog.destroy()