Esempio n. 1
0
def makeactions(actions_list):
    actions = {}
    actions['-'] = obj = EasyUtils.EMPTY_CLASS()
    obj.type = wx.ITEM_SEPARATOR
    for i in actions_list:
        obj = EasyUtils.EMPTY_CLASS()
        obj_id, obj.caption, obj.type, obj.shorttip, obj.longtip, obj.image, obj.funcname = i
        actions[obj_id] = obj

    return actions
Esempio n. 2
0
def maketoolbar(win, alist, toollist):
    setattr(win.__class__, 'OnExecuteMenuCommand', _OnExecuteMenuCommand)

    win.toolbar = toolbar = win.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER
                                              | wx.TB_FLAT | wx.TB_TEXT)

    #judge image size by the first item of the toolbar item list
    for order, obj_id in toollist:
        obj = alist.get(obj_id, None)
        if not obj:
            raise EasyUtils.EasyException, 'You should define action[%s] first!' % obj_id

        if obj_id == '-': continue
        image = EasyUtils.getimage(obj.image)
        size = wx.Size(image.GetWidth(), image.GetHeight())
        toolbar.SetToolBitmapSize(size)
        break

    toollist.sort()
    for order, obj_id in toollist:
        obj = alist.get(obj_id, None)
        if not obj:
            raise EasyUtils.EasyException, 'You should define action[%s] first!' % obj_id
        if obj_id == '-':
            toolbar.AddSeparator()
        else:
            _type = _item_type.get(obj.type, wx.ITEM_NORMAL)
            image = EasyUtils.getimage(obj.image)
            tool_id = makeid(win, obj_id)
            if not obj.shorttip:
                obj.shorttip = ''
            if not obj.longtip:
                obj.longtip = ''
            if _type == wx.ITEM_NORMAL:
                toolbar.AddSimpleTool(tool_id, image, obj.shorttip,
                                      obj.longtip)
            elif _type == wx.ITEM_CHECK:
                toolbar.AddCheckTool(tool_id, image, obj.shorttip, obj.longtip)
            wx.EVT_TOOL(win, tool_id, win.OnExecuteMenuCommand)
    toolbar.Realize()
Esempio n. 3
0
def maketoolbar(win, alist, toollist):
    setattr(win.__class__, 'OnExecuteMenuCommand', _OnExecuteMenuCommand)

    win.toolbar = toolbar = win.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT | wx.TB_TEXT)

    #judge image size by the first item of the toolbar item list
    for order, obj_id in toollist:
        obj = alist.get(obj_id, None)
        if not obj:
            raise EasyUtils.EasyException, 'You should define action[%s] first!' % obj_id

        if obj_id == '-': continue
        image = EasyUtils.getimage(obj.image)
        size = wx.Size(image.GetWidth(), image.GetHeight())
        toolbar.SetToolBitmapSize(size)
        break

    toollist.sort()
    for order, obj_id in toollist:
        obj = alist.get(obj_id, None)
        if not obj:
            raise EasyUtils.EasyException, 'You should define action[%s] first!' % obj_id
        if obj_id == '-':
            toolbar.AddSeparator()
        else:
            _type = _item_type.get(obj.type, wx.ITEM_NORMAL)
            image = EasyUtils.getimage(obj.image)
            tool_id = makeid(win, obj_id)
            if not obj.shorttip:
                obj.shorttip = ''
            if not obj.longtip:
                obj.longtip = ''
            if _type == wx.ITEM_NORMAL:
                toolbar.AddSimpleTool(tool_id, image, obj.shorttip, obj.longtip)
            elif _type == wx.ITEM_CHECK:
                toolbar.AddCheckTool(tool_id, image, obj.shorttip, obj.longtip)
            wx.EVT_TOOL(win, tool_id, win.OnExecuteMenuCommand)
    toolbar.Realize()
Esempio n. 4
0
    def initlog(self):
        #        import logging
        #        self.log = log = logging.getLogger('EasyGuider')
        #        hdlr = logging.FileHandler('EasyAdmin.log')
        #        formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
        #        hdlr.setFormatter(formatter)
        #        log.addHandler(hdlr)
        #        log.setLevel(logging.WARNING)
        self.log = log = EasyUtils.EMPTY_CLASS()

        def trace():
            #            message = traceback.format_exception(*sys.exc_info())
            #            log.error(''.join(message))
            raise

        log.traceback = trace
