Skip to content

Commit 47b46b5

Browse files
authored
Add files via upload
1 parent 27fffb3 commit 47b46b5

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# -------- Activate virtual environment -------------------------
2+
import os
3+
import ctypes
4+
import sys
5+
from pathlib import Path
6+
7+
def search_activation_path():
8+
for i in range(5):
9+
final_path = str(Path(__file__).parents[i]) + '\\env\\Scripts\\activate_this.py'
10+
if os.path.exists(final_path):
11+
return final_path
12+
return ''
13+
14+
activate_path = search_activation_path()
15+
if os.path.exists(activate_path):
16+
exec(open(activate_path).read(), {'__file__': activate_path})
17+
print(f'Aivia virtual environment activated\nUsing python: {activate_path}')
18+
else:
19+
error_mess = f'Error: {activate_path} was not found.\n\nPlease check that:\n' \
20+
f' 1/ The \'FirstTimeSetup.py\' script was already run in Aivia,\n' \
21+
f' 2/ The current python recipe is in one of the "\\PythonEnvForAivia\\" subfolders.'
22+
ctypes.windll.user32.MessageBoxW(0, error_mess, 'Error', 0)
23+
sys.exit(error_mess)
24+
# ---------------------------------------------------------------
25+
26+
import tifffile
27+
import wx
28+
import textwrap
29+
import re
30+
31+
max_char_len = 150
32+
33+
34+
# [INPUT Name:inputImagePath Type:string DisplayName:'Any channel']
35+
# [OUTPUT Name:resultPath Type:string DisplayName:'Dummy to delete']
36+
def run(params):
37+
# Choose file
38+
file_path = pick_file('')
39+
40+
# Read the file
41+
raw_text = open(file_path, 'r+').read()
42+
43+
# Split description from processing steps
44+
main_parts = raw_text.split('"Entities":[')
45+
46+
# Split processing steps
47+
block_end_pattern = re.compile(r'},{\"[^(RecipeName|Name)]')
48+
step_blocks = re.split(block_end_pattern, main_parts[1])
49+
50+
# Prepare displayed table
51+
app = wx.App()
52+
frame = wx.Frame(parent=None, title='TIF tags', size=(1000, 1000))
53+
54+
table = wx.ListCtrl(frame, size=(-1, 100), style=wx.LC_REPORT)
55+
table.InsertColumn(0, 'Info', width=200)
56+
table.InsertColumn(1, 'Value', width=1600)
57+
58+
# Write first part
59+
r = 0
60+
table.InsertItem(r, 'Description')
61+
table.SetItem(r, 1, main_parts[0].replace(',', ',\n'))
62+
r += 1
63+
64+
# Split values in each block
65+
for i in range(len(step_blocks)):
66+
# Writing a line to separate blocks
67+
table.InsertItem(r, '----- Step ' + str(i) + ' ---')
68+
table.SetItem(r, 1, '---------------------------------')
69+
r += 1
70+
71+
lines = step_blocks[i].split(',')
72+
73+
for l in lines:
74+
split_line = l.split(':')
75+
76+
# Repair some broken text
77+
filtered_tag = split_line[0].replace('ackupPath"',
78+
'"BackupPath"').replace('ixelClassifierID"',
79+
'"PixelClassifierID"')
80+
81+
# Insert tag name
82+
table.InsertItem(r, filtered_tag)
83+
84+
# Set value because some can be very long
85+
final_val = str(split_line[1:])
86+
87+
# Removing some characters from value
88+
filtered_value = re.sub('[}\[\]\"\']', '', final_val)
89+
90+
# Insert value
91+
table.SetItem(r, 1, filtered_value)
92+
93+
r += 1
94+
95+
frame.Show()
96+
app.MainLoop()
97+
98+
99+
def wrap(string, length):
100+
return '\n'.join(textwrap.wrap(string, length))
101+
102+
103+
def pick_file(default_dir):
104+
print('Starting wxPython app')
105+
app = wx.App()
106+
107+
# Create open file dialog
108+
openFileDialog = wx.FileDialog(None, "Select a Aivia Workflow file",
109+
default_dir, "", "Workflow files (*.workflow)|*.workflow",
110+
wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
111+
112+
openFileDialog.ShowModal()
113+
filename = openFileDialog.GetPath()
114+
print("Selected file: ", filename)
115+
openFileDialog.Destroy()
116+
return filename
117+
118+
119+
if __name__ == '__main__':
120+
params = {}
121+
run(params)
122+
123+
# CHANGELOG
124+
# v1.00: - First version
125+
# v1.01: - New virtual env code for auto-activation

0 commit comments

Comments
 (0)