Skip to content

Commit a4e2131

Browse files
committed
nothing
1 parent 8049eb5 commit a4e2131

34 files changed

+2450
-403
lines changed

demo/icons/open.png

8.04 KB
Loading

demo/labelapp/labelapp.py

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import sys; sys.path.append('../../')
2+
3+
import ttkbootstrap as ttk
4+
import scitk.ttk as sttk
5+
from scitk.widgets.toolbar import ToolBar
6+
from scitk.canvas import MCanvas as Canvas
7+
8+
class Classmanager(ttk.Frame):
9+
cmap = [
10+
"#a6cee3", "#1f78b4", "#b2df8a", "#33a02c",
11+
"#fb9a99", "#e31a1c", "#fdbf6f", "#ff7f00",
12+
"#cab2d6", "#6a3d9a", "#ffff99", "#b15928"
13+
]
14+
def __init__(self, parent, **key):
15+
super().__init__(parent, **key)
16+
self.toolbar = ttk.Frame(self)
17+
self.toolbar.pack(side='top', fill='x')
18+
btn_new = ttk.Button(self.toolbar, text='new', bootstyle='info-outline', padding=2)
19+
btn_new.pack(side='left', padx=3, pady=3)
20+
21+
btn_edit = ttk.Button(self.toolbar, text='edit', bootstyle='info-outline', padding=2)
22+
btn_edit.pack(side='left', padx=3, pady=3)
23+
24+
btn_del = ttk.Button(self.toolbar, text='del', bootstyle='info-outline', padding=2)
25+
btn_del.pack(side='left', padx=3, pady=3)
26+
27+
btn_clear = ttk.Button(self.toolbar, text='clear', bootstyle='info-outline', padding=2)
28+
btn_clear.pack(side='left', padx=3, pady=3)
29+
30+
btn_unsel = ttk.Button(self.toolbar, text='unsel', bootstyle='info-outline', padding=2)
31+
btn_unsel.pack(side='left', padx=3, pady=3)
32+
33+
cls_lst = self.cls_lst = sttk.Gridview(self, indexwidth=False, mode='row', selmode='single', stripe=True, edit=True)
34+
cls_lst.set([], columns=['Name'])
35+
cls_lst.set_column_width(0, 80, 1)
36+
cls_lst.pack(fill='both', expand=True)
37+
38+
btn_new.config(command=self.on_new)
39+
btn_clear.config(command=self.on_clear)
40+
btn_del.config(command=self.on_delete)
41+
btn_edit.config(command=self.on_edit)
42+
btn_unsel.config(command=self.on_unsel)
43+
self.classes = []
44+
45+
def on_new(self):
46+
self.classes.append('new class')
47+
self.set(self.classes)
48+
self.cls_lst.active(len(self.classes)-1, 0)
49+
50+
def on_clear(self): self.set([])
51+
52+
def on_unsel(self):
53+
self.cls_lst.select(None)
54+
self.set(self.classes)
55+
56+
def on_delete(self):
57+
if self.cls_lst.selection is None: return
58+
self.classes.pop(self.cls_lst.selection[0])
59+
self.set(self.classes)
60+
61+
def on_edit(self):
62+
if self.cls_lst.selection is None: return
63+
self.cls_lst.active(self.cls_lst.selection[0], 0)
64+
65+
def set(self, classes):
66+
self.classes = classes
67+
self.cls_lst.set([[i] for i in classes], columns=['Name'])
68+
for i in range(len(classes)):
69+
self.cls_lst.set_cell_color(i, 'x', self.cmap[i%12])
70+
71+
def default(self):
72+
i = self.cls_lst.selection
73+
if i is None: return
74+
return self.classes[i], self.cmap[i%12]
75+
76+
def get_classes(self):
77+
return [(c, self.cmap[i%12]) for (i,c) in enumerate(self.classes)]
78+
79+
classes = ['human', 'car', 'dog', 'cat', 'tree']
80+
81+
# from plugins import Gaussian
82+
83+
class MainFrame(ttk.Frame):
84+
def __init__(self, parent, **key):
85+
super().__init__(parent, **key)
86+
87+
toolbar = self.toolbar = ToolBar(self)
88+
toolbar.add_tools('IO', [('Open', None, print),
89+
('Open Folder', None, print),
90+
('Save', None, print)], True)
91+
92+
toolbar.add_tools('Browse', [('Next', None, print),
93+
('Prev', None, print),
94+
('Zoom', None, print),
95+
('Move', None, print),
96+
('Auto Fit', None, print)], True)
97+
98+
toolbar.add_tools('Edit', [('Rectangle', None, print),
99+
('Polygon', None, print),
100+
('Line', None, print),
101+
('Point', None, print),
102+
('Editor', None, print),
103+
('Clear', None, print)], True)
104+
105+
toolbar.add_tools('AI', [('Sam', None, print),
106+
('xxx', None, print)], True)
107+
108+
toolbar.pack(fill='x', side='top')
109+
110+
111+
self.status = ttk.Label(self)
112+
self.status.config(text='状态栏')
113+
self.status.pack(side='bottom', fill='x')
114+
ttk.Separator(self).pack(side='bottom', fill='x')
115+
116+
117+
self.fmanager = sttk.FileManager(self)
118+
self.fmanager.pack(side='left', fill='y')
119+
120+
self.canvas = Canvas(self)
121+
self.canvas.pack(side='left', fill='both', expand=True)
122+
123+
124+
rp = self.rpanel = sttk.Panedbook(self)
125+
panel = rp.add('Class Manager', weight=1)
126+
clsmanager = Classmanager(panel)
127+
clsmanager.pack(fill='both', expand=True, padx=1, pady=1)
128+
clsmanager.set(classes)
129+
130+
panel = rp.add('Label Manager', weight=1)
131+
lab_lst = sttk.Gridview(panel, indexwidth=False)
132+
lab_lst.set([], columns=['Name'])
133+
lab_lst.set_column_width(0, 80, 1)
134+
lab_lst.pack(fill='both', expand=True, padx=1, pady=1)
135+
136+
rp.config(width=200)
137+
rp.pack(side='right', fill='y')
138+
139+
self.fmanager.bind('<<File-Select>>', self.on_open)
140+
141+
def get_img(self): return self.canvas.image
142+
143+
# def alert(
144+
def info(self, info):
145+
print(info)
146+
147+
def on_open(self, path):
148+
from imageio import imread
149+
img = imread(path)
150+
self.canvas.set_img(img)
151+
152+
def info(self, info):
153+
self.status.config(text=info)
154+
155+
156+
if __name__ == '__main__':
157+
app = ttk.Window('标注工具')
158+
ttk.Style('darkly')
159+
frame = MainFrame(app)
160+
frame.pack(fill='both', expand=True)
161+
app.mainloop()

