def menu_bar(self): if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_quit, selected_quit = imgui.menu_item( "Quit", 'Cmd+Q', False, True) if clicked_quit: self.cleanup() exit(0) imgui.end_menu() changed, value = imgui.input_text("", self.input_text, 30) if changed: imgui.set_next_window_position(imgui.get_item_rect_min().x, imgui.get_item_rect_max().y) imgui.set_next_window_size(imgui.get_item_rect_size().x, 0) if imgui.begin( "##popup", False, imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE): for index, row in self.symbol_list.iterrows(): if value.upper() in row[0]: _, _ = imgui.selectable(row[0] + " - " + row[2]) if imgui.is_item_clicked(): self.input_text = row[0] self.load_symbol(str(row[0]).lower()) imgui.end() imgui.end_main_menu_bar()
def render_callback(self, time: float, frametime: float): if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_quit, selected_quit = imgui.menu_item( "Quit", 'Cmd+Q', False, True ) if clicked_quit: exit(1) imgui.end_menu() changed, value = imgui.input_text("", self.input_text, 30) if changed: imgui.set_next_window_position(imgui.get_item_rect_min().x, imgui.get_item_rect_max().y) imgui.set_next_window_size(imgui.get_item_rect_size().x, 0) if imgui.begin("##popup", False, imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE): for index, row in symbol_list.iterrows(): if value.upper() in row[0]: opened, selected = imgui.selectable(row[0] + " - " + row[2]) if imgui.is_item_clicked(): input_text = row[0] selected_symbol = row[0] imgui.end() if imgui.button("download"): yfc.download(self.selected_symbol, symbol_data_file()) imgui.end_main_menu_bar() pass
def mouse_position_last_image(): io = imgui.get_io() mouse = io.mouse_pos rect_min = imgui.get_item_rect_min() mouse_relative = imgui.Vec2(mouse.x - rect_min.x, mouse.y - rect_min.y) if not _is_in_last_image(mouse_relative): return None else: return mouse_relative
def zoomtip(imtex, imdim, mag=1.0): if imgui.is_item_hovered(): w, h = imgui.get_window_size() h = imdim[0] * w / imdim[1] rectmin = imgui.get_item_rect_min() mousepos = imgui.get_mouse_pos() u = float(mousepos[0] - rectmin[0]) / w v = float(mousepos[1] - rectmin[1]) / h imgui.begin_tooltip() tw = 32. / imdim[1] / mag th = 32. / imdim[0] / mag imgui.image(imtex, 64, 64, uv0=(u - tw, v - th), uv1=(u + tw, v + th)) dl = imgui.get_window_draw_list() rm = imgui.get_item_rect_min() col = imgui.get_color_u32_rgba(1, 1, 0, 1) dl.add_line(rm[0], rm[1] + 32, rm[0] + 64, rm[1] + 32, col) dl.add_line(rm[0] + 32, rm[1], rm[0] + 32, rm[1] + 64, col) imgui.end()
def ProgessBar(CV, MV, BarSize = 200): if CV >= MV: CV = MV imgui.dummy(10, 20) draw_list = imgui.get_window_draw_list() sp = imgui.get_item_rect_min() ep = imgui.get_item_rect_max() draw_list.add_rect(sp[0]+60,ep[1], sp[0]+60 + BarSize ,sp[1], imgui.get_color_u32_rgba(0.098, 0.098, 0.439, 1)) draw_list.add_rect_filled(sp[0]+60,ep[1], sp[0]+60 + CV/MV * BarSize ,sp[1], imgui.get_color_u32_rgba(0.098, 0.098, 0.439, 1)) draw_list.add_text(sp[0]+60 + BarSize + 10, sp[1] + 2, imgui.get_color_u32_rgba(1,0.5,0.5,1), f'{round(CV/MV* 100, 2)} %')
def render(self, time: float, frametime: float): global selected_symbol global input_text self.candlestick_chart.render() imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_quit, selected_quit = imgui.menu_item( "Quit", 'Cmd+Q', False, True ) if clicked_quit: exit(1) imgui.end_menu() changed, value = imgui.input_text("", input_text, 30) if changed: imgui.set_next_window_position(imgui.get_item_rect_min().x, imgui.get_item_rect_max().y) imgui.set_next_window_size(imgui.get_item_rect_size().x, 0) if imgui.begin("##popup", False, imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE): for index, row in symbol_list.iterrows(): if value.upper() in row[0]: opened, selected = imgui.selectable(row[0] + " - " + row[2]) if imgui.is_item_clicked(): input_text = row[0] selected_symbol = row[0] imgui.end() if imgui.button("download"): yfc.download(selected_symbol, symbol_data_file()) imgui.end_main_menu_bar() if not imgui.get_io().want_capture_mouse: self.candlestick_chart.render_gui() # if len(df): # graphics.draw_table(df, 0) imgui.show_test_window() imgui.render() self.imgui.render(imgui.get_draw_data())
def get_item_rect() -> IMGui[Rect]: return Rect(im.get_item_rect_min(), im.get_item_rect_max())
def render_editor(self): if imgui.button("optimize track"): self.start_optimization() imgui.same_line() _, ks = imgui.slider_float2("kcurv, kdist", self.kcurv, self.kdist, min_value=0, max_value=100.0, power=2) self.kcurv, self.kdist = ks _, self.lanewidth = imgui.slider_float("lane width", self.lanewidth, min_value=10, max_value=1000, power=1.5) # use a child region just to keep appearing/disappearing widgets at the # top from shifting stuff around imgui.begin_child("region", 0, 25, border=False) if (self.editmode == 'turn' and self.selectedpt is not None and self.selectedpt < len(self.pts['turn'])): i = self.selectedpt T = self.pts['turn'] _, T[i][2] = imgui.slider_float("turn %d radius" % (i + 1), T[i][2], min_value=-1000., max_value=1000., power=1.2) if self.editmode == 'home': _, self.homeangle = imgui.slider_float("home position angle", self.homeangle, -3.141, 3.141) imgui.end_child() w, h = imgui.get_window_size() h = self.mapim.shape[0] * w / self.mapim.shape[1] imgui.image_button(self.maptex, w, h, frame_padding=0) rectmin = imgui.get_item_rect_min() if imgui.is_item_clicked(0): mxy = imgui.get_mouse_pos() u = (mxy[0] - rectmin[0]) * self.mapim.shape[1] / w v = (mxy[1] - rectmin[1]) * self.mapim.shape[1] / w if imgui.is_mouse_double_clicked(0): self.add_point(u, v) else: self.select_point(u, v) if (imgui.is_item_hovered() and self.selectedpt is not None and imgui.is_mouse_dragging(0)): mxy = imgui.get_mouse_pos() u = (mxy[0] - rectmin[0]) * self.mapim.shape[1] / w v = (mxy[1] - rectmin[1]) * self.mapim.shape[1] / w self.move_point(u, v) scale = w / self.mapim.shape[1] dl = imgui.get_window_draw_list() self.render_ptlist(dl, self.pts['cone'], rectmin, scale, imgui.get_color_u32_rgba(1, 0.7, 0, 1), 4, self.editmode == 'cone') self.render_ptlist(dl, self.pts['turn'], rectmin, scale, imgui.get_color_u32_rgba(0, 0.3, 1, 1), 3, self.editmode == 'turn') self.render_ptlist(dl, self.pts['home'], rectmin, scale, imgui.get_color_u32_rgba(1, 1, 1, 1), 10, self.editmode == 'home') # render home position angle if len(self.pts['home']) > 0: h = self.pts['home'][0] S = 100 * np.sin(self.homeangle) C = 100 * np.cos(self.homeangle) dl.add_line(rectmin[0] + h[0] * scale, rectmin[1] + h[1] * scale, rectmin[0] + h[0] * scale + C, rectmin[1] + h[1] * scale - S, imgui.get_color_u32_rgba(1, 1, 1, 1)) self.render_turns(scale, rectmin) self.render_opttrack(scale, rectmin) if self.editmode == "cone": zoomtip(self.maptex, self.mapim.shape, 2)