Esempio n. 1
0
    def __init__(
        self,
        parent,
    ):
        wx.Panel.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          size=wx.Size(600, 300),
                          style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        bSizer1 = wx.BoxSizer(wx.VERTICAL)
        bSizer2 = wx.BoxSizer(wx.HORIZONTAL)
        self.m_staticText1 = wx.StaticText(self, wx.ID_ANY, "Search:",
                                           wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.m_staticText1.Wrap(-1)
        bSizer2.Add(self.m_staticText1, 0,
                    wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, 5)
        self.txt_search = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
                                      wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer2.Add(self.txt_search, 1, wx.ALL, 5)

        bSizer3 = wx.BoxSizer(wx.HORIZONTAL)
        self.btn_install = wx.Button(self, wx.ID_ANY, 'Install/Update',
                                     wx.DefaultPosition, wx.DefaultSize,
                                     wx.BU_EXACTFIT)
        self.btn_uninstall = wx.Button(self, wx.ID_ANY, 'Remove',
                                       wx.DefaultPosition, wx.DefaultSize,
                                       wx.BU_EXACTFIT)
        self.chk_has = wx.CheckBox(self, wx.ID_ANY, 'only installed',
                                   wx.DefaultPosition, wx.DefaultSize, 0)

        bSizer3.Add(self.chk_has, 0, wx.ALL | wx.EXPAND, 5)
        bSizer3.AddStretchSpacer(1)
        bSizer3.Add(self.btn_install, 0, wx.ALL, 5)
        bSizer3.Add(self.btn_uninstall, 0, wx.ALL, 5)
        bSizer1.Add(bSizer2, 0, wx.EXPAND, 5)
        self.lst_plgs = VirtualListCtrl(
            self, ['Name', 'Author', 'Version', 'Status'])
        self.lst_plgs.SetColumnWidth(0, 100)
        self.lst_plgs.SetColumnWidth(1, 100)
        self.lst_plgs.SetColumnWidth(2, 60)
        self.lst_plgs.SetColumnWidth(3, 60)
        self.htmlpanel = MDPad(self)
        bSizer1.Add(self.lst_plgs, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 5)
        bSizer1.Add(bSizer3, 0, wx.EXPAND, 5)
        sizer.Add(bSizer1, 0, wx.ALL | wx.EXPAND, 0)
        sizer.Add(self.htmlpanel, 1, wx.ALL | wx.EXPAND, 5)

        self.SetSizer(sizer)
        self.Layout()
        self.Centre(wx.BOTH)
        # Connect Events
        self.txt_search.Bind(wx.EVT_TEXT, self.on_search)
        self.lst_plgs.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_run)
        self.btn_install.Bind(wx.EVT_BUTTON, self.on_install)
        self.btn_uninstall.Bind(wx.EVT_BUTTON, self.on_remove)
        self.chk_has.Bind(wx.EVT_CHECKBOX, self.on_check)
        self.load()
Esempio n. 2
0
    def __init__(self, parent, app=None):
        wx.Panel.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          size=wx.Size(500, 300),
                          style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
        self.app = app
        bSizer1 = wx.BoxSizer(wx.HORIZONTAL)

        self.tre_plugins = wx.TreeCtrl(self, wx.ID_ANY, wx.DefaultPosition,
                                       wx.DefaultSize, wx.TR_DEFAULT_STYLE)
        self.tre_plugins.SetMinSize(wx.Size(300, -1))

        bSizer1.Add(self.tre_plugins, 0, wx.ALL | wx.EXPAND, 5)
        bSizer3 = wx.BoxSizer(wx.VERTICAL)
        bSizer4 = wx.BoxSizer(wx.HORIZONTAL)

        self.m_staticText2 = wx.StaticText(self, wx.ID_ANY,
                                           "Plugin Information",
                                           wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.m_staticText2.Wrap(-1)
        bSizer4.Add(self.m_staticText2, 0, wx.ALL, 5)

        self.m_staticText3 = wx.StaticText(self, wx.ID_ANY, "[SourceCode]",
                                           wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.m_staticText3.Wrap(-1)
        self.m_staticText3.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT))

        bSizer4.Add(self.m_staticText3, 0, wx.ALL, 5)
        bSizer3.Add(bSizer4, 0, wx.EXPAND, 5)

        self.txt_info = MDPad(self)
        bSizer3.Add(self.txt_info, 1, wx.ALL | wx.EXPAND, 5)

        bSizer1.Add(bSizer3, 1, wx.EXPAND, 5)
        self.SetSizer(bSizer1)
        self.Layout()

        self.Centre(wx.BOTH)

        # Connect Events
        self.tre_plugins.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.on_run)
        self.tre_plugins.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_select)
        self.m_staticText3.Bind(wx.EVT_LEFT_DOWN, self.on_source)
        self.plg = None
        self.load()
