コード例 #1
0
ファイル: UI.py プロジェクト: ProfSteve/conduit
    def __init__(self, conduitApplication, moduleManager, typeConverter, syncManager):
        hildon.Program.__init__(self)

        #add some additional dirs to the icon theme search path so that
        #modules can provider their own icons
        icon_dirs = [
                    conduit.SHARED_DATA_DIR,
                    conduit.SHARED_MODULE_DIR,
                    os.path.join(conduit.SHARED_DATA_DIR,"icons"),
                    os.path.join(conduit.USER_DIR, "modules")
                    ]
        for i in icon_dirs:                    
            gtk.icon_theme_get_default().prepend_search_path(i)
            log.debug("Adding %s to icon theme search path" % (i))

        self.conduitApplication = conduitApplication
        self.type_converter = typeConverter
        self.sync_manager = syncManager
        self.syncSet = None

        self.mainWindow = hildon.Window()
        self.mainWindow.set_icon_name("conduit")
        # self.mainWindow.resize (800, 480)

        self.mainWindow.connect("destroy", self.on_window_destroyed)
        self.add_window(self.mainWindow)

        self.provider_box = DataProviderBox ()
        self.provider_box.combo.set_active (0)

        # FIXME: we should do something hildon specific
        self.canvas = Canvas(
                        parentWindow=self.mainWindow,
                        typeConverter=self.type_converter,
                        syncManager=self.sync_manager)

        self.canvas.connect('drag-drop', self.drop_cb)
        self.canvas.connect("drag-data-received", self.drag_data_received_data)

        main_pane = gtk.HPaned ()
        main_pane.add1(self.provider_box)
        main_pane.add2(self.canvas)
        self.mainWindow.add(main_pane)
コード例 #2
0
ファイル: UI.py プロジェクト: ProfSteve/conduit
class MainWindow(hildon.Program):
    def __init__(self, conduitApplication, moduleManager, typeConverter, syncManager):
        hildon.Program.__init__(self)

        #add some additional dirs to the icon theme search path so that
        #modules can provider their own icons
        icon_dirs = [
                    conduit.SHARED_DATA_DIR,
                    conduit.SHARED_MODULE_DIR,
                    os.path.join(conduit.SHARED_DATA_DIR,"icons"),
                    os.path.join(conduit.USER_DIR, "modules")
                    ]
        for i in icon_dirs:                    
            gtk.icon_theme_get_default().prepend_search_path(i)
            log.debug("Adding %s to icon theme search path" % (i))

        self.conduitApplication = conduitApplication
        self.type_converter = typeConverter
        self.sync_manager = syncManager
        self.syncSet = None

        self.mainWindow = hildon.Window()
        self.mainWindow.set_icon_name("conduit")
        # self.mainWindow.resize (800, 480)

        self.mainWindow.connect("destroy", self.on_window_destroyed)
        self.add_window(self.mainWindow)

        self.provider_box = DataProviderBox ()
        self.provider_box.combo.set_active (0)

        # FIXME: we should do something hildon specific
        self.canvas = Canvas(
                        parentWindow=self.mainWindow,
                        typeConverter=self.type_converter,
                        syncManager=self.sync_manager)

        self.canvas.connect('drag-drop', self.drop_cb)
        self.canvas.connect("drag-data-received", self.drag_data_received_data)

        main_pane = gtk.HPaned ()
        main_pane.add1(self.provider_box)
        main_pane.add2(self.canvas)
        self.mainWindow.add(main_pane)

    def set_model(self, syncSet):
        self.syncSet = syncSet
        self.toolbar = ConduitToolbar(self.syncSet, self.canvas)
        self.canvas.set_sync_set(syncSet)
        
        self.set_common_toolbar(self.toolbar)

    def present(self):
        """
        Present the main window. Enjoy your window
        """
        self.mainWindow.show_all ()

    def minimize_to_tray(self):
        """
        Iconifies the main window
        """
        log.debug("Iconifying GUI")
        self.mainWindow.hide()

    def is_visible(self):
        """
        Dummy for now
        """
        return True

    def drop_cb(self, wid, context, x, y, time):
        """
        drop cb
        """
        self.canvas.drag_get_data(context, context.targets[0], time)
        return True
        
    def drag_data_received_data(self, treeview, context, x, y, selection, info, etime):
        """
        DND
        """
        dataproviderKey = selection.data
        #FIXME: DnD should be cancelled in the Treeview on the drag-begin 
        #signal and NOT here
        if dataproviderKey != "":
            #Add a new instance if the dataprovider to the canvas.
            new = conduit.GLOBALS.moduleManager.get_module_wrapper_with_instance(dataproviderKey)
            self.canvas.add_dataprovider_to_canvas(dataproviderKey, new, x, y)
        
        context.finish(True, True, etime)
        return
 
    def on_window_destroyed(self, widget, event=None):
        """
        Check if there are any synchronizations currently in progress and
        ask the user if they wish to cancel them
        """
        busy = False
        quit = False

        if self.syncSet:
            for c in self.syncSet.get_all_conduits(): 
                if c.is_busy():
                    busy = True
               
        if busy:       
            dialog = gtk.MessageDialog(
                            self.mainWindow,
                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                            gtk.MESSAGE_QUESTION,
                            gtk.BUTTONS_YES_NO,_("Synchronization in progress. Do you want to cancel it?")
                            )
            response = dialog.run()
            if response == gtk.RESPONSE_YES:
                quit = True
            else:
                #Dont exit
                dialog.destroy()
                return True
        else:
            quit = True
            
        #OK, if we have decided to quit then call quit on the 
        #DBus interface which will tidy up any pending running
        #non gui tasks
        if quit:
            log.debug("Quitting...")
            self.conduitApplication.Quit()
            
    def save_settings(self, widget):
        pass