Source code for Loader_gtk

# Loader_gtk.py
# By MW, Jul 2013
# GPLv3+
#
# Graphical interface to load movies

# ==== Importations
import imp, logging, gtk

LoadFolders_gtk = imp.load_source("LoadFolders_gtk", './bin/Movies/Loader/load_folders_gtk.py')
LoadModulo_gtk = imp.load_source("LoadModulo", './bin/Movies/Loader/load_modulo_gtk.py')
LoadFile_gtk = imp.load_source("LoadFile", './bin/Movies/Loader/load_file_gtk.py')
#LoadModulo_gtk = imp.load_source("LoadModulo_gtk", './bin/Movies/Loader/load_folders_gtk.py')


[docs]class Loader_gtk : def __init__(self) : self.win_size = (250, 400) load_modulo = LoadModulo_gtk.Loader() load_folders = LoadFolders_gtk.Loader() load_file = LoadFile_gtk.Loader() self.loaders_list = [load_folders, load_modulo, load_file] self.frames_object = None
[docs] def get_panel(self) : """Creates the loader window. The window is created in a non-blocking fashion (other window will show up if instanciated). To launch the window in a blocking fashion, use run_panel()""" self.window = gtk.Window() self.window.set_border_width(5) self.window.set_default_size(self.win_size[0], self.win_size[1]) self.window.set_title("Load a movie") self.window.connect("destroy", lambda w: gtk.main_quit()) ### TO CHANGE mainbox = gtk.VBox() self.window.add(mainbox) # Menu m = self.get_menu() mainbox.pack_start(m, fill=False, expand=False) # Tabs self.notebook = gtk.Notebook() mainbox.pack_start(self.notebook, fill=True, expand=True) # Adding gtk loaders for loader in self.loaders_list : self.notebook.append_page(loader.get_panel(), gtk.Label(loader.get_name())) # Ok/Cancel bottom_box = gtk.HBox() bottom_box.pack_start(gtk.Label(' '), fill=True, expand=True) ok = gtk.Button() ok_i = gtk.Image() ok_i.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_SMALL_TOOLBAR) ok.add(ok_i) ok.set_tooltip_text("Load channels") ok.connect('clicked', self.load_evt, self.notebook) cancel = gtk.Button() cancel_i = gtk.Image() cancel_i.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_SMALL_TOOLBAR) cancel.add(cancel_i) cancel.set_tooltip_text("Cancel (and exit)") cancel.connect('clicked', self.quit) bottom_box.pack_start(ok, fill=False, expand=False) bottom_box.pack_start(cancel, fill=False, expand=False) mainbox.pack_start(bottom_box, fill=False, expand=False) self.window.show_all()
[docs] def get_menu(self) : self.menubar = gtk.MenuBar() # Menu file menu_file = gtk.Menu() menu_file_m = gtk.MenuItem("File") menu_file_m.set_submenu(menu_file) menu_exit = gtk.MenuItem("Exit") menu_exit.connect("activate", self.quit) menu_file.append(menu_exit) self.menubar.append(menu_file_m) self.menubar.show_all() return self.menubar
[docs] def quit(self, w) : self.window.destroy()
[docs] def load_evt(self, w, notebook) : """Loads all the required files and prepare everything for the main window""" loader = self.loaders_list[notebook.get_current_page()] frames_object = loader.get_frames_object() #print frames_list names = [] emptyname = False if frames_object['type'] == 'frames' : # Looking for empty channel names for ch in frames_object['value'] : n = ch['name'] names.append(n) if n == '' : emptyname = True # No file selected if frames_object['value'] == [] : dialog = gtk.MessageDialog(self.window, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, "No file selected!") dialog.run() dialog.destroy() elif emptyname : dialog = gtk.MessageDialog(self.window, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, "Some channels have empty name!") dialog.run() dialog.destroy() elif len(names) != len(set(names)) :# check for duplicate names dialog = gtk.MessageDialog(self.window, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, "Some channel names are duplicated!") dialog.run() dialog.destroy() else : # create channels self.frames_object = frames_object logging.info("%s channels loaded", str(len(frames_object['value']))) logging.info("%s frames loaded", str(len(frames_object['value'][0]['frames']))) else : self.frames_object = frames_object logging.info("Save session loaded") self.window.destroy()
[docs] def run_panel(self) : """Runs the panel in a blocking fashion (launches gtk.main()). Use get_panel to launch the panel without starting the main""" self.get_panel() gtk.main()
[docs] def get_frames_object(self) : """Returns a dict containing the channels to load""" return self.frames_object
if __name__ == "__main__" : loader = Loader_gtk() loader.get_panel() gtk.main()