Esempio n. 3
0
class Plugin(wx.Panel):
    title = 'Plugins Manager'
    single = None

    def __init__(
        self,
        parent,
    ):
        wx.Panel.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          size=wx.Size(600, 300),
                          style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        bSizer1 = wx.BoxSizer(wx.VERTICAL)
        bSizer2 = wx.BoxSizer(wx.HORIZONTAL)
        self.m_staticText1 = wx.StaticText(self, wx.ID_ANY, "Search:",
                                           wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.m_staticText1.Wrap(-1)
        bSizer2.Add(self.m_staticText1, 0,
                    wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, 5)
        self.txt_search = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
                                      wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer2.Add(self.txt_search, 1, wx.ALL, 5)

        bSizer3 = wx.BoxSizer(wx.HORIZONTAL)
        self.btn_install = wx.Button(self, wx.ID_ANY, 'Install/Update',
                                     wx.DefaultPosition, wx.DefaultSize,
                                     wx.BU_EXACTFIT)
        self.btn_uninstall = wx.Button(self, wx.ID_ANY, 'Remove',
                                       wx.DefaultPosition, wx.DefaultSize,
                                       wx.BU_EXACTFIT)
        self.chk_has = wx.CheckBox(self, wx.ID_ANY, 'only installed',
                                   wx.DefaultPosition, wx.DefaultSize, 0)

        bSizer3.Add(self.chk_has, 0, wx.ALL | wx.EXPAND, 5)
        bSizer3.AddStretchSpacer(1)
        bSizer3.Add(self.btn_install, 0, wx.ALL, 5)
        bSizer3.Add(self.btn_uninstall, 0, wx.ALL, 5)
        bSizer1.Add(bSizer2, 0, wx.EXPAND, 5)
        self.lst_plgs = VirtualListCtrl(
            self, ['Name', 'Author', 'Version', 'Status'])
        self.lst_plgs.SetColumnWidth(0, 100)
        self.lst_plgs.SetColumnWidth(1, 100)
        self.lst_plgs.SetColumnWidth(2, 60)
        self.lst_plgs.SetColumnWidth(3, 60)
        self.htmlpanel = MDPad(self)
        bSizer1.Add(self.lst_plgs, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 5)
        bSizer1.Add(bSizer3, 0, wx.EXPAND, 5)
        sizer.Add(bSizer1, 0, wx.ALL | wx.EXPAND, 0)
        sizer.Add(self.htmlpanel, 1, wx.ALL | wx.EXPAND, 5)

        self.SetSizer(sizer)
        self.Layout()
        self.Centre(wx.BOTH)
        # Connect Events
        self.txt_search.Bind(wx.EVT_TEXT, self.on_search)
        self.lst_plgs.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_run)
        self.btn_install.Bind(wx.EVT_BUTTON, self.on_install)
        self.btn_uninstall.Bind(wx.EVT_BUTTON, self.on_remove)
        self.chk_has.Bind(wx.EVT_CHECKBOX, self.on_check)
        self.load()

    #def list_plg(self, lst, items
    def load(self):
        here = os.path.abspath(os.path.dirname(__file__))
        has = glob.glob(os.path.join(root_dir, 'plugins/*/*.md'))
        fs = glob.glob(here + '/Contributions/*.md')
        prjs = [p for p in [parse(i) for i in fs] if not p is None]
        has = [p for p in [parse(i) for i in has] if not p is None]
        keys = set([i['path'] for i in prjs])
        for i in has:
            if not i['path'] in keys: prjs.append(i)
        prjs = sorted([(i['name'] + str(random.random()), i) for i in prjs])
        self.prjs = [i[1] for i in prjs]

        for i in self.prjs:
            for j in has:
                if i['path'] == j['path']:
                    i['old'] = j['version']
                    i['folder'] = os.path.split(j['file'])[0]
        self.on_search(None)

    # Virtual event handlers, overide them in your derived class
    def on_search(self, event):
        wd = self.txt_search.GetValue()
        f = lambda x: '' if not 'old' in x else ['update', 'installed'][x[
            'old'] == x['version']]
        self.buf = [[i['name'], i['author'], i['version'],
                     f(i), i] for i in self.prjs
                    if wd.lower() in str(i).lower()]
        if self.chk_has.GetValue():
            self.buf = [i for i in self.buf if i[3] != '']
        self.lst_plgs.set_data(self.buf)
        self.lst_plgs.Refresh()

    def on_run(self, event):
        f = open(self.buf[event.GetIndex()][-1]['file'], encoding='utf-8')
        cont = f.read()
        f.close()
        cont = '\n'.join([i.strip() for i in cont.split('\n')])
        self.htmlpanel.set_cont(cont)

    def on_install(self, event):
        i = self.lst_plgs.GetFirstSelected()
        if i == -1: return
        path = self.buf[i][-1]['path']
        Source.manager('plugin').get('Install Plugins')().start(
            {'repo': self.buf[i][-1]['path']}, self.load)

    def on_remove(self, event):
        i = self.lst_plgs.GetFirstSelected()
        if i == -1: return
        shutil.rmtree(self.buf[i][-1]['folder'])
        IPy.reload_plgs(True, True, True, True)
        self.load()

    def on_check(self, event):
        self.load()
