Example #1
0
    def make_misc_functions_notebook(self):
        misc_functions = self.cfg.get("misc_functions")
        self.misc_functions_notebook=miscFunctionNotebook(id=-1,name="misc_notebook",parent=self)
        module4button = {}
        for x in range(len(misc_functions)):        
            try:
                misc_functions[x]
                page_name="tasks"

                try:
                    page_name=misc_functions[x][3]["page"]
                except:
                    pass
                #print "adding "+misc_functions[x][0]+" on "+page_name

                if (not(self.misc_functions_notebook.hasPage(page_name))):
                    self.misc_functions_notebook.addPage(page_name)
                    
                my_page=self.misc_functions_notebook.pages[page_name]

                setattr(self,"miscfunc%i" % (x+1),
                        wxButton(id=-1,
                                 label=misc_functions[x][0],
                                 name='miscfunc%i' % (x+1),
                                 parent=my_page,
                                 pos=wxPoint(0, 32 * (my_page.counter)),
                                 size=wxSize(180, 32), style=0))
                my_page.counter=my_page.counter+1
                try:
                    modul = __import__('factories.'+misc_functions[x][1], globals(),[],[1])
                    clas = getattr(modul, misc_functions[x][2])
                    module4button[x] = clas()
                except:    
                    print "Factory %s crashed when loading class %s... " % (misc_functions[x][1], misc_functions[x][2])
 
                EVT_BUTTON(getattr(self,"miscfunc%i" % (x+1)),
                           getattr(getattr(self,"miscfunc%i" % (x+1)),"GetId")(),
                           module4button[x].GenerateOnPress(self,misc_functions[x][2]))
            
                try:
                    getattr(self,"miscfunc%i" % (x+1)).SetForegroundColour(misc_functions[x][3]["color"])
                except:
                    a="no color"
            except:
                a="outofrange"
        return self.misc_functions_notebook
Example #2
0
    def make_misc_functions(self, type):
        self.modulefunc = {}
	module4button = {}
        misc_functions = self.cfg.get("misc_functions")
	if type == "notebook":
            self.misc_functions_notebook=miscFunctionNotebook(id=-1,name="misc_notebook",parent=self)
	if type == "menu":
	    self.misc_functions_menubar=wxMenuBar()
	    self.menu = {}
        for x in range(len(misc_functions)):	
	    # page name here refer either to the name of the default menu
	    # or the default page
            page_name="tasks"
            try:
                page_name=misc_functions[x][3]["page"]
            except:
                pass
            print "adding "+misc_functions[x][0]+" on "+page_name
            # Create the object that will be clicked on
	    if type == "notebook": 
		if not(self.misc_functions_notebook.hasPage(page_name)):
                    self.misc_functions_notebook.addPage(page_name)
                my_page=self.misc_functions_notebook.pages[page_name]
                # John, shall we use an array here instead of setattr ?
	        setattr(self,"miscfunc%i" % (x+1),
                        wxButton(id=-1,
                        label=misc_functions[x][0],
                        name='miscfunc%i' % (x+1),
                        parent=my_page,
                        pos=wxPoint(0, 32 * (my_page.counter)),
                        size=wxSize(180, 32), style=0))
                my_page.counter=my_page.counter+1
            if type == "menu": 
	        if not self.menu.has_key(page_name):
                    self.menu[page_name] = wxMenu()
                the_menu = self.menu[page_name].Append(x+99, misc_functions[x][0], misc_functions[x][2])
            # Load the function from the factory it comes
            try:
	        modul = __import__('factories.'+misc_functions[x][1], globals(),[],[1])
	    except:    
                print "Factory %s crashed when opening it... " % misc_functions[x][1]
	        import sys
		print sys.exc_info()[0]
	        raise

            try:
	        clas = getattr(modul, misc_functions[x][2])
	    except:    
	 	print "Class " + misc_functions[x][2] + "isn't defined in the factory " + misc_functions[x][1]
            try:
	        module4button[x] = clas()
	    except:
                print "Class %s have crashed when initialized. It was loaded from %s." % (misc_functions[x][2], misc_functions[x][1])
	        import sys
		print sys.exc_info()[0]
	        raise
            try:
                self.modulefunc[x] = module4button[x].GenerateOnPress(self, misc_functions[x][0])
	    except:  
                print "Factory %s GenerateOnPress function doesn't work " % misc_functions[x][2]
	        import sys
		print sys.exc_info()[0]
	        raise
            if type == "notebook":
   	        EVT_BUTTON(getattr(self,"miscfunc%i" % (x+1)),
                       getattr(getattr(self,"miscfunc%i" % (x+1)),"GetId")(),
                       self.modulefunc[x])
            if type == "menu":
		self.Bind(wx.EVT_MENU,  self.modulefunc[x], id=x+99)
            try:
                getattr(self,"miscfunc%i" % (x+1)).SetForegroundColour(misc_functions[x][3]["color"])
            except:
                a="no color"
	if type == "menu":
            for key, val in self.menu.iteritems():
	        self.misc_functions_menubar.Append(self.menu[key], key)
            return_value = self.misc_functions_menubar
	if type == "notebook":
	    return_value = self.misc_functions_notebook
	return return_value