demo/labelapp/plugins.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys; sys.path.append('../')
2+
3+
from sciapp.action import Filter
4+
5+
class Gaussian(Filter):
6+
title = 'Gaussian'
7+
note = ['auto_snap', 'preview']
8+
para = {'sigma':2}
9+
view = [(float, 'sigma', (0, 30), 1, '标准差', '像素')]
10+
11+
def run(self, ips, img, snap, para):
12+
gaussian_filter(snap, para['sigma'], output=img)

demo/shpfile/shpapp.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import sys; sys.path.append('../../')
2+
3+
import ttkbootstrap as ttk
4+
import scitk.ttk as sttk
5+
6+
print(sttk.ColorBox)
7+
from scitk.widgets.toolbar import ToolBar
8+
from scitk.canvas import VCanvas as Canvas
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
12+
import geopandas as gpd
13+
14+
from sciapp.object import Layer
15+
from sciapp.util import json2shp
16+
17+
cmap = []
18+
for i in plt.colormaps()[::-1]:
19+
cm = plt.get_cmap(i)
20+
if i[-2:]=='_r': continue
21+
vs = np.linspace(0, cm.N, 256, endpoint=False)
22+
lut = cm(vs.astype(np.uint8), bytes=True)[:,:3]
23+
cmap.append((i, lut))
24+
25+
def shp2mark(df):
26+
feats = df.geometry.__geo_interface__['features']
27+
feats = [json2shp(i['geometry']) for i in feats]
28+
return Layer(feats, color=(255,0,0), lstyle='-o')
29+
30+
31+
class MainFrame(ttk.Frame):
32+
def __init__(self, parent, **key):
33+
super().__init__(parent, **key)
34+
35+
toolbar = self.toolbar = ToolBar(self)
36+
toolbar.add_tools('IO', [('Open', None, print),
37+
('Save', None, print)], True)
38+
39+
toolbar.add_tools('Browse', [('Move', None, print),
40+
('Auto Fit', None, print)], True)
41+
42+
toolbar.add_tools('Select', [('Rectangle', None, print),
43+
('Polygon', None, print),
44+
('Line', None, print),
45+
('Point', None, print),
46+
('Invert', None, print)], True)
47+
48+
toolbar.add_tools('LUT', [('Unique Value', None, print),
49+
('xxx', None, print)], True)
50+
51+
toolbar.pack(fill='x', side='top')
52+
53+
self.status = ttk.Label(self)
54+
self.status.config(text='状态栏')
55+
self.status.pack(side='bottom', fill='x')
56+
ttk.Separator(self).pack(side='bottom', fill='x')
57+
58+
panebook = ttk.PanedWindow(self, orient='horizontal')
59+
self.canvas = Canvas(panebook)
60+
# self.canvas.pack(side='left', fill='both', expand=True)
61+
62+
# linecolor, 属性映射,field, unique|max-min|std, cmap
63+
self.features = ttk.Frame(panebook)
64+
topframe = ttk.Frame(self.features)
65+
topframe.pack(side='top')
66+
ttk.Label(topframe, text='Pure Color', bootstyle='primary').pack(side='left')
67+
68+
self.box_color = sttk.ColorBox(topframe)
69+
self.box_color.pack(side='left', padx=3, pady=5)
70+
71+
ttk.Label(topframe, text=' Property Map', bootstyle='primary').pack(side='left')
72+
self.comb_field = ttk.Combobox(topframe, width=10, values=['Undefined', 'Province'])
73+
self.comb_field.pack(side='left', padx=3, pady=5)
74+
75+
self.comb_method = ttk.Combobox(topframe, width=10, values=['Max-Min', 'Mean-Std', 'Unique'])
76+
self.comb_method.pack(side='left', padx=3, pady=5)
77+
78+
self.box_cmap = sttk.ColorMapBox(topframe, cmap)
79+
self.box_cmap.pack(side='left', padx=3, pady=5)
80+
81+
self.table = table = sttk.Gridview(self.features, indexwidth=50)
82+
# table.set([], columns=['Name'])
83+
# table.set_column_width(0, 80, 1)
84+
table.pack(fill='both', expand=True, padx=1, pady=1)
85+
86+
panebook.add(self.canvas, weight=2)
87+
panebook.add(self.features, weight=0)
88+
panebook.pack(fill='both', expand=True)
89+
90+
'''
91+
rp = self.rpanel = sttk.Panedbook(self)
92+
93+
panel = rp.add('Feature Table', weight=1)
94+
lab_lst = sttk.Gridview(panel, indexwidth=False)
95+
lab_lst.set([], columns=['Name'])
96+
lab_lst.set_column_width(0, 80, 1)
97+
lab_lst.pack(fill='both', expand=True, padx=1, pady=1)
98+
99+
rp.config(width=200)
100+
rp.pack(side='right', fill='y')
101+
'''
102+
103+
def set_vector(self, shp):
104+
self.shp = shp
105+
shp = shp[[i for i in shp.columns if i!='geometry']]
106+
self.table.set(shp.values, columns=shp.columns, index=shp.index)
107+
108+
self.canvas.set_shp(shp2mark(self.shp))
109+
110+
def get_img(self): return self.canvas.image
111+
112+
# def alert(
113+
def info(self, info):
114+
print(info)
115+
116+
def on_open(self, path):
117+
from imageio import imread
118+
img = imread(path)
119+
self.canvas.set_img(img)
120+
121+
def info(self, info):
122+
self.status.config(text=info)
123+
124+
if __name__ == '__main__':
125+
126+
shp = gpd.read_file('lines.json', encoding='utf-8')
127+
128+
app = ttk.Window('标注工具')
129+
# ttk.Style('darkly')
130+
frame = MainFrame(app)
131+
frame.pack(fill='both', expand=True)
132+
frame.set_vector(shp)
133+
app.mainloop()
134+

sciapp/action/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
from .plugin.roi_tools import *
77
from .plugin.img_tools import *
88
from .plugin.mesh_tools import *
9-
from .advanced import Filter, Free, Simple, Table, Macros, Widget, dataio, Report
9+
from .advanced import Filter, Free, Simple, Table, Macros, Widget, dataio #, Report

sciapp/action/advanced/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
from .free import Free
55
from .macros import Macros
66
from .widget import Widget
7-
from .report import Report
7+
# from .report import Report

0 commit comments

Comments
 (0)