def __voltage_window(self): bimpy.set_next_window_pos(bimpy.Vec2(5, 278 + 128), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(345, 110), bimpy.Condition.Once) bimpy.begin("Voltage", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Voltage") bimpy.pop_font() bimpy.separator() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.text("") bimpy.same_line(25, 0) if self.data.voltage >= 0: bimpy.text("{:.2f}".format(self.data.voltage).rjust(6, "0")) else: bimpy.text("-" + "{:.2f}".format(self.data.voltage).rjust(5, "0")) bimpy.pop_font() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.same_line(220, 0) bimpy.text("Volt") bimpy.pop_font() bimpy.end()
def __current_window(self): bimpy.set_next_window_pos(bimpy.Vec2(5, 393 + 128), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(345, 110), bimpy.Condition.Once) bimpy.begin("Current", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Current") bimpy.pop_font() bimpy.separator() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.text("") bimpy.same_line(25, 0) bimpy.text("{:.2f}".format(self.data.voltage).rjust(6, "0")) bimpy.pop_font() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.same_line(215, 0) bimpy.text("Amp") bimpy.pop_font() bimpy.end()
def render(self): super(SaveGameFrame, self).render() if bimpy.begin(self.name, self.opened, flags=bimpy.WindowFlags.NoCollapse | bimpy.WindowFlags.MenuBar): if bimpy.begin_menu_bar(): bimpy.menu_item('Save', 'Cmd+S', self.click_states['save']) bimpy.menu_item('Reload', 'Cmd+R', self.click_states['reload']) bimpy.menu_item('Export', 'Cmd+E', self.click_states['export']) bimpy.menu_item('Reload & Diff', 'Cmd+D', self.click_states['reload_and_diff']) bimpy.end_menu_bar() if self.diff_string: bimpy.columns(2, "hex split") bimpy.text('Game: ') bimpy.same_line() bimpy.text(self.backend.game.value) for section_name, section_items in self.items.items(): if bimpy.collapsing_header(section_name): for item in section_items: item.render_widget() if self.diff_string: bimpy.next_column() for line in self.diff_string.splitlines(): bimpy.text(line) bimpy.end()
def __distance_window(self): bimpy.set_next_window_pos(bimpy.Vec2(5, 120 + 128), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(345, 110), bimpy.Condition.Once) bimpy.begin("Distance", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Distance Traveled") bimpy.pop_font() bimpy.separator() if self.data.distance <= 1.1: distance_formatted_data = str(int(self.data.distance * 1000)) distance_formatted_data = distance_formatted_data.rjust(4, "0") scalar = "m" else: distance_formatted_data = "{:.2f}".format(self.data.distance) distance_formatted_data = distance_formatted_data.rjust(6, "0") scalar = "Km" bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.text("") bimpy.same_line(38, -1) bimpy.text(distance_formatted_data) bimpy.same_line(245, 0) bimpy.text(scalar) bimpy.pop_font() bimpy.end()
def __calories_burtn_window(self): bimpy.set_next_window_pos(bimpy.Vec2(355, 5 + 128), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(345, 110), bimpy.Condition.Once) bimpy.begin("Calories Burnt", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Calories Burnt") bimpy.pop_font() bimpy.separator() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.text("") bimpy.same_line(25, 0) if self.data.calories_burned >= 0: bimpy.text("{:.2f}".format(self.data.calories_burned).rjust( 7, "0")) else: bimpy.text("0.00".rjust(7, "0")) bimpy.pop_font() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.same_line(250, 0) bimpy.text("cal") bimpy.pop_font() bimpy.end()
def __rpm_window(self): bimpy.set_next_window_pos(bimpy.Vec2(705, 278 + 128), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(305, 225), bimpy.Condition.Once) bimpy.begin("RPM", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "RPM") bimpy.pop_font() bimpy.separator() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.text("") bimpy.same_line(25, 0) bimpy.text(str(int(self.data.rpm)).rjust(4, "0")) bimpy.pop_font() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.same_line(175, 0) bimpy.text("RPM") bimpy.pop_font() self.rpm_datas.append(self.data.rpm) self.rpm_datas.pop(0) self.rpm_datas.reverse() bimpy.plot_lines("", self.rpm_datas, graph_size=bimpy.Vec2(288, 112)) self.rpm_datas.reverse() bimpy.end()
def __speed_window(self): bimpy.set_next_window_pos(bimpy.Vec2(355, 120 + 128), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(345, 110), bimpy.Condition.Once) bimpy.begin("Speed", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Speed") bimpy.pop_font() bimpy.separator() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.text("") bimpy.same_line(25, 0) bimpy.text(str(int(self.data.speed[0])).rjust(4, " ")) bimpy.pop_font() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.same_line(200, 0) bimpy.text("Km/H") bimpy.pop_font() bimpy.end()
def run(self): ctx = bimpy.Context() ctx.init(600, 600, "Neural Network") while (not ctx.should_close()): with ctx: bimpy.begin("Control Center") self.sub.show(ctx) bimpy.end()
def main(): global CTX ctx = bimpy.Context() ctx.init(1200, 1200, "Image") with ctx: bimpy.themes.set_light_theme() socket_thread = threading.Thread(target = thread_socket_func, args = (8883, )) socket_thread.start() message_thread = threading.Thread(target = message_thread_func) message_thread.start() previous_n_points = 0 clear_flag = False while not ctx.should_close(): with ctx: bimpy.set_next_window_pos(bimpy.Vec2(120, 120), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(400, 400), bimpy.Condition.Once) bimpy.begin("Window #1") bimpy.text("This is text!") if bimpy.button("Send A Lot Of Messages"): temp_messages = [make_message_text("log", "Message #" + str(i)) for i in range(560)] send_messages(CTX.message_pipeline, temp_messages) if bimpy.button("Send A Lot Of Random Points"): temp_messages = [make_message_point("point", (random.randrange(400 + i), random.randrange(400 + i))) for i in range(20)] send_messages(CTX.message_pipeline, temp_messages) if bimpy.button("Clear Flag"): clear_flag = not clear_flag bimpy.text("Text from events:\n%s" % (CTX.data.text)) bimpy.end() draw_window_drawing(ctx, 400, 400, "Sample Drawing", CTX.data.points) log("Exited rendering thread") log("Sending exit to message_thread") send_message_text(CTX.message_pipeline, "exit", "") log("Waiting for message_thread") message_thread.join() CTX.server_socket_running = False if CTX.server_socket: for c, info in CTX.server_socket.connections: c.send(b'exit') log("Waiting for socket_thread") socket_thread.join() log("Bye")
def view_batch(bp): bimpy.begin("Batch") bimpy.button("Open files...") bimpy.button("Open configurations...") bimpy.separator() bimpy.text("Regions:") bimpy.separator() bimpy.button("Render Files") bimpy.end()
def __separator_name_window(self): bimpy.set_next_window_pos(bimpy.Vec2(5, 90), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(1005, 38), bimpy.Condition.Once) bimpy.begin("Separator Name", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.separator() bimpy.text("") bimpy.separator() bimpy.end()
def visualize(self): bimpy.begin(type(self).__name__ + " - " + str(id(self)), bimpy.Bool(True)) bimpy.input_text("Text", self.__state["text"], 256) button_pressed = bimpy.button("Plot", bimpy.Vec2(40, 20)) if button_pressed or self.__state["toggle"]: if button_pressed: self.__state["toggle"] ^= True if len(self.__state["text"].value) > 0: bimpy.plot_lines("Graph", self.encode(self.__state["text"].value.encode())) bimpy.end()
def __heart_rate_window(self): bimpy.set_next_window_pos(bimpy.Vec2(705, 5 + 128), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(305, 225), bimpy.Condition.Once) bimpy.begin("Heart Rate", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Heart Rate") bimpy.pop_font() bimpy.separator() bimpy.text("") bimpy.same_line(30, -1) bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.text(str(int(self.data.heart_rate)).rjust(3, "0")) bimpy.pop_font() bimpy.same_line(140, 20) bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.text("BPM") bimpy.pop_font() if (time.time() - self.heart_rate_start_monitor) >= (self.data.heart_rate / 60): self.heart_rate_data.append(-0.7) self.heart_rate_data.append(1) self.heart_rate_start_monitor = time.time() self.heart_rate_data.pop(0) else: self.heart_rate_data.append(0) self.heart_rate_data.pop(0) self.heart_rate_data.reverse() bimpy.plot_lines("", self.heart_rate_data, graph_size=bimpy.Vec2(288, 112), scale_min=-1.0, scale_max=1.3) self.heart_rate_data.reverse() bimpy.end()
def main(): selected_compiler = bimpy.Int() ctx = bimpy.Context() ctx.init(WIDTH, HEIGHT, "Virtual enviroment manager") environments = getAvailableEnviroments() compilers_list = list(data.compilers.keys()) show_new_env_menu = False while (not ctx.should_close()): with ctx: bimpy.set_next_window_pos(bimpy.Vec2(0, 0), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(WIDTH, HEIGHT), bimpy.Condition.Once) bimpy.begin("Enviroments",bimpy.Bool(True), \ bimpy.WindowFlags.NoCollapse and bimpy.WindowFlags.NoResize) bimpy.text(sys.version) bimpy.columns(2) for enviroment in environments: if bimpy.button(enviroment): compiler = list(data.compilers.values())[ selected_compiler. value] if selected_compiler.value != 0 else "" subprocess.call( ['start', environments[enviroment], compiler], shell=True) bimpy.next_column() if bimpy.button("O##" + enviroment): subprocess.Popen(r'explorer /select,' + os.path.dirname(environments[enviroment])) #os.startfile(os.path.realpath(os.path.dirname(environments[enviroment]))) bimpy.next_column() bimpy.columns(1) if bimpy.combo("Compiler", selected_compiler, compilers_list): pass # if bimpy.button("Add new enviroment"): # new_env_ctx = BimpyContext(WIDTH, HEIGHT, "New enviroment menu") # while(not new_env_ctx.ctx.should_close()): # with new_env_ctx.ctx: # bimpy.begin("dsad") # bimpy.text("d") # bimpy.end() # if bimpy.button("Create new enviroment"): bimpy.end()
def on_update(self): y = 30 self.text('Window size: %dx%d' % (self.width, self.height), 10, y) y += 30 self.text('World size: %dx%d' % (self.world_width, self.world_height), 10, y) y += 30 self.text('Scale %f' % self.scale, 10, y) y += 30 self.text('%f x %f' % self.cursor_pos_world, 10, y) y += 30 self.point(*self.cursor_pos_world, (230, 10, 10, 240), radius=2.) plt = vec2(-0.035, -0.045) pmt = vec2(0.56, 0.31) prt = vec2(0.862, 0.0421) plm = vec2(0.039, -0.3) prm = vec2(0.87, -0.088) plb = vec2(0.31, -0.35) pmb = vec2(0.55, -0.35) prb = vec2(0.84, -0.25) self._ctx.nvgBeginPath() self._ctx.nvgScale(vec2(1000.)) self._ctx.nvgTranslate(vec2(1.)) self._ctx.nvgScale(vec2(1., -1.)) self._ctx.nvgMoveTo(plt) self._ctx.nvgQuadTo(plm, plb) self._ctx.nvgQuadTo(pmb, prb) self._ctx.nvgQuadTo(prm, prt) self._ctx.nvgQuadTo(pmt, plt) self._ctx.nvgClosePath() self._ctx.nvgFillColor(vec4(0.73, 0.78, 0.83, 1.)) self._ctx.nvgFill() bimpy.begin('Editor') bimpy.columns(2) bimpy.begin_child('Scene', bimpy.Vec2(0, 300)) self.scene_tree() bimpy.end_child() bimpy.next_column() self.object_inspector() self.draw() bimpy.end()
def render(self, config_server): if self.ctx.should_close(): return 0 self.ctx.new_frame() bimpy.set_next_window_pos(bimpy.Vec2(0, 0), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(self.width, self.height), bimpy.Condition.Once) bimpy.begin("", flags=bimpy.WindowFlags.NoResize | bimpy.WindowFlags.NoTitleBar | bimpy.WindowFlags.NoMove) self.draw_gui(config_server) bimpy.end() self.ctx.render() return 1
def __age_window(self): bimpy.set_next_window_pos(bimpy.Vec2(900, 5), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(110, 80), bimpy.Condition.Once) bimpy.begin("Age", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Age") bimpy.pop_font() bimpy.separator() bimpy.push_font(self.fonts.fonts[16]["ext_bold_ital"]) bimpy.text("") bimpy.same_line(38, 0) bimpy.text(str(self.data.age)) bimpy.pop_font() bimpy.end()
def __gender_window(self): bimpy.set_next_window_pos(bimpy.Vec2(729, 5), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(166, 80), bimpy.Condition.Once) bimpy.begin("Gender", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Gender") bimpy.pop_font() bimpy.separator() bimpy.push_font(self.fonts.fonts[16]["ext_bold_ital"]) bimpy.text("") bimpy.same_line(38, 0) bimpy.text("Female" if self.data.gender else "Male") bimpy.pop_font() bimpy.end()
def draw_window_drawing(ctx, w, h, name, points): bimpy.set_next_window_pos(bimpy.Vec2(w + 20, h + 20), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(w, h), bimpy.Condition.Once) bimpy.begin(name) window_zero = bimpy.get_window_pos() + bimpy.Vec2(100 + temp_separation_test.value, 100 + temp_separation_test.value) window_one = bimpy.get_window_pos() + bimpy.Vec2(w - 100 - temp_separation_test.value, h - 100 - temp_separation_test.value) bimpy.add_circle_filled(window_zero, 5.0, 0xFF000000 + 0xc88200, 100) bimpy.add_circle_filled(window_one, 5.0, 0xFF000000 + 0x4bb43c, 100) for x,y in points: point = bimpy.get_window_pos() + bimpy.Vec2(x, y) bimpy.add_circle_filled(point, 5.0, 0xFF000000 + 0x4bb43c, 100) bimpy.slider_float("separation", temp_separation_test, 0.0, 100.0) bimpy.end()
def __time_window(self): bimpy.set_next_window_pos(bimpy.Vec2(5, 5 + 128), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(345, 110), bimpy.Condition.Once) bimpy.begin("Time Elapsed", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Time Elapsed") bimpy.pop_font() bimpy.separator() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.text("") bimpy.same_line(38, 0) bimpy.text( str(datetime.timedelta(seconds=self.data.exercize_time))[:-4]) bimpy.pop_font() bimpy.end()
def render(self): # display_size = bimpy.get_display_size() window_pos = bimpy.Vec2(self._distance, self._distance) window_pos_pivot = bimpy.Vec2(0.0, 0.0) bimpy.set_next_window_pos(window_pos, bimpy.Condition.FirstUseEver, window_pos_pivot) bimpy.set_next_window_bg_alpha(0.35) flags = bimpy.WindowFlags.NoDecoration \ | bimpy.WindowFlags.AlwaysAutoResize \ | bimpy.WindowFlags.NoSavedSettings \ | bimpy.WindowFlags.NoFocusOnAppearing \ | bimpy.WindowFlags.NoFocusOnAppearing \ | bimpy.WindowFlags.NoNav if bimpy.begin("logging overlay##logging_tools", flags=flags): if bimpy.is_mouse_pos_valid(None): mouse_pos = bimpy.get_mouse_pos() bimpy.text("Mouse Pos: ({:.1f},{:.1f})".format(mouse_pos.x, mouse_pos.y)) else: bimpy.text("Mouse Pos: <invalid>") bimpy.end()
def __power_window(self): bimpy.set_next_window_pos(bimpy.Vec2(355, 278 + 128), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(345, 225), bimpy.Condition.Once) bimpy.begin("Power", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Power") bimpy.pop_font() bimpy.separator() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.text("") bimpy.same_line(25, 0) bimpy.text("{:.2f}".format(self.data.power).rjust(6, "0")) bimpy.pop_font() bimpy.push_font(self.fonts.fonts[44]["ext_bold_ital"]) bimpy.same_line(212, 0) bimpy.text("Watts") bimpy.pop_font() self.power_datas.append(self.data.power) self.power_datas.pop(0) self.power_datas.reverse() bimpy.plot_lines("", self.power_datas, graph_size=bimpy.Vec2(329, 112), scale_min=-1.0, scale_max=500.0) self.power_datas.reverse() bimpy.end()
def run(self): """Runs the application. .. note:: This is a blocking call. It won't return until the window is closed Runs an event loop, where it process user input and updates window. Call callback method :meth:`on_update`. Example: >>> app = App() >>> app.run() """ while not self._ctx.should_close(): with self._ctx: for k, v in self.keys.items(): self.keys[k] += 1 if v > 50: self.on_keyboard(k, True, 0) self.keys[k] = 45 bimpy.begin_root() self.on_update() bimpy.end()
def render(self): if not self._size: self._size = bimpy.Vec2(400, 600) bimpy.set_next_window_size(self._size) if bimpy.begin(self.name, self.opened, flags=bimpy.WindowFlags.NoCollapse | bimpy.WindowFlags.MenuBar): if bimpy.begin_menu_bar(): bimpy.menu_item('Reload', 'Cmd+R', self.click_states['reload']) bimpy.end_menu_bar() for folder_name, folder_files in self.tree.items(): if bimpy.collapsing_header(folder_name): for item, button_name in folder_files: if bimpy.button(button_name): item_path = '{0}/{1}'.format(folder_name, item) try: new_savegame = SaveGameFrame( PS2WrappedBinBackend, item_path, self) self.child_frames.append(new_savegame) except KeyboardInterrupt as e: raise e except Exception as e: print(e) bimpy.same_line() bimpy.text(item) bimpy.end() for child_frame in self.child_frames: child_frame.render()
syphonpy.convert_to_texture(img.texture_name(), _converted, int(img.texture_size().width), int(img.texture_size().height)) # glBindTexture(GL_TEXTURE_2D, 0) # glBindTexture(GL_TEXTURE_RECTANGLE, img.texture_name) bimpy.image( _converted, bimpy.Vec2(img.texture_size().width, img.texture_size().height)) # glBindTexture(GL_TEXTURE_RECTANGLE, 0) # glBindFramebuffer(GL_FRAMEBUFFER, 0); bimpy.text("ok") # except Exception as e: # bimpy.text(str(e)) # pass bimpy.text(str(img.texture_name())) bimpy.text(str(_converted)) bimpy.text("[{}x{}]".format(img.texture_size().width, img.texture_size().height)) # bimpy.text(str(client.context())) img = None bimpy.end() ctx.render()
import sys import os if os.path.exists("../cmake-build-debug/"): print('Running Debugging session!') sys.path.insert(0, "../cmake-build-debug/") import bimpy as bp ctx = bp.Context() ctx.init(600, 600, "Hello") str = bp.String() f = bp.Float() while not ctx.should_close(): with ctx: bp.begin_root("") bp.text("Hello, world!") if bp.button("OK"): print(str.value) bp.input_text('string', str, 256) bp.slider_float("float", f, 0.0, 1.0) bp.end()
def render(self, ctx, windows_info): # calculate autoly pos = bimpy.Vec2( windows_info['file_brewswer_ui']['x'] + windows_info['file_brewswer_ui']['w'] + conf.margin, windows_info['image_shower_ui']['y'] + windows_info['image_shower_ui']['h'] + conf.margin) size = bimpy.Vec2(ctx.width() - pos.x - conf.margin, conf.meta_info_height) bimpy.set_next_window_pos(pos, bimpy.Condition.Always) bimpy.set_next_window_size(size, bimpy.Condition.Always) bimpy.begin( "", bimpy.Bool(True), bimpy.WindowFlags.NoCollapse | bimpy.WindowFlags.NoMove | bimpy.WindowFlags.NoResize | bimpy.WindowFlags.NoTitleBar | bimpy.WindowFlags.NoScrollbar) ###########UI########### if self.meta_info is not None: ####LINE1#### self.meta_info.setdefault('ImageWidth', '') self.meta_info.setdefault('ImageLength', '') bimpy.text('{}:{}x{}'.format(LANG.meta_size, self.meta_info['ImageWidth'], self.meta_info['ImageLength'])) bimpy.same_line(size.x / 3) self.meta_info.setdefault('DateTimeOriginal', '') bimpy.text('{}:{}'.format(LANG.meta_date, self.meta_info['DateTimeOriginal'])) bimpy.same_line(size.x / 3 * 2) self.meta_info.setdefault('Make', '') self.meta_info.setdefault('Model', '') bimpy.text('{}:{} {}'.format(LANG.meta_device, self.meta_info['Make'], self.meta_info['Model'])) ####LINE2#### self.meta_info.setdefault('FocalLength', '') bimpy.text('{}:{}'.format(LANG.meta_focal_length, self.meta_info['FocalLength'])) bimpy.same_line(size.x / 3) self.meta_info.setdefault('ExposureTime', '') # truncate too high number try: x, y = self.meta_info['ExposureTime'] self.meta_info['ExposureTime'] = (x % 1000, y % 1000) except: pass bimpy.text('{}:{}'.format(LANG.meta_exposure_time, self.meta_info['ExposureTime'])) bimpy.same_line(size.x / 3 * 2) self.meta_info.setdefault('ISOSpeedRatings', '') bimpy.text('{}:{}'.format(LANG.meta_ISO_speed_ratings, self.meta_info['ISOSpeedRatings'])) ####LINE3#### bimpy.text('{}:({},{})'.format(LANG.meta_GPS, round(self.lat, 1), round(self.lon, 1))) bimpy.same_line(size.x / 3) bimpy.text('{}:{}'.format(LANG.meta_location, self.location)) ######################## t = { 'x': bimpy.get_window_pos().x, 'y': bimpy.get_window_pos().y, 'w': bimpy.get_window_size().x, 'h': bimpy.get_window_size().y, 'self': self, } bimpy.end() return t
def show_demo_window(): bp.begin_root(menu=True) # Menu Bar if bp.begin_menu_bar(): if bp.begin_menu("Menu"): bp.end_menu() if bp.begin_menu("Examples"): bp.end_menu() if bp.begin_menu("Tools"): bp.end_menu() bp.end_menu_bar() global clicked if bp.button("Button"): clicked += 1 if clicked & 1: bp.same_line() bp.text("Thanks for clicking me!") bp.checkbox("checkbox", check) bp.radio_button("radio a", e, 0) bp.same_line() bp.radio_button("radio b", e, 1) bp.same_line() bp.radio_button("radio c", e, 2) # Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style. for i in range(7): if i > 0: bp.same_line() bp.push_id_int(i) bp.push_style_color(bp.Colors.Button, bp.Vec4(i / 7.0, 0.6, 0.6, 1.0)) bp.push_style_color(bp.Colors.ButtonHovered, bp.Vec4(i / 7.0, 0.7, 0.7, 1.0)) bp.push_style_color(bp.Colors.ButtonActive, bp.Vec4(i / 7.0, 0.8, 0.8, 1.0)) bp.button("Click") bp.pop_style_color(3) bp.pop_id() # Use AlignTextToFramePadding() to align text baseline to the baseline of framed elements (otherwise a Text+SameLine+Button sequence will have the text a little too high by default) bp.align_text_to_frame_padding() bp.text("Hold to repeat:") bp.same_line() # Arrow buttons with Repeater spacing = bp.get_style().item_inner_spacing.x bp.push_button_repeat(True) global counter if bp.arrow_button("##left", bp.Direction.Left): counter -= 1 bp.same_line(0.0, spacing) if bp.arrow_button("##right", bp.Direction.Right): counter += 1 bp.pop_button_repeat() bp.same_line() bp.text("%d" % counter) bp.text("Hover over me") if bp.is_item_hovered(): bp.set_tooltip("I am a tooltip") bp.same_line() bp.text("- or me") if bp.is_item_hovered(): bp.begin_tooltip() bp.text("I am a fancy tooltip") arr = [0.6, 0.1, 1.0, 0.5, 0.92, 0.1, 0.2] bp.plot_lines("Curve", arr) bp.end_tooltip() bp.separator() bp.label_text("label", "Value") # Using the _simplified_ one-liner Combo() api here # See "Combo" section for examples of how to use the more complete BeginCombo()/EndCombo() api. items = [ "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO" ] bp.combo("combo", item_current, items) bp.same_line() help_marker( "Refer to the \"Combo\" section below for an explanation of the full BeginCombo/EndCombo API, and demonstration of various flags.\n" ) # To wire InputText() with std::string or any other custom string type, # see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file. bp.input_text("input text", str0, 128) bp.same_line() help_marker( "USER:\nHold SHIFT or use mouse to select text.\n" "CTRL+Left/Right to word jump.\n" "CTRL+A or double-click to select all.\n" "CTRL+X,CTRL+C,CTRL+V clipboard.\n" "CTRL+Z,CTRL+Y undo/redo.\n" "ESCAPE to revert.\n\nPROGRAMMER:\nYou can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputText() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example (this is not demonstrated in imgui_demo.cpp)." ) bp.end()
def sample(cfg, logger): torch.cuda.set_device(0) model = Model(startf=cfg.MODEL.START_CHANNEL_COUNT, layer_count=cfg.MODEL.LAYER_COUNT, maxf=cfg.MODEL.MAX_CHANNEL_COUNT, latent_size=cfg.MODEL.LATENT_SPACE_SIZE, truncation_psi=cfg.MODEL.TRUNCATIOM_PSI, truncation_cutoff=cfg.MODEL.TRUNCATIOM_CUTOFF, mapping_layers=cfg.MODEL.MAPPING_LAYERS, channels=cfg.MODEL.CHANNELS, generator=cfg.MODEL.GENERATOR, encoder=cfg.MODEL.ENCODER) model.cuda(0) model.eval() model.requires_grad_(False) decoder = model.decoder encoder = model.encoder mapping_tl = model.mapping_d mapping_fl = model.mapping_f dlatent_avg = model.dlatent_avg logger.info("Trainable parameters generator:") count_parameters(decoder) logger.info("Trainable parameters discriminator:") count_parameters(encoder) arguments = dict() arguments["iteration"] = 0 model_dict = { 'discriminator_s': encoder, 'generator_s': decoder, 'mapping_tl_s': mapping_tl, 'mapping_fl_s': mapping_fl, 'dlatent_avg': dlatent_avg } checkpointer = Checkpointer(cfg, model_dict, {}, logger=logger, save=False) extra_checkpoint_data = checkpointer.load() model.eval() layer_count = cfg.MODEL.LAYER_COUNT def encode(x): Z, _ = model.encode(x, layer_count - 1, 1) Z = Z.repeat(1, model.mapping_f.num_layers, 1) return Z def decode(x): layer_idx = torch.arange(2 * layer_count)[np.newaxis, :, np.newaxis] ones = torch.ones(layer_idx.shape, dtype=torch.float32) coefs = torch.where(layer_idx < model.truncation_cutoff, ones, ones) # x = torch.lerp(model.dlatent_avg.buff.data, x, coefs) return model.decoder(x, layer_count - 1, 1, noise=True) path = 'dataset_samples/faces/realign1024x1024' paths = list(os.listdir(path)) paths.sort() paths_backup = paths[:] randomize = bimpy.Bool(True) current_file = bimpy.String("") ctx = bimpy.Context() attribute_values = [bimpy.Float(0) for i in indices] W = [ torch.tensor(np.load("principal_directions/direction_%d.npy" % i), dtype=torch.float32) for i in indices ] rnd = np.random.RandomState(5) def loadNext(): img = np.asarray(Image.open(path + '/' + paths[0])) current_file.value = paths[0] paths.pop(0) if len(paths) == 0: paths.extend(paths_backup) if img.shape[2] == 4: img = img[:, :, :3] im = img.transpose((2, 0, 1)) x = torch.tensor(np.asarray(im, dtype=np.float32), device='cpu', requires_grad=True).cuda() / 127.5 - 1. if x.shape[0] == 4: x = x[:3] needed_resolution = model.decoder.layer_to_resolution[-1] while x.shape[2] > needed_resolution: x = F.avg_pool2d(x, 2, 2) if x.shape[2] != needed_resolution: x = F.adaptive_avg_pool2d(x, (needed_resolution, needed_resolution)) img_src = ((x * 0.5 + 0.5) * 255).type(torch.long).clamp( 0, 255).cpu().type(torch.uint8).transpose(0, 2).transpose(0, 1).numpy() latents_original = encode(x[None, ...].cuda()) latents = latents_original[0, 0].clone() latents -= model.dlatent_avg.buff.data[0] for v, w in zip(attribute_values, W): v.value = (latents * w).sum() for v, w in zip(attribute_values, W): latents = latents - v.value * w return latents, latents_original, img_src def loadRandom(): latents = rnd.randn(1, cfg.MODEL.LATENT_SPACE_SIZE) lat = torch.tensor(latents).float().cuda() dlat = mapping_fl(lat) layer_idx = torch.arange(2 * layer_count)[np.newaxis, :, np.newaxis] ones = torch.ones(layer_idx.shape, dtype=torch.float32) coefs = torch.where(layer_idx < model.truncation_cutoff, ones, ones) dlat = torch.lerp(model.dlatent_avg.buff.data, dlat, coefs) x = decode(dlat)[0] img_src = ((x * 0.5 + 0.5) * 255).type(torch.long).clamp( 0, 255).cpu().type(torch.uint8).transpose(0, 2).transpose(0, 1).numpy() latents_original = dlat latents = latents_original[0, 0].clone() latents -= model.dlatent_avg.buff.data[0] for v, w in zip(attribute_values, W): v.value = (latents * w).sum() for v, w in zip(attribute_values, W): latents = latents - v.value * w return latents, latents_original, img_src latents, latents_original, img_src = loadNext() ctx.init(1800, 1600, "Styles") def update_image(w, latents_original): with torch.no_grad(): w = w + model.dlatent_avg.buff.data[0] w = w[None, None, ...].repeat(1, model.mapping_f.num_layers, 1) layer_idx = torch.arange(model.mapping_f.num_layers)[np.newaxis, :, np.newaxis] cur_layers = (7 + 1) * 2 mixing_cutoff = cur_layers styles = torch.where(layer_idx < mixing_cutoff, w, latents_original) x_rec = decode(styles) resultsample = ((x_rec * 0.5 + 0.5) * 255).type(torch.long).clamp( 0, 255) resultsample = resultsample.cpu()[0, :, :, :] return resultsample.type(torch.uint8).transpose(0, 2).transpose(0, 1) im_size = 2**(cfg.MODEL.LAYER_COUNT + 1) im = update_image(latents, latents_original) print(im.shape) im = bimpy.Image(im) display_original = True seed = 0 while not ctx.should_close(): with ctx: new_latents = latents + sum( [v.value * w for v, w in zip(attribute_values, W)]) if display_original: im = bimpy.Image(img_src) else: im = bimpy.Image(update_image(new_latents, latents_original)) bimpy.begin("Principal directions") bimpy.columns(2) bimpy.set_column_width(0, im_size + 20) bimpy.image(im) bimpy.next_column() for v, label in zip(attribute_values, labels): bimpy.slider_float(label, v, -40.0, 40.0) bimpy.checkbox("Randomize noise", randomize) if randomize.value: seed += 1 torch.manual_seed(seed) if bimpy.button('Next'): latents, latents_original, img_src = loadNext() display_original = True if bimpy.button('Display Reconstruction'): display_original = False if bimpy.button('Generate random'): latents, latents_original, img_src = loadRandom() display_original = False if bimpy.input_text( "Current file", current_file, 64) and os.path.exists(path + '/' + current_file.value): paths.insert(0, current_file.value) latents, latents_original, img_src = loadNext() bimpy.end()
def render(self, ctx, windows_info): pos = bimpy.Vec2(conf.margin, conf.margin) size_min = bimpy.Vec2(conf.min_file_browser_width, ctx.height() - 2 * conf.margin) size_max = bimpy.Vec2(conf.max_file_browser_width, ctx.height() - 2 * conf.margin) bimpy.set_next_window_pos(pos, bimpy.Condition.Once) bimpy.set_next_window_size_constraints(size_min, size_max) bimpy.begin(LANG.file_brewswer_ui_title, bimpy.Bool(True), bimpy.WindowFlags.NoCollapse | bimpy.WindowFlags.NoMove) ###########UI########### if bimpy.button(LANG.file_brewswer_ui_refresh) == True: self.fb.refresh_file_list() bimpy.same_line() if bimpy.button(LANG.about) == True: bimpy.open_popup(LANG.about) # call render about ui # print(dir(windows_info['about_ui'])) windows_info['about_ui']['self'].about() for idx, f_name in enumerate(self.fb.file_list): # print(self.selected.value) if bimpy.selectable( f_name.split('\\')[-1], self.selected.value == idx): self.selected.value = idx if self.selected.value != -1 and self.selected.value != self.preidx: self.preidx = self.selected.value windows_info['image_shower_ui']['self'].update_pic(f_name) windows_info['meta_info_ui']['self'].update_meta_info( f_name) # progress bar if not self.fb.q.empty(): self.process = self.fb.q.get() f, d = self.process[-2], self.process[-1] # update if new if d != {}: self.fb.pp.yolo_res[f] = d self.process = (self.process[0] + 1, self.process[1]) if self.process[0] == self.process[1]: with open('yolo_res', 'wb') as f: pickle.dump(self.fb.pp.yolo_res, f) # build retrieval index windows_info['retrival_ui']['self'].init = False sz = bimpy.get_window_size() bimpy.set_cursor_pos(bimpy.Vec2(conf.margin, sz.y - conf.margin * 2)) bimpy.push_item_width(sz.x - conf.margin * 3 - 60) process = self.process bimpy.progress_bar(process[0] / float(process[1]), bimpy.Vec2(0.0, 0.0), "{}/{}".format(process[0], process[1])) bimpy.same_line() if bimpy.button(LANG.reindex) == True and process[0] == process[1]: self.fb.refresh() ######################## t = { 'x': bimpy.get_window_pos().x, 'y': bimpy.get_window_pos().y, 'w': bimpy.get_window_size().x, 'h': bimpy.get_window_size().y, 'self': self, } bimpy.end() return t
def __buttons_window(self): bimpy.set_next_window_pos(bimpy.Vec2(5, 635), bimpy.Condition.Once) bimpy.set_next_window_size(bimpy.Vec2(1005, 128), bimpy.Condition.Once) bimpy.begin("Exercise Control", flags=bimpy.WindowFlags(4) | bimpy.WindowFlags(1) | bimpy.WindowFlags(2)) bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text_colored(bimpy.Vec4(1, 0, 0, 1), "Controls") bimpy.separator() bimpy.pop_font() bimpy.push_font(self.fonts.fonts[16]["cond"]) bimpy.text("") bimpy.same_line(0, 150) if self.pause_button_state == 1: bimpy.push_style_color(bimpy.Colors(0), bimpy.Vec4(0, 0, 0, 1)) bimpy.push_style_color(bimpy.Colors(21), bimpy.Vec4(0.8, 0.8, 0, 1)) bimpy.push_style_color(bimpy.Colors(22), bimpy.Vec4(1, 1, 0, 1)) bimpy.push_style_color(bimpy.Colors(23), bimpy.Vec4(0.5, 0.5, 0, 1)) pause_button_text = "Pause Exercise" elif self.pause_button_state == 0: bimpy.push_style_color(bimpy.Colors(0), bimpy.Vec4(0, 0, 0, 1)) bimpy.push_style_color(bimpy.Colors(21), bimpy.Vec4(0.0, 0.8, 0.0, 1)) bimpy.push_style_color(bimpy.Colors(22), bimpy.Vec4(0.0, 1, 0.0, 1)) bimpy.push_style_color(bimpy.Colors(23), bimpy.Vec4(0.0, 0.5, 0.0, 1)) pause_button_text = "Resume Exercise" elif self.pause_button_state == -1: bimpy.push_style_color(bimpy.Colors(0), bimpy.Vec4(0, 0, 0, 1)) bimpy.push_style_color(bimpy.Colors(21), bimpy.Vec4(0.4, 0.4, 0.4, 1)) bimpy.push_style_color(bimpy.Colors(22), bimpy.Vec4(0.4, 0.4, 0.4, 1)) bimpy.push_style_color(bimpy.Colors(23), bimpy.Vec4(0.4, 0.4, 0.4, 1)) pause_button_text = "------ -------" if bimpy.button(pause_button_text, bimpy.Vec2(250, 75)): if self.pause_button_state == 1: self.pause_button_state = 0 self.data.is_exercising = False elif self.pause_button_state == 0: self.pause_button_state = 1 self.data.is_exercising = True bimpy.pop_style_color() bimpy.pop_style_color() bimpy.pop_style_color() bimpy.pop_style_color() bimpy.same_line(450, 150) if self.stop_button_enabled: bimpy.push_style_color(bimpy.Colors(0), bimpy.Vec4(0, 0, 0, 1)) bimpy.push_style_color(bimpy.Colors(21), bimpy.Vec4(0.8, 0, 0, 1)) bimpy.push_style_color(bimpy.Colors(22), bimpy.Vec4(1, 0, 0, 1)) bimpy.push_style_color(bimpy.Colors(23), bimpy.Vec4(0.5, 0, 0, 1)) else: bimpy.push_style_color(bimpy.Colors(0), bimpy.Vec4(0, 0, 0, 1)) bimpy.push_style_color(bimpy.Colors(21), bimpy.Vec4(0.4, 0.4, 0.4, 1)) bimpy.push_style_color(bimpy.Colors(22), bimpy.Vec4(0.4, 0.4, 0.4, 1)) bimpy.push_style_color(bimpy.Colors(23), bimpy.Vec4(0.4, 0.4, 0.4, 1)) self.pause_button_state = -1 if bimpy.button("Stop Exercise", bimpy.Vec2(250, 75)): self.data.is_exercising = False self.stop_button_enabled = False bimpy.pop_style_color() bimpy.pop_style_color() bimpy.pop_style_color() bimpy.pop_style_color() bimpy.pop_font() bimpy.end()