Esempio n. 5
0
def makesubmenu(win, alist, mlist, pid):
    menu = wx.Menu()
    if not mlist.has_key(pid):
        return menu
    for i in mlist[pid]:
        order, obj_id = i
        obj = alist.get(obj_id, None)
        if not obj:
            raise EasyUtils.EasyException, 'You should define action[%s] first!' % obj_id

        if mlist.has_key(obj_id):
            menu_id = makeid(win, obj_id)
            submenu = makesubmenu(mlist, win, obj_id, pid)
            menu.AppendMenu(menu_id, obj.caption, submenu)
            win._menuitems[obj_id] = submenu
        else:
            _type = _item_type.get(obj.type, wx.ITEM_NORMAL)
            if obj_id == '-':
                menu.AppendSeparator()
            else:
                menu_id = makeid(win, obj_id)
                if not obj.longtip:
                    obj.longtip = ''
                mitem = wx.MenuItem(menu, menu_id, obj.caption, obj.longtip,
                                    _type)
                if obj.image:
                    image = EasyUtils.getimage(obj.image)
                    if _type == wx.ITEM_CHECK:
                        mitem.SetBitmaps(image)
                    else:
                        mitem.SetBitmap(image)
                menu.AppendItem(mitem)
                win._menuitems[obj_id] = mitem

            if _type in (wx.ITEM_NORMAL, wx.ITEM_CHECK, wx.ITEM_RADIO):
                wx.EVT_MENU(win, menu_id, win.OnExecuteMenuCommand)
    return menu
Esempio n. 6
0
def makesubmenu(win, alist, mlist, pid):
    menu = wx.Menu()
    if not mlist.has_key(pid):
        return menu
    for i in mlist[pid]:
        order, obj_id = i
        obj = alist.get(obj_id, None)
        if not obj:
            raise EasyUtils.EasyException, 'You should define action[%s] first!' % obj_id

        if mlist.has_key(obj_id):
            menu_id = makeid(win, obj_id)
            submenu = makesubmenu(mlist, win, obj_id, pid)
            menu.AppendMenu(menu_id, obj.caption, submenu)
            win._menuitems[obj_id] = submenu
        else:
            _type = _item_type.get(obj.type, wx.ITEM_NORMAL)
            if obj_id == '-':
                menu.AppendSeparator()
            else:
                menu_id = makeid(win, obj_id)
                if not obj.longtip:
                    obj.longtip = ''
                mitem = wx.MenuItem(menu, menu_id, obj.caption, obj.longtip, _type)
                if obj.image:
                    image = EasyUtils.getimage(obj.image)
                    if _type == wx.ITEM_CHECK:
                        mitem.SetBitmaps(image)
                    else:
                        mitem.SetBitmap(image)
                menu.AppendItem(mitem)
                win._menuitems[obj_id] = mitem

            if _type in (wx.ITEM_NORMAL, wx.ITEM_CHECK, wx.ITEM_RADIO):
                wx.EVT_MENU(win, menu_id, win.OnExecuteMenuCommand)
    return menu
Esempio n. 7
0
    def run(self):
        mod = self.mod

        # read config information from imported template module
        if hasattr(mod, "scriptfile") and mod.scriptfile:
            self.scriptfile = mod.scriptfile
        elif hasattr(mod, "templatefile") and mod.templatefile:
            self.templatefile = mod.templatefile
        elif hasattr(mod, "inipickle") and mod.inipickle:
            self.inipickle = mod.inipickle
        elif hasattr(mod, "picklefile") and mod.picklefile:
            self.picklefile = mod.picklefile
        elif hasattr(mod, "outputfile") and mod.outputfile:
            self.outputfile = mod.outputfile
        elif hasattr(mod, "yamlfile") and mod.yamlfile:
            self.yamlfile = mod.yamlfile
            try:
                import yaml
            except:
                self.yamlfile = ""

        if self.picklefile:
            try:
                f = file(self.picklefile)
                import pickle

                self.values = pickle.load(f)
                f.close()
            except:
                self.log.traceback()
        elif self.inipickle:
            try:
                import obj2ini

                self.values = obj2ini.load(self.inipickle)
            except:
                self.log.traceback()
        elif self.yamlfile:
            try:
                import yaml

                self.values = yaml.loadFile(self.yamlfile).next()
            except:
                self.log.traceback()
        self.easy = easy = self.create_easy(mod, self.values)
        if easy.ShowModal() == wx.ID_OK:
            self.values = easy.GetValue()
            if self.picklefile:
                try:
                    import pickle

                    f = file(self.picklefile, "wb")
                    pickle.dump(self.values, f)
                    f.close()
                except:
                    self.log.traceback()
            elif self.inipickle:
                try:
                    import obj2ini

                    obj2ini.dump(self.values, self.inipickle)
                except:
                    self.log.traceback()
            elif self.yamlfile:
                try:
                    import yaml

                    yaml.dumpToFile(file(self.yamlfile, "wb"), self.values)
                except:
                    self.log.traceback()

            if self.scriptfile:
                # cal scriptpath
                SCRIPTPATH = ""
                if hasattr(mod, "__file__"):
                    SCRIPTPATH = os.path.dirname(
                        os.path.abspath(os.path.join(os.path.dirname(mod.__file__), self.scriptfile))
                    )
                # add scriptpath
                # self.values['SCRIPTPATH'] = SCRIPTPATH
                oldworkpath = os.getcwd()
                try:
                    #                    os.chdir(SCRIPTPATH)
                    #                    from meteor import TemplateScript, Template
                    #                    from StringIO import StringIO
                    #                    buf = StringIO()
                    #                    template = Template()
                    #                    template.load(os.path.basename(self.scriptfile), 'text')
                    #                    buf.write(template.value('text', EasyUtils.str_object(self.values, self.outputencoding)))
                    #                    buf.seek(0)
                    #                    ts = TemplateScript()
                    #                    ts.run(buf, self.values, True)
                    if SCRIPTPATH:
                        os.chdir(SCRIPTPATH)
                    from meteor import TemplateScript

                    ts = TemplateScript()
                    ts.run(self.scriptfile, self.values, True)
                finally:
                    os.chdir(oldworkpath)
            #                    if self.verbose:
            #                        print buf.getvalue()
            elif self.templatefile:
                from meteor import Template

                template = Template()
                template.load(self.templatefile)
                if isinstance(self.outputfile, (str, unicode)):
                    f = file(self.outputfile, "wb")
                elif not self.outputfile:
                    f = sys.stdout
                else:
                    f = self.outputfile
                f.write(template.value(values=EasyUtils.str_object(self.values, self.outputencoding)))
            return True
        else:
            return False