Example #3
0
    def make_misc_functions(self, type):
        self.modulefunc = {}
        module4button = {}
        misc_functions = self.cfg.get("misc_functions")
        if type == "notebook":
            self.misc_functions_notebook = miscFunctionNotebook(
                id=-1, name="misc_notebook", parent=self)
        if type == "menu":
            self.misc_functions_menubar = wxMenuBar()
            self.menu = {}
        for x in range(len(misc_functions)):
            # page name here refer either to the name of the default menu
            # or the default page
            page_name = "tasks"
            try:
                page_name = misc_functions[x][3]["page"]
            except:
                pass
            print "adding " + misc_functions[x][0] + " on " + page_name
            # Create the object that will be clicked on
            if type == "notebook":
                if not (self.misc_functions_notebook.hasPage(page_name)):
                    self.misc_functions_notebook.addPage(page_name)
                my_page = self.misc_functions_notebook.pages[page_name]
                # John, shall we use an array here instead of setattr ?
                setattr(
                    self, "miscfunc%i" % (x + 1),
                    wxButton(id=-1,
                             label=misc_functions[x][0],
                             name='miscfunc%i' % (x + 1),
                             parent=my_page,
                             pos=wxPoint(0, 32 * (my_page.counter)),
                             size=wxSize(180, 32),
                             style=0))
                my_page.counter = my_page.counter + 1
            if type == "menu":
                if not self.menu.has_key(page_name):
                    self.menu[page_name] = wxMenu()
                the_menu = self.menu[page_name].Append(x + 99,
                                                       misc_functions[x][0],
                                                       misc_functions[x][2])
            # Load the function from the factory it comes
            try:
                modul = __import__('factories.' + misc_functions[x][1],
                                   globals(), [], [1])
            except:
                print "Factory %s crashed when opening it... " % misc_functions[
                    x][1]
                import sys
                print sys.exc_info()[0]
                raise

            try:
                clas = getattr(modul, misc_functions[x][2])
            except:
                print "Class " + misc_functions[x][
                    2] + "isn't defined in the factory " + misc_functions[x][1]
            try:
                module4button[x] = clas()
            except:
                print "Class %s have crashed when initialized. It was loaded from %s." % (
                    misc_functions[x][2], misc_functions[x][1])
                import sys
                print sys.exc_info()[0]
                raise
            try:
                self.modulefunc[x] = module4button[x].GenerateOnPress(
                    self, misc_functions[x][0])
            except:
                print "Factory %s GenerateOnPress function doesn't work " % misc_functions[
                    x][2]
                import sys
                print sys.exc_info()[0]
                raise
            if type == "notebook":
                EVT_BUTTON(
                    getattr(self, "miscfunc%i" % (x + 1)),
                    getattr(getattr(self, "miscfunc%i" % (x + 1)), "GetId")(),
                    self.modulefunc[x])
            if type == "menu":
                self.Bind(wx.EVT_MENU, self.modulefunc[x], id=x + 99)
            try:
                getattr(self, "miscfunc%i" % (x + 1)).SetForegroundColour(
                    misc_functions[x][3]["color"])
            except:
                a = "no color"
        if type == "menu":
            for key, val in self.menu.iteritems():
                self.misc_functions_menubar.Append(self.menu[key], key)
            return_value = self.misc_functions_menubar
        if type == "notebook":
            return_value = self.misc_functions_notebook
        return return_value