Esempio n. 4
0
class Plugin(wx.Panel):
    title = 'Plugin Tree View'
    single = None

    def __init__(self, parent, app=None):
        wx.Panel.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          size=wx.Size(500, 300),
                          style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
        self.app = app
        bSizer1 = wx.BoxSizer(wx.HORIZONTAL)

        self.tre_plugins = wx.TreeCtrl(self, wx.ID_ANY, wx.DefaultPosition,
                                       wx.DefaultSize, wx.TR_DEFAULT_STYLE)
        self.tre_plugins.SetMinSize(wx.Size(300, -1))

        bSizer1.Add(self.tre_plugins, 0, wx.ALL | wx.EXPAND, 5)
        bSizer3 = wx.BoxSizer(wx.VERTICAL)
        bSizer4 = wx.BoxSizer(wx.HORIZONTAL)

        self.m_staticText2 = wx.StaticText(self, wx.ID_ANY,
                                           "Plugin Information",
                                           wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.m_staticText2.Wrap(-1)
        bSizer4.Add(self.m_staticText2, 0, wx.ALL, 5)

        self.m_staticText3 = wx.StaticText(self, wx.ID_ANY, "[SourceCode]",
                                           wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.m_staticText3.Wrap(-1)
        self.m_staticText3.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT))

        bSizer4.Add(self.m_staticText3, 0, wx.ALL, 5)
        bSizer3.Add(bSizer4, 0, wx.EXPAND, 5)

        self.txt_info = MDPad(self)
        bSizer3.Add(self.txt_info, 1, wx.ALL | wx.EXPAND, 5)

        bSizer1.Add(bSizer3, 1, wx.EXPAND, 5)
        self.SetSizer(bSizer1)
        self.Layout()

        self.Centre(wx.BOTH)

        # Connect Events
        self.tre_plugins.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.on_run)
        self.tre_plugins.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_select)
        self.m_staticText3.Bind(wx.EVT_LEFT_DOWN, self.on_source)
        self.plg = None
        self.load()

    def addnode(self, parent, data):
        for i in data:
            if i == '-': continue
            if isinstance(i, tuple):
                item = self.tre_plugins.AppendItem(parent, i[0].title)
                self.tre_plugins.SetItemData(item, i[0])
                self.addnode(item, i[1])
            else:
                item = self.tre_plugins.AppendItem(parent, i.title)
                self.tre_plugins.SetItemData(item, i)

    def load(self):
        datas = loader.build_plugins('menus')
        keydata = {}
        for i in datas[1]:
            if isinstance(i, tuple):
                keydata[i[0].__name__.split('.')[-1]] = i[1]
        #print(keydata)
        extends = glob('plugins/*/menus')
        for i in extends:
            plgs = loader.build_plugins(i)
            for j in plgs[1]:
                if not isinstance(j, tuple): continue
                name = j[0].__name__.split('.')[-1]
                if name in keydata:
                    keydata[name].extend(j[1])
                else:
                    datas[1].append(j)
        root = self.tre_plugins.AddRoot('Plugins')
        self.addnode(root, datas[1])

    # Virtual event handlers, overide them in your derived class
    def on_run(self, event):
        plg = self.tre_plugins.GetItemPyData(event.GetItem())
        if hasattr(plg, 'start'): plg().start(self.app)

    def on_select(self, event):
        plg = self.tre_plugins.GetItemData(event.GetItem())
        if plg != None:
            self.plg = plg
            name = self.tre_plugins.GetItemText(event.GetItem())
            lang = Source.manager('config').get('language')
            doc = Source.manager('document').get(name, tag=lang)
            doc = doc or Source.manager('document').get(name, tag='English')
            self.txt_info.set_cont(doc or 'No Document!')

    def on_source(self, event):
        ## TODO: should it be absolute path ?
        filename = self.plg.__module__.replace('.', '/') + '.py'
        #print('==========', filename)
        root = os.path.split(root_dir)[0]
        filename = os.path.join(root, filename)
        #print(filename)
        EditorFrame(filename=filename).Show()