Esempio n. 8
0
    def run(self):
        mod = self.mod

        #read config information from imported template module
        if hasattr(mod, 'scriptfile') and mod.scriptfile:
            self.scriptfile = mod.scriptfile
        elif hasattr(mod, 'templatefile') and mod.templatefile:
            self.templatefile = mod.templatefile
        elif hasattr(mod, 'inipickle') and mod.inipickle:
            self.inipickle = mod.inipickle
        elif hasattr(mod, 'picklefile') and mod.picklefile:
            self.picklefile = mod.picklefile
        elif hasattr(mod, 'outputfile') and mod.outputfile:
            self.outputfile = mod.outputfile
        elif hasattr(mod, 'yamlfile') and mod.yamlfile:
            self.yamlfile = mod.yamlfile
            try:
                import yaml
            except:
                self.yamlfile = ''

        if self.picklefile:
            try:
                f = file(self.picklefile)
                import pickle
                self.values = pickle.load(f)
                f.close()
            except:
                self.log.traceback()
        elif self.inipickle:
            try:
                import obj2ini
                self.values = obj2ini.load(self.inipickle)
            except:
                self.log.traceback()
        elif self.yamlfile:
            try:
                import yaml
                self.values = yaml.loadFile(self.yamlfile).next()
            except:
                self.log.traceback()
        self.easy = easy = self.create_easy(mod, self.values)
        if easy.ShowModal() == wx.ID_OK:
            self.values = easy.GetValue()
            if self.picklefile:
                try:
                    import pickle
                    f = file(self.picklefile, 'wb')
                    pickle.dump(self.values, f)
                    f.close()
                except:
                    self.log.traceback()
            elif self.inipickle:
                try:
                    import obj2ini
                    obj2ini.dump(self.values, self.inipickle)
                except:
                    self.log.traceback()
            elif self.yamlfile:
                try:
                    import yaml
                    yaml.dumpToFile(file(self.yamlfile, 'wb'), self.values)
                except:
                    self.log.traceback()

            if self.scriptfile:
                #cal scriptpath
                SCRIPTPATH = ''
                if hasattr(mod, '__file__'):
                    SCRIPTPATH = os.path.dirname(
                        os.path.abspath(
                            os.path.join(os.path.dirname(mod.__file__),
                                         self.scriptfile)))
                #add scriptpath
                #self.values['SCRIPTPATH'] = SCRIPTPATH
                oldworkpath = os.getcwd()
                try:
                    #                    os.chdir(SCRIPTPATH)
                    #                    from meteor import TemplateScript, Template
                    #                    from StringIO import StringIO
                    #                    buf = StringIO()
                    #                    template = Template()
                    #                    template.load(os.path.basename(self.scriptfile), 'text')
                    #                    buf.write(template.value('text', EasyUtils.str_object(self.values, self.outputencoding)))
                    #                    buf.seek(0)
                    #                    ts = TemplateScript()
                    #                    ts.run(buf, self.values, True)
                    if SCRIPTPATH:
                        os.chdir(SCRIPTPATH)
                    from meteor import TemplateScript
                    ts = TemplateScript()
                    ts.run(self.scriptfile, self.values, True)
                finally:
                    os.chdir(oldworkpath)


#                    if self.verbose:
#                        print buf.getvalue()
            elif self.templatefile:
                from meteor import Template
                template = Template()
                template.load(self.templatefile)
                if isinstance(self.outputfile, (str, unicode)):
                    f = file(self.outputfile, 'wb')
                elif not self.outputfile:
                    f = sys.stdout
                else:
                    f = self.outputfile
                f.write(
                    template.value(values=EasyUtils.str_object(
                        self.values, self.outputencoding)))
            return True
        else:
            return False