def update(self, event): kwargs = event.kwargs xlim = kwargs["xlim"] ylim = kwargs["ylim"] major_x_tick = kwargs["major_x_tick"] major_y_tick = kwargs["major_y_tick"] minor_x_tick = kwargs["minor_x_tick"] minor_y_tick = kwargs["minor_y_tick"] auto_scale = kwargs.pop("auto_scale", False) with code_printer(): current_figure = self.__figure_book.current_figure if auto_scale: current_figure.auto_scale() return lim = list(xlim) if current_figure.is_polar: lim = list(deg2rad(lim)) major_x_tick = deg2rad(major_x_tick) if minor_x_tick is not None: minor_x_tick = deg2rad(minor_x_tick) lim.extend(ylim) current_figure.axis(lim) for XY in ('x_', 'y_'): for mm in ('major_', 'minor_'): current_figure.set_tick(mm + XY + 'tick', locals()[mm + XY + 'tick'])
def _on_save_mat_file(self): filename = asksaveasfilename(filetypes=[('Matlab mat files', '*.mat')]) if not filename: return def linkFunc(filename): with code_printer(): clipboard = Scripting.root_node.interfaces.os.clipboard clipboard.clear() clipboard.write(auto_subs('load $filename')) with code_printer(): self.__topwin.save_mat_file(filename) tip = [{ 'type': 'text', 'content': auto_subs( '''The correlation matrix has been saved in the mat file "$filename" successully. You can extract the data in Matlab using the following command:''') }, { 'type': 'link', 'content': auto_subs('>> load $filename'), 'command': lambda dumb: linkFunc(filename=filename) }, { 'type': 'text', 'content': '''and variable named "R" will appear in your Matlab workspace. (Click the underlined Matlab command and copy it to the clipboard)''' }] self._app.gui.console.show_tips(tip)
def _on_item_doubleclick(self, item_id, item_properties): try: path = item_properties['values'][0] except IndexError: return with code_printer(): Scripting.root_node.interfaces.os.win_open(path)
def on_ok(): link_str = link.get() text_str = text.get() target = '' if not blank.get() else 'target="_blank"' with code_printer(): self.root_node.interfaces.os.clipboard.write(f'<a href="{link_str}" {target}>{text_str}</a>', html=True) win.destroy()
def on_click(): console =Scripting.root_node.gui.console b = console.is_topmost fg = 'black' if b else 'lime green' topmost_button['fg'] = fg with code_printer(True): console.set_topmost(not b)
def _on_save_mat_file(self): filename = asksaveasfilename(filetypes=[('Matlab mat files', '*.mat')]) if not filename: return def linkFunc(filename): with code_printer(): clipboard = Scripting.root_node.interfaces.os.clipboard clipboard.clear() clipboard.write(auto_subs('load $filename')) with code_printer(): self.__topwin.save_mat_file(filename) tip = [ { 'type':'text', 'content':auto_subs('''The correlation matrix has been saved in the mat file "$filename" successully. You can extract the data in Matlab using the following command:''') }, { 'type':'link', 'content':auto_subs('>> load $filename'), 'command':lambda dumb: linkFunc(filename=filename) }, { 'type':'text', 'content':'''and variable named "R" will appear in your Matlab workspace. (Click the underlined Matlab command and copy it to the clipboard)''' } ] self._app.gui.console.show_tips(tip)
def on_ok(): link_str = link.get() text_str = text.get() target = '' if not blank.get() else 'target="_blank"' with code_printer(): self.root_node.interfaces.os.clipboard.write( f'<a href="{link_str}" {target}>{text_str}</a>', html=True) win.destroy()
def update(self, delType): with code_printer(): if delType == 'all': self.__figure_book.clear() elif delType == 'sel': self.__figure_book.delete_selected_lines(index=None) else: return
def chdir_func(directory, passive): try: with code_printer(not passive): self.root_node.interfaces.os.chdir(directory=directory) except AttributeError: # While the console node is connecting, several components # are not ready to use. os.chdir(directory)
def _on_export_matlab_script(self): filename = asksaveasfilename(filetypes=[('Matlab script files', '*.m')]) if not filename: return with code_printer(): self.__topwin.figure_book.export_matlab_script(filename) self._app.gui.console.show_tips(f'''A Matlab script file has been saved as {filename}. By running this script, Matlab will literally "re-plot" the curves shown here.''')
def run(self): with code_printer(print_=False): com = self.get_command_string() stdout, stderr, errorlevel = execute(com) coding = chardet.detect(stdout)['encoding'] stdout = stdout.decode(coding) stderr = stderr.decode(coding) return {'stdout':json.loads(stdout), 'stderr':stderr, 'errorlevel':errorlevel}
def __on_insert_psd(self): office = self.root_node.interfaces.msoffice kwargs = {'filename':self.root_node.lang_center.wavesynscript.constants.ASK_OPEN_FILENAME} id_, app_name, txt, is_parent = self.__get_selected() if not is_parent: kwargs['window'] = txt with code_printer(): office[id_].utils.insert_psd_image(**kwargs)
def solve_func(): with code_printer(): topwin.solve(M=M, display=bool(display)) @self._app.thread_manager.main_thread_do(block=False) def on_finish_solving(): with code_printer(): topwin.plot_current_data()
def _on_write_click(self): serialno = self.__dev_combo.get() data = self.__writebuf.get() if len(data) % 2 != 0: data += '0' data_list = [int(data[(k*2):(k*2+2)], base=16) for k in range(len(data)//2)] with code_printer(): self.write_bytes(serial_number=serialno, data=data_list)
def update(self, event): del_type = event.kwargs["del_type"] with code_printer(): if del_type == 'all': self.__figure_book.clear() elif del_type == 'sel': self.__figure_book.delete_selected_lines(index=None) else: return
def _on_open_click(self): open_or_close = self.__is_opened.get() serialno = self.__dev_combo.get() with code_printer(): if open_or_close: self.open_device(serialno) else: self.close_device(serialno)
def __on_export_to_dvplane_btn_click(self): sel_exist, winid_str = ask_dvplane(self) radius = askfloat("Radius", "Please input radius:", initialvalue=1.0) if sel_exist: winid = int(winid_str) else: winid = "new" with code_printer(): self.export_to_dvplane(winid, radius=radius)
def __on_update_psd(self): office = self.root_node.interfaces.msoffice id_, app_name, txt, is_parent = self.__get_selected() if not is_parent: window = txt else: window = None with code_printer(): office[id_].utils.update_psd_images(window=window)
def __on_update_psd(self): office = self.root_node.toolboxes["msoffice"].app_dict id_, app_name, txt, is_parent = self.__get_selected() if not is_parent: window = txt else: window = None with code_printer(): office[id_].utils.update_psd_images(window=window)
def _on_solve_click(self): params = self.__topwin.parameter_group.get_parameters() repeat_times = self.__num.get_int() if self.__parallel_checker_variable.get(): run = self.__topwin.current_algorithm.process_run else: run = self.__topwin.current_algorithm.thread_run with code_printer(): run(on_finished=['store', 'plot'], progress_indicator='progress_dialog', repeat_times=repeat_times, **params)
def _on_export_matlab_script(self): filename = asksaveasfilename(filetypes=[('Matlab script files', '*.m')]) if not filename: return with code_printer(): self.__topwin.figure_book.export_matlab_script(filename) self._app.gui.console.show_tips( f'''A Matlab script file has been saved as {filename}. By running this script, Matlab will literally "re-plot" the curves shown here.''' )
def _on_solve_button_click(self): with code_printer(): topwin = self.__topwin beam_data = topwin.edit_group.beam_data if not beam_data: showerror( 'Error', 'Please input the specification of the ideal beam pattern.' ) return topwin.figure_book.clear() topwin.set_ideal_pattern(*beam_data) topwin.plot_ideal_pattern() M = self.__M.get_int() display = self.__bDisplay.get() with code_printer(): topwin.solve.new_thread_run(M=M, verbose=bool(display), on_finish=["draw"])
def __connect_app(self, app_name=None, get_active=True): if app_name is None: app_name = self.root_node.lang_center.wavesynscript.constants.ASK_LIST_ITEM msoffice = self.root_node.toolboxes["msoffice"].app_dict with code_printer(): if get_active: msoffice.get_active(app_name=app_name) else: msoffice.create(app_name=app_name) self.__treeview.update(msoffice)
def __on_insert_psd(self): office = self.root_node.toolboxes["msoffice"].app_dict kwargs = { 'filename': self.root_node.lang_center.wavesynscript.constants. ASK_OPEN_FILENAME } id_, app_name, txt, is_parent = self.__get_selected() if not is_parent: kwargs['window'] = txt with code_printer(): office[id_].utils.insert_psd_image(**kwargs)
def _on_write_click(self): serialno = self.__dev_combo.get() data = self.__writebuf.get() if len(data) % 2 != 0: data += '0' data_list = [ int(data[(k * 2):(k * 2 + 2)], base=16) for k in range(len(data) // 2) ] with code_printer(): self.write_bytes(serial_number=serialno, data=data_list)
def __connect_app(self, app_name=None, get_active=True): if app_name is None: app_name = self.root_node.lang_center.wavesynscript.constants.ASK_LIST_ITEM msoffice = self.root_node.interfaces.msoffice with code_printer(): if get_active: msoffice.get_active(app_name=app_name) else: msoffice.create(app_name=app_name) self.__treeview.update(msoffice)
def update(self, event): kwargs = event.kwargs label_type = kwargs["label_type"] label_string = kwargs["label_string"] name_map = { 'title': 'set_title', 'xlabel': 'setXLabel', 'ylabel': 'setYLabel' } with code_printer(): current_figure = self.__figure_book.current_figure getattr(current_figure, name_map[label_type])(label_string)
def _on_solve_click(self): params = self.__topwin.parameter_group.get_parameters() repeat_times = self.__num.get_int() if self.__parallel_checker_variable.get(): run = self.__topwin.current_algorithm.process_run else: run = self.__topwin.current_algorithm.thread_run with code_printer(): run(on_finished=['store', 'draw'], progress_indicator='progress_dialog', repeat_times=repeat_times, **params)
def __on_foreground(self): office = self.root_node.toolboxes["msoffice"].app_dict id_, app_name, txt, is_parent = self.__get_selected() kwargs = {} if app_name == 'word' and not is_parent: kwargs['index'] = txt with code_printer(print_=True): try: office[id_].set_foreground(**kwargs) except COMError as err: tk.messagebox.showerror( title='Office Error', message='\n'.join([str(item) for item in err.details]))
def update(self, meta): if meta['type'] in ('axvspan', 'axhspan'): if meta['type'] == 'axvspan': the_min = meta['xmin'] the_max = meta['xmax'] else: the_min = meta['ymin'] the_max = meta['ymax'] props = meta['props'] with code_printer(): getattr(self.__figure_book.current_figure.indicators, meta['type'])(the_min, the_max, **props) self.__figure_book.update_indicator_list()
def update(self, major_grid, minor_grid, props=None): if not props: props = {'major':{}, 'minor':{}} switch_name_map = {True:'on', False:'off'} major_grid = switch_name_map[major_grid] minor_grid = switch_name_map[minor_grid] current_figure = self.__figure_book.current_figure with code_printer(): current_figure.turn_grid(major_grid, which='major', **props['major']) current_figure.turn_grid(minor_grid, which='minor', **props['minor'])
def __on_foreground(self): office = self.root_node.interfaces.msoffice id_, app_name, txt, is_parent = self.__get_selected() kwargs = {} if app_name == 'word' and not is_parent: kwargs['index'] = txt with code_printer(print_=True): try: office[id_].set_foreground(**kwargs) except COMError as err: tk.messagebox.showerror( title = 'Office Error', message = '\n'.join([str(item) for item in err.details]))
def update(self, event): meta = event.kwargs["meta"] if meta['type'] in ('axvspan', 'axhspan'): if meta['type'] == 'axvspan': the_min = meta['xmin'] the_max = meta['xmax'] else: the_min = meta['ymin'] the_max = meta['ymax'] props = meta['props'] with code_printer(): getattr(self.__figure_book.current_figure.indicators, meta['type'])(the_min, the_max, **props) self.__figure_book.update_indicator_list()
def update(self, xlim, ylim, major_x_tick, major_y_tick, minor_x_tick, minor_y_tick, auto_scale=False): with code_printer(): current_figure = self.__figure_book.current_figure if auto_scale: current_figure.auto_scale() return lim = list(xlim) if current_figure.is_polar: lim = list(deg2rad(lim)) major_x_tick = deg2rad(major_x_tick) if minor_x_tick is not None: minor_x_tick = deg2rad(minor_x_tick) lim.extend(ylim) current_figure.axis(lim) for XY in ('x_', 'y_'): for mm in ('major_', 'minor_'): current_figure.set_tick(mm+XY+'tick', locals()[mm+XY+'tick'])
def _on_param_change(self): serialno = self.__dev_combo.get() baudrate = int(self.__baud_combo.get()) CPOL = self.__CPOL.get() CPHA = self.__CPHA.get() read_timeout = int(self.__read_timeout_str.get()) write_timeout = int(self.__write_timeout_str.get()) kwargs = {} kwargs['serial_number'] = serialno kwargs['is_master'] = True kwargs['baudrate'] = baudrate kwargs['CPHA'] = CPHA kwargs['CPOL'] = CPOL kwargs['read_timeout'] = read_timeout kwargs['write_timeout'] = write_timeout with code_printer(): self.configure_device(**kwargs)
def update(self, event): kwargs = event.kwargs major_grid = kwargs["major_grid"] minor_grid = kwargs["minor_grid"] props = kwargs.pop("props", None) if not props: props = {'major': {}, 'minor': {}} switch_name_map = {True: 'on', False: 'off'} major_grid = switch_name_map[major_grid] minor_grid = switch_name_map[minor_grid] current_figure = self.__figure_book.current_figure with code_printer(): current_figure.turn_grid(major_grid, which='major', **props['major']) current_figure.turn_grid(minor_grid, which='minor', **props['minor'])
def _on_solve_button_click(self): with code_printer(): topwin = self.__topwin center, width = topwin.edit_group.beam_data topwin.figure_book.clear() topwin.set_ideal_pattern(center, width) topwin.plot_ideal_pattern() M = self.__M.get_int() display = self.__bDisplay.get() # Create a new thread for solving the correlation matrix. def solve_func(): with code_printer(): topwin.solve(M=M, display=bool(display)) @self._app.thread_manager.main_thread_do(block=False) def on_finish_solving(): with code_printer(): topwin.plot_current_data() thread.start_new_thread(solve_func, ())
def check_cpu_mem_battery(event): with code_printer(print_=False): self.__membar.set(get_memory_usage()) self.__cpubar.set(get_cpu_usage()) battery_status = get_battery_status() if battery_status: percent = battery_status.percent if percent > 75: percent = 100 elif percent > 50: percent = 75 elif percent > 25: percent = 50 elif percent > 10: percent = 25 else: percent = 10 charge = '_charge' if battery_status.power_plugged else '' image_name = f'{percent}per{charge}' image = battery_images[image_name] if battery_meter['image'] != image: battery_meter['image'] = image
def check_cpu_mem_battery(): with code_printer(print_=False): self.__membar.set(get_memory_usage()) self.__cpubar.set(get_cpu_usage()) battery_status = get_battery_status() if battery_status: percent = battery_status.percent if percent > 75: percent = 100 elif percent > 50: percent = 75 elif percent > 25: percent = 50 elif percent > 10: percent = 25 else: percent = 10 charge = '_charge' if battery_status.power_plugged else '' image_name = f'{percent}per{charge}' image = battery_images[image_name] if battery_meter['image'] != image: battery_meter['image'] = image
def _on_copy_path_click(self): with code_printer(): self.copy_window_path()
def _on_copy_id_click(self): with code_printer(): self.copy_window_id()
def callback(code, var): enable = False if var.get() else True with code_printer(): self.enable_key(enable, code)
def on_close(self): with code_printer(): self.close()
def __on_copy_path(self): with code_printer(): self.copy_selected_path()
def foreground_run_macro(self, macro_name, *args): self.set_foreground() with code_printer(False): ret = self.run_macro(macro_name, *args) return ret
def linkFunc(filename): with code_printer(): clipboard = Scripting.root_node.interfaces.os.clipboard clipboard.clear() clipboard.write(auto_subs('load $filename'))
def browse_func(*args): with code_printer(): self.root_node.interfaces.os.win_open(path)
def load(): with code_printer(): self._topwin.load_algorithm(module_name=module_name, class_name=class_name)
def _on_reload_algorithm(self): with code_printer(): self._topwin.current_algorithm.reload_algorithm()
def _on_topmost_click(self): with code_printer(): topmost = True if self.__topmost.get() else False self.set_topmost(topmost)