Skip to content

Commit 3173309

Browse files
committed
plugin installer
1 parent f653d63 commit 3173309

File tree

6 files changed

+52
-20
lines changed

6 files changed

+52
-20
lines changed

imagepy/menus/Plugins/Contribute/Contribute Plugin.md

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Site Plugins Catlog
2+
3+
| name | version | author | mail | keyword | description |
4+
| --- | --- | --- | --- | --- | --- |
5+
| [cellpose-planer](https://gitee.com/imagepy/cellpose-planer) | 0.1 | yxdragon | yxdragon@imagepy.org | cellpose,segment | generalist algorithm for cell and nucleus segmentation |
6+
| [Demo Plugin](https://github.com/Image-Py/demoplugin) | 0.1 | yxdragon | yxdragon@imagepy.org | demo,tutorial | This is a demo project to show How to write ImagePy plugin. Including the usage of all kinds of plugin, with document wrote in detail. Developers can take this project as example.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
catlog = ['Contribute Document', 'Contribute Plugin', '-', 'pmanager_wgt', 'Contributions']
1+
catlog = ['Contribute Document', 'Site Plugins List', 'update_plg', '-', 'pmanager_wgt', 'Contributions']

imagepy/menus/Plugins/Contribute/pmanager_wgt.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import wx, os, glob, shutil, random
88
from imagepy import root_dir
99
from sciwx.text import MDPad
10+
from sciapp.action import Macros
1011
#from imagepy.ui.mkdownwindow import HtmlPanel, md2html
1112

1213
class VirtualListCtrl(wx.ListCtrl):
@@ -36,15 +37,16 @@ def parse(path):
3637
f = open(path, encoding='utf-8')
3738
body = {'file':path}
3839
try:
39-
for i in range(13):
40+
line = f.readline()
41+
if line[0] == '#':body['name'] = line.split('#')[-1].strip()
42+
while line:
4043
line = f.readline()
41-
if line[0] == '#':body['name'] = line.split('#')[-1].strip()
42-
if 'Path:' in line: body['path'] = line.split('**')[-1].strip()
43-
if 'Version:' in line: body['version'] = line.split('**')[-1].strip()
44-
if 'Author:' in line: body['author'] = line.split('**')[-1].strip()
45-
if 'Email:' in line: body['email'] = line.split('**')[-1].strip()
46-
if 'Keyword:' in line: body['keyword'] = line.split('**')[-1].strip()
47-
if 'Description' in line: body['Description'] = line.split('**')[-1].strip()
44+
if line.startswith('**Path:'): body['path'] = line.split('**')[-1].strip()
45+
if line.startswith('**Version:'): body['version'] = line.split('**')[-1].strip()
46+
if line.startswith('**Author:'): body['author'] = line.split('**')[-1].strip()
47+
if line.startswith('**Email:'): body['email'] = line.split('**')[-1].strip()
48+
if line.startswith('**Keyword:'): body['keyword'] = line.split('**')[-1].strip()
49+
if line.startswith('**Description'): body['Description'] = line.split('**')[-1].strip()
4850
f.close()
4951
except: body = [0]
5052
finally: f.close()
@@ -67,6 +69,8 @@ def __init__( self, parent, app=None):
6769
self.txt_search = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString,
6870
wx.DefaultPosition, wx.DefaultSize, 0 )
6971
bSizer2.Add( self.txt_search, 1, wx.ALL, 5 )
72+
self.btn_update = wx.Button( self, wx.ID_ANY, 'Refresh List Online', wx.DefaultPosition, wx.DefaultSize, wx.BU_EXACTFIT )
73+
bSizer2.Add( self.btn_update, 0, wx.ALL, 5 )
7074

7175
bSizer3 = wx.BoxSizer( wx.HORIZONTAL )
7276
self.btn_install = wx.Button( self, wx.ID_ANY, 'Install/Update', wx.DefaultPosition, wx.DefaultSize, wx.BU_EXACTFIT )
@@ -95,6 +99,7 @@ def __init__( self, parent, app=None):
9599
# Connect Events
96100
self.txt_search.Bind( wx.EVT_TEXT, self.on_search)
97101
self.lst_plgs.Bind( wx.EVT_LIST_ITEM_SELECTED, self.on_run)
102+
self.btn_update.Bind(wx.EVT_BUTTON, self.on_update)
98103
self.btn_install.Bind(wx.EVT_BUTTON, self.on_install)
99104
self.btn_uninstall.Bind(wx.EVT_BUTTON, self.on_remove)
100105
self.chk_has.Bind( wx.EVT_CHECKBOX, self.on_check)
@@ -131,6 +136,9 @@ def on_search( self, event ):
131136
self.lst_plgs.set_data(self.buf)
132137
self.lst_plgs.Refresh()
133138

139+
def on_update(self, event):
140+
Macros('', ['Update Plugins List>None']).start(self.app, callafter=self.load)
141+
134142
def on_run(self, event):
135143
f = open(self.buf[event.GetIndex()][-1]['file'], encoding='utf-8')
136144
cont = f.read()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from sciapp.action import Free
2+
import sys, requests, re, os.path as osp
3+
from urllib.request import urlretrieve
4+
5+
class Plugin(Free):
6+
title = 'Update Plugins List'
7+
8+
def run(self, para = None):
9+
try:
10+
here = osp.abspath(osp.dirname(__file__))
11+
url = 'https://gitee.com/mirrors/imagepy/tree/master/imagepy/menus/Plugins/Contribute/Contributions'
12+
temp = re.compile('mirrors/imagepy/blob/master/imagepy/menus/Plugins/Contribute/Contributions/.*?md')
13+
14+
rst = requests.get(url).text
15+
records = ['https://gitee.com/'+i.replace('blob', 'raw') for i in temp.findall(rst)]
16+
for i in records: urlretrieve(i, osp.join(here, 'Contributions', osp.split(i)[-1].replace('%20',' ')))
17+
self.app.alert('site plugins list updated!')
18+
except Exception as e:
19+
self.app.alert('update failed!\tErrof:%s'%sys.exc_info()[1])

imagepy/menus/Plugins/Manager/plgtree_wgt.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from sciapp.action import Free
99
import wx,os
1010
from imagepy import root_dir
11-
from imagepy.app import loader, ConfigManager
11+
from imagepy.app import loader, ConfigManager, DocumentManager
1212
from wx.py.editor import EditorFrame
1313
from sciwx.text import MDPad
1414
from glob import glob
@@ -74,22 +74,21 @@ def addnode(self, parent, data):
7474
self.tre_plugins.SetItemData(item, i)
7575

7676
def load(self):
77-
datas = loader.build_plugins('menus')
77+
data = loader.build_plugins(root_dir+'/menus')
78+
extends = glob(root_dir+'/plugins/*/menus')
7879
keydata = {}
79-
for i in datas[1]:
80-
if isinstance(i, tuple): keydata[i[0].__name__.split('.')[-1]] = i[1]
81-
#print(keydata)
82-
extends = glob('plugins/*/menus')
80+
for i in data[1]:
81+
if isinstance(i, tuple): keydata[i[0].title] = i[1]
8382
for i in extends:
8483
plgs = loader.build_plugins(i)
84+
data[2].extend(plgs[2])
8585
for j in plgs[1]:
8686
if not isinstance(j, tuple): continue
87-
name = j[0].__name__.split('.')[-1]
88-
if name in keydata:
89-
keydata[name].extend(j[1])
90-
else: datas[1].append(j)
87+
name = j[0].title
88+
if name in keydata: keydata[name].extend(j[1])
89+
else: data[1].append(j)
9190
root = self.tre_plugins.AddRoot('Plugins')
92-
self.addnode(root, datas[1])
91+
self.addnode(root, data[1])
9392

9493
# Virtual event handlers, overide them in your derived class
9594
def on_run( self, event ):

0 commit comments

Comments
 (0)