Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _show_image(self):
if self.current_image in self.images_info:
imgui.begin_group()
if imgui.button("X"):
self.images_info.pop(self.current_image)
self.current_image = ""
else:
image_info = self.images_info[self.current_image]
if image_info.additional_legend != "":
imgui.same_line()
imgui.text(image_info.additional_legend)
img = image_info.image
image_size = imgui.Vec2(img.shape[1], img.shape[0])
image_size = image_size_fit_in_gui(image_size, self._max_image_size(), can_make_bigger=True)
imgui_cv.image_explorer(img, title=self.current_image,
width=int(round(image_size.x)), height=int(round(image_size.y)),
image_adjustments=image_info.image_adjustments)
imgui.end_group()
try:
if data_type == 0:
data_value = DB.entities[data_value]
if constant:
DB.global_binds[data_attr] = data_value
else:
DB.add((DB.entities[data_entity], data_attr, data_value))
query_error = ""
data_entity = 0
data_attr = ""
data_type = 1
data_value = ""
imgui.close_current_popup()
except ValueError as e:
query_error = "Data Error: " + str(e)
imgui.same_line()
if imgui.button("Cancel"):
imgui.close_current_popup()
imgui.end_popup()
if imgui.small_button(imgui_ext.make_unique_label("Adjust")):
im.show_adjustments = True
# adjustments
if im.show_adjustments:
imgui.new_line()
imgui.text("Adjust:")
imgui.same_line()
imgui.push_item_width(80)
# noinspection PyArgumentList
changed, im.image_adjustments.factor = imgui.slider_float(
imgui_ext.make_unique_label("k"), im.image_adjustments.factor, 0., 32., format="%.3f", power=5.)
imgui.same_line()
imgui.push_item_width(80)
changed, im.image_adjustments.delta = imgui.slider_float(
imgui_ext.make_unique_label("delta"), im.image_adjustments.delta, 0., 255., format="%.3f", power=5.)
imgui.same_line()
if not im.image_adjustments.is_none():
if imgui.small_button(imgui_ext.make_unique_label("reset")):
im.image_adjustments = imgui_cv.ImageAdjustments()
imgui.same_line()
if imgui.small_button(imgui_ext.make_unique_label("hide adjust")):
im.show_adjustments = False
# Show image info
image_type_msg = str(im.image.dtype) + str(im.image.shape)
zoom = im.zoom_info.affine_transform[0, 0]
import math
if not _is_close(zoom, 1):
zoom_msg = "Zoom:{0:.2f} ".format(zoom)
else:
zoom_msg = ""
msg = zoom_msg + image_type_msg
imgui.text(msg)
def color_msg(color):
msg = ""
if isinstance(color, np.uint8):
msg = "{0}".format(color)
elif isinstance(color, np.float32):
msg = "{0:.3f}".format(color)
elif isinstance(color, np.float64):
msg = "{0:.3f}".format(color)
else:
if len(color) == 3:
bgr = color
imgui.color_button("", bgr[2] / 255., bgr[1] / 255., bgr[0] / 255.)
imgui.same_line()
msg = "RGB({0},{1},{2})".format(bgr[2], bgr[1], bgr[0])
elif len(color) == 4:
bgra = color
imgui.color_button("", bgra[2] / 255., bgra[1] / 255., bgra[0] / 255., bgra[3])
imgui.same_line()
msg = "RGBA({0},{1},{2},{3})".format(bgra[2], bgra[1], bgra[0], bgra[3])
return msg
)
if changed and " " in rule_args[i]:
rule_args[i] = rule_args[i].title().replace(" ", "")
arg_changed = changed or arg_changed
imgui.same_line()
imgui.pop_font()
if imgui.button("+##new" + name):
rule_args.append("NewArgument")
arg_changed = True
imgui.same_line()
if imgui.button("-##del" + name):
if len(rule_args) != 0:
del rule_args[-1]
arg_changed = True
imgui.same_line()
clicked, rule_lang = imgui.combo(
"##lang-" + name,
rule_lang,
["S-Expr", "NL"]
)
imgui.pop_item_width()
if rule_lang == 0:
imgui.push_font(monospaced_font)
changed, rule_text = imgui.input_text_multiline(
'##body-' + name,
rule_text,
2056,
500,
300,
)
# I want to use the space after the spacebar for clearing options
# So on the same line we create two buttons
imgui.same_line()
# Give a style to the button
imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_BGRAY)
# Create a button "CLEAR"
if imgui.button("CLEAR", width=80, height=50):
# Execute code when button is pressed
self.cli_history = []
self.input = ""
# push style
imgui.pop_style_color(1)
# Again same line
imgui.same_line()
# Give a style to the button
imgui.push_style_color(imgui.COLOR_BUTTON, *self.KEY_COLOR_BGRAY)
# Create a button "BACKSPACE"
if imgui.button("BACKSPACE", width=150, height=50):
# Execute code when button is pressed
self.input = self.input[:-1]
# push style
imgui.pop_style_color(1)
imgui.end_group()
for e in files:
if e.endswith(".py"):
imgui.push_style_color(imgui.COLOR_BUTTON, *PYFILE_COLOR)
else:
imgui.push_style_color(imgui.COLOR_BUTTON, *FILE_COLOR)
if imgui.button(e, width=200, height=60) and e.endswith(".py"):
run_python_module(e)
imgui.pop_style_color(1)
imgui.end_group()
# end of file picker
imgui.same_line(spacing=50)
imgui.begin_group()
imgui.text("Utils:")
imgui.push_style_color(imgui.COLOR_BUTTON, *APP_COLOR)
if imgui.button("Interactive Python", width=200, height=60):
t = Terminal()
t.main()
imgui.pop_style_color(1)
imgui.end_group()
imgui.end()
if ERROR:
imgui.set_next_window_size(width, height)