Newer
Older
def parse_dirs(s):
filepaths = set(map(lambda x: x[2:], s.strip('\n').split('\n')[1:]))
dirs = set()
for path in filepaths:
lst = path.split('/')
dir_ = '/'.join(lst[:-1])
if dir_:
dirs.add(dir_)
return dirs, filepaths
def get_current_ui_type():
for child in dpg.get_item_children('ui', 1):
if dpg.get_value(child):
return dpg.get_item_alias(child)
def get_current_theme():
for child in dpg.get_item_children('theme', 1):
if dpg.get_value(child):
return dpg.get_item_alias(child)
def get_config_file_path():
return dpg.get_item_user_data('main')['config_file_path']
def get_config():
return dpg.get_item_user_data('main')['config']
def set_main_window_value(key, value):
data = dpg.get_item_user_data('main')
data[key] = value
dpg.set_item_user_data('main', data)
def get_main_window_value(key):
return dpg.get_item_user_data('main').get(key, None)
def get_height_map_file_path():
return dpg.get_item_user_data('map_window')['height_map_file_path']
def is_drawing():
return dpg.get_item_user_data('map_window')['drawing']
def get_prev_coords():
return dpg.get_item_user_data('map_window')['prev_coords']
def get_current_action():
return dpg.get_item_user_data('map_window')['current_action']
def set_map_window_value(key, value):
data = dpg.get_item_user_data('map_window')
data[key] = value
dpg.set_item_user_data('map_window', data)
def get_map_window_value(key):
return dpg.get_item_user_data('map_window').get(key, None)
def show_status_text(message):
dpg.set_item_pos('status_text', (dpg.get_item_width('main') - dpg.get_text_size(message)[0] - 2 * SPACE, dpg.get_item_pos('status_text')[1]))
dpg.set_value('status_text', message)
def get_emission_points():
points = dict()
config = get_config()
for key in config:
if 'point_emission' in key:
point_n = re.findall(r'tracer_([0-9]+)', key)[-1]
if point_n not in points:
points[point_n] = dict()
points[point_n][config[key].key] = config[key].value
return points
def get_max_n_emission_point():
config = get_config()
n = 0
for key in config:
if 'point_emission' in key:
n = max(int(re.findall(r'tracer_([0-9]+)', key)[-1]), n)
return n
def apply_tint_func(tint):
tint = np.array(tint[:-1]) / 255
def func(color):
color = np.array(color) / 255
color *= tint
return list(map(int, (color * 255)))
return func
def apply_tint(color, tint=(0, 119, 200)):
tint = np.array(tint) / 255
color = np.array(color) / 255
color *= tint
return list(map(int, (color * 255)))
def path_iter(path, prefix=""):
namespaces = path.split('.')
for i in range(len(namespaces)):
yield prefix + '.' + '.'.join(namespaces[:i+1])
def delete_item_and_clear_alias(item):
if dpg.does_item_exist(item):
dpg.delete_item(item)
if dpg.does_item_exist(item):
for child in dpg.get_item_children(item, 1):
delete_item_children_and_clear_aliases(child)
for child in dpg.get_item_children(item, 2):
delete_item_children_and_clear_aliases(child)
delete_item_and_clear_alias(item)
delete_item_children_and_clear_aliases(dpg.get_item_children('main', 1)[1])
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
####################################################################################
#
# search utils
#
####################################################################################
def change_color_temporarily(text_tag, color, duration=1):
color = list(color)[:-1] + [255]
dpg.configure_item(text_tag, color=color)
threading.Timer(duration, lambda: revert_color(text_tag)).start()
def revert_color(text_tag):
dpg.configure_item(text_tag, color=(255, 255, 255, 255))
####################################################################################
#
# main menu utils
#
####################################################################################
def combo_menu(callback):
def func(s, a, u):
for child in dpg.get_item_children(dpg.get_item_parent(s), 1):
if dpg.get_item_alias(child) != dpg.get_item_alias(s):
dpg.set_value(child, False)
else:
dpg.set_value(child, True)
dpg.set_item_user_data(s, dpg.get_item_alias(s))
callback(s, a, u)
return func
####################################################################################
#
# tabs ui utils
#
####################################################################################
def does_tab_bar_child_exist(item):
for uuid in dpg.get_item_children(item, 1):
if dpg.get_item_type(uuid) == "mvAppItemType::mvTabBar":
return True, uuid
return False, None
def get_absolute_y(item):
y = dpg.get_item_pos(item)[1]
parent = dpg.get_item_parent(item)
while parent:
if dpg.get_item_type(parent) == 'mvAppItemType::mvChildWindow':
y += dpg.get_item_pos(parent)[1]
parent = dpg.get_item_parent(parent)
return y
def get_item_level(item):
level = 0
parent = dpg.get_item_parent(item)
while parent:
if dpg.get_item_type(parent) == 'mvAppItemType::mvTabBar':
level += 1
parent = dpg.get_item_parent(parent)
return level
def change_height(item):
if not dpg.does_item_exist(item):
return
if dpg.get_item_type(item) == 'mvAppItemType::mvChildWindow':
uuid = dpg.get_item_parent(item)
new_height = dpg.get_viewport_client_height() - get_absolute_y(uuid) - SPACE * get_item_level(item)
dpg.set_item_height(item, max(new_height, dpg.get_item_user_data(item)))
for child in dpg.get_item_children(item, 1):
change_height(child)