Esempio n. 5
0
class Plugin(wx.Panel):
    title = 'Tool Tree View'
    single = None

    def __init__(self, parent):
        wx.Frame.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          size=wx.Size(500, 300),
                          style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
        self.app = parent
        bSizer1 = wx.BoxSizer(wx.HORIZONTAL)

        self.tre_plugins = wx.TreeCtrl(self, wx.ID_ANY, wx.DefaultPosition,
                                       wx.DefaultSize, wx.TR_DEFAULT_STYLE)
        self.tre_plugins.SetMinSize(wx.Size(200, -1))

        bSizer1.Add(self.tre_plugins, 0, wx.ALL | wx.EXPAND, 5)
        bSizer3 = wx.BoxSizer(wx.VERTICAL)
        bSizer4 = wx.BoxSizer(wx.HORIZONTAL)

        self.m_staticText2 = wx.StaticText(self, wx.ID_ANY, "Tool Infomation:",
                                           wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.m_staticText2.Wrap(-1)
        bSizer4.Add(self.m_staticText2, 0, wx.ALL, 5)

        self.m_staticText3 = wx.StaticText(self, wx.ID_ANY, "[SourceCode]",
                                           wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.m_staticText3.Wrap(-1)
        self.m_staticText3.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT))

        bSizer4.Add(self.m_staticText3, 0, wx.ALL, 5)
        bSizer3.Add(bSizer4, 0, wx.EXPAND, 5)

        self.txt_info = MDPad(self)
        bSizer3.Add(self.txt_info, 1, wx.ALL | wx.EXPAND, 5)

        bSizer1.Add(bSizer3, 1, wx.EXPAND, 5)
        self.SetSizer(bSizer1)
        self.Layout()

        self.Centre(wx.BOTH)

        # Connect Events
        self.tre_plugins.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.on_run)
        self.tre_plugins.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_select)
        self.m_staticText3.Bind(wx.EVT_LEFT_DOWN, self.on_source)
        self.plg = None
        self.load()

    def addnode(self, parent, data):
        for i in data:
            if i == '-': continue
            if isinstance(i, tuple):
                item = self.tre_plugins.AppendItem(parent, i[0].title)
                self.tre_plugins.SetItemData(item, i[0])
                self.addnode(item, i[1])
            else:
                item = self.tre_plugins.AppendItem(parent, i[0].title)
                self.tre_plugins.SetItemData(item, i[0])

    def load(self):
        datas = loader.build_tools('tools')
        extends = glob('plugins/*/tools')
        for i in extends:
            tols = loader.build_tools(i)
            if len(tols) != 0: datas[1].extend(tols[1])

        root = self.tre_plugins.AddRoot('Tools')
        for i in datas[1]:
            item = self.tre_plugins.AppendItem(root, i[0].title)
            self.tre_plugins.SetItemData(item, i[0])
            for j in i[1]:
                it = self.tre_plugins.AppendItem(item, j[0].title)
                self.tre_plugins.SetItemData(it, j[0])

    # Virtual event handlers, overide them in your derived class
    def on_run(self, event):
        plg = self.tre_plugins.GetItemData(event.GetItem())
        if hasattr(plg, 'start'): plg().start(self.app)

    def on_select(self, event):
        plg = self.tre_plugins.GetItemData(event.GetItem())
        if plg != None:
            self.plg = plg
            name = self.tre_plugins.GetItemText(event.GetItem())
            self.txt_info.set_cont(Source.manager('document').get(name))

    def on_source(self, event):
        ## TODO: should it be absolute path ?
        filename = self.plg.__module__.replace('.', '/') + '.py'
        root = os.path.split(root_dir)[0]
        filename = os.path.join(root, filename)
        EditorFrame(filename=filename).Show()
def md_pad_test():
    frame = wx.Frame(None, title='Text Pad')
    mdpad = MDPad(frame)
    mdpad.set_cont(mdstr)
    frame.Show()