def create_new_ideal_imager(**inputs): conj_type = (inputs['conjugate_type'] if 'conjugate_type' in inputs else 'finite') specsheets = create_specsheets() if 'opt_model' in inputs: opt_model = inputs['opt_model'] specsheet = create_specsheet_from_model(opt_model, specsheets=specsheets) conj_type = specsheet.conjugate_type specsheets[conj_type] = specsheet if 'gui_parent' in inputs: gui_parent = inputs['gui_parent'] opt_model = gui_parent.app_manager.model iid = IdealImagerDialog(conj_type, specsheets, cmd_fct=gui_parent.handle_ideal_imager_command, parent=gui_parent) gui_parent.add_subwindow(iid, ModelInfo(gui_parent.app_manager.model, update_specsheet, (iid, opt_model))) iid.update_values() iid.show() else: iid = IdealImagerDialog(conj_type, specsheets) iid.update_values() iid.exec_()
def create_ipython_console(app, title, view_width, view_ht): """ create a iPython console with a rayoptics environment """ opt_model = app.app_manager.model if opt_model: ro_env = { 'app': app, 'opm': opt_model, 'sm': opt_model.seq_model, 'osp': opt_model.optical_spec, 'pm': opt_model.parax_model } else: ro_env = {'app': app, 'opm': opt_model} ro_setup = 'from rayoptics.environment import *' # construct the top level widget ipy_console = ConsoleWidget() # load the environment ipy_console.execute_command(ro_setup) ipy_console.push_vars(ro_env) mi = ModelInfo(opt_model) sub_window = app.add_subwindow(ipy_console, mi) sub_window.setWindowTitle(title) orig_x, orig_y = app.initial_window_offset() sub_window.setGeometry(orig_x, orig_y, view_width, view_ht) sub_window.show()
def handle_ideal_imager_command(self, iid, command, specsheet): if command == 'Apply': opt_model = self.app_manager.model opt_model.set_from_specsheet(specsheet) self.refresh_gui() elif command == 'Close': for view, info in self.app_manager.view_dict.items(): if iid == info[0]: view.close() elif command == 'Update': opt_model = self.app_manager.model specsheet = opt_model.specsheet firstorder.specsheet_from_parax_data(opt_model, specsheet) iid.specsheet_dict[specsheet.conjugate_type] = specsheet iid.update_values() elif command == 'New': opt_model = cmds.create_new_optical_model_from_specsheet(specsheet) self.app_manager.set_model(opt_model) for view, info in self.app_manager.view_dict.items(): if iid == info[0]: w = iid mi = info[1] args = (iid, opt_model) new_mi = ModelInfo(model=opt_model, fct=mi.fct, args=args, kwargs=mi.kwargs) self.app_manager.view_dict[view] = w, new_mi self.refresh_gui() self.create_lens_table() cmds.create_live_layout_view(opt_model, gui_parent=self) cmds.create_paraxial_design_view(opt_model, 'ht', gui_parent=self) self.refresh_gui()
def create_glass_map_view(app, glass_db): def create_light_or_dark_callback(fig): def l_or_d(is_dark): fig.sync_light_or_dark(is_dark) return l_or_d title = 'Glass Map Viewer' width = 1100 height = 650 # glass_db = gm.GlassMapDB(['Schott', 'Hoya', 'Ohara']) pdt = "Refractive Index" # hotwire GlassMapFigure to inherit from StyledFigure gm.GlassMapFigure.__bases__ = (StyledFigure,) fig = gm.GlassMapFigure(glass_db, plot_display_type=pdt, # width=5, height=4, ) widget, pick_model = gmv.init_UI(app, fig) def refresh_gui(**kwargs): pick_model.fill_table(fig.pick_list) fig.refresh_gui = refresh_gui mi = ModelInfo(app.app_manager.model, update_figure_view, (fig,)) sub_window = app.add_subwindow(widget, mi) sub_window.sync_light_or_dark = create_light_or_dark_callback(fig) sub_window.setWindowTitle(title) orig_x, orig_y = app.initial_window_offset() sub_window.setGeometry(orig_x, orig_y, width, height) sub_window.show()
def create_plot_view(app, fig, title, view_width, view_ht, commands=None, add_panel_fcts=None, add_nav_toolbar=False, drop_action=None): """ create a window hosting a (mpl) figure """ def create_light_or_dark_callback(fig): def l_or_d(is_dark): fig.sync_light_or_dark(is_dark) return l_or_d # construct the top level widget widget = QWidget() top_layout = QHBoxLayout(widget) # set the layout on the widget widget.setLayout(top_layout) if commands: command_panel = create_command_panel(fig, commands) top_layout.addWidget(command_panel) # construct the top level layout plot_layout = QVBoxLayout() top_layout.addLayout(plot_layout) pc = PlotCanvas(app, fig, drop_action=drop_action) if add_panel_fcts is not None: panel_layout = QHBoxLayout() plot_layout.addLayout(panel_layout) for p in add_panel_fcts: panel = p(app, pc) panel_layout.addWidget(panel) panel_layout.addStretch(50) mi = ModelInfo(app.app_manager.model, update_figure_view, (fig, )) sub_window = app.add_subwindow(widget, mi) sub_window.sync_light_or_dark = create_light_or_dark_callback(fig) lens_title = app.app_manager.model.name() sub_window.setWindowTitle(title + ': ' + lens_title) orig_x, orig_y = app.initial_window_offset() sub_window.setGeometry(orig_x, orig_y, view_width, view_ht) plot_layout.addWidget(pc) if add_nav_toolbar: plot_layout.addWidget(NavigationToolbar(pc, sub_window)) sub_window.show()
def create_ipython_console(app, title, view_width, view_ht): """ create a iPython console with a rayoptics environment """ def create_light_or_dark_callback(ipy_console): # if not hasattr(ipy_console, 'background'): # ipy_console.background = ipy_console.background() def l_or_d(is_dark): if is_dark: ipy_console.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) # rgb = DarkPalette.color_palette() # ipy_console.setBackground(QColor( # rgb['COLOR_BACKGROUND_NORMAL'])) else: ipy_console.setStyleSheet('') # ipy_console.setBackground(ipy_console.background) return l_or_d opt_model = app.app_manager.model if opt_model: ro_env = { 'app': app, 'opm': opt_model, 'sm': opt_model.seq_model, 'osp': opt_model.optical_spec, 'pm': opt_model.parax_model } else: ro_env = {'app': app, 'opm': opt_model} ro_setup = 'from rayoptics.environment import *' # construct the top level widget ipy_console = ConsoleWidget() # load the environment ipy_console.execute_command(ro_setup) ipy_console.push_vars(ro_env) mi = ModelInfo(opt_model) sub_window = app.add_subwindow(ipy_console, mi) sub_window.setWindowTitle(title) sub_window.sync_light_or_dark = create_light_or_dark_callback(ipy_console) orig_x, orig_y = app.initial_window_offset() sub_window.setGeometry(orig_x, orig_y, view_width, view_ht) sub_window.show()
def create_plot_view(app, fig, title, view_width, view_ht, commands=None, add_panel_fcts=None, add_nav_toolbar=False): # construct the top level widget widget = QWidget() top_layout = QHBoxLayout(widget) # set the layout on the widget widget.setLayout(top_layout) if commands: command_panel = create_command_panel(fig, commands) top_layout.addWidget(command_panel) # construct the top level layout plot_layout = QVBoxLayout() top_layout.addLayout(plot_layout) pc = PlotCanvas(app, fig) if add_panel_fcts is not None: panel_layout = QHBoxLayout() plot_layout.addLayout(panel_layout) for p in add_panel_fcts: panel = p(app, pc) panel_layout.addWidget(panel) panel_layout.addStretch(50) mi = ModelInfo(app.app_manager.model, update_figure_view, (fig, )) sub_window = app.add_subwindow(widget, mi) sub_window.setWindowTitle(title) orig_x, orig_y = app.initial_window_offset() sub_window.setGeometry(orig_x, orig_y, view_width, view_ht) plot_layout.addWidget(pc) if add_nav_toolbar: plot_layout.addWidget(NavigationToolbar(pc, sub_window)) sub_window.show()
def handle_ideal_imager_command(self, iid, command, specsheet): ''' link Ideal Imager Dialog buttons to model actions iid: ideal imager dialog command: text field with the action - same as button label specsheet: the input specsheet used to drive the actions ''' if command == 'Apply': opt_model = self.app_manager.model opt_model.set_from_specsheet(specsheet) self.refresh_gui() elif command == 'Close': for view, info in self.app_manager.view_dict.items(): if iid == info[0]: self.delete_subwindow(view) view.close() break elif command == 'Update': opt_model = self.app_manager.model specsheet = opt_model.specsheet firstorder.specsheet_from_parax_data(opt_model, specsheet) iid.specsheet_dict[specsheet.conjugate_type] = specsheet iid.update_values() elif command == 'New': opt_model = cmds.create_new_optical_model_from_specsheet(specsheet) self.app_manager.set_model(opt_model) for view, info in self.app_manager.view_dict.items(): if iid == info[0]: w = iid mi = info[1] args = (iid, opt_model) new_mi = ModelInfo(model=opt_model, fct=mi.fct, args=args, kwargs=mi.kwargs) self.app_manager.view_dict[view] = w, new_mi self.refresh_gui() self.create_lens_table() cmds.create_live_layout_view(opt_model, gui_parent=self) cmds.create_paraxial_design_view_v2(opt_model, 'ht', gui_parent=self) self.refresh_gui()
def create_table_view(self, table_model, table_title, close_callback=None): # construct the top level widget widget = QWidget() # construct the top level layout layout = QVBoxLayout(widget) tableView = QTableView() tableView.setAlternatingRowColors(True) # Add table to box layout layout.addWidget(tableView) # set the layout on the widget widget.setLayout(layout) sub = self.add_subwindow( widget, ModelInfo(self.app_manager.model, cmds.update_table_view, (tableView, ))) sub.setWindowTitle(table_title) sub.installEventFilter(self) tableView.setModel(table_model) tableView.setMinimumWidth(tableView.horizontalHeader().length() + tableView.horizontalHeader().height()) # The following line should work but returns 0 # tableView.verticalHeader().width()) view_width = tableView.width() view_ht = tableView.height() orig_x, orig_y = self.initial_window_offset() sub.setGeometry(orig_x, orig_y, view_width, view_ht) # table data updated successfully table_model.update.connect(self.on_data_changed) sub.show() return sub
def create_2D_lens_view(self): scene2d = QGraphicsScene() self.create_element_model(scene2d) self.create_ray_model(scene2d) scene2d.setBackgroundBrush(QColor(237, 243, 254)) # light blue sceneRect2d = scene2d.sceneRect() # construct the top level widget widget = QWidget() # construct the top level layout layout = QVBoxLayout(widget) # set the layout on the widget widget.setLayout(layout) sub = self.add_subwindow( widget, ModelInfo(self.app_manager.model, MainWindow.update_2D_lens_view, (scene2d, ))) sub.setWindowTitle("2D Lens View") view_width = 660 view_ht = 440 view_ratio = view_width / view_ht orig_x, orig_y = self.initial_window_offset() sub.setGeometry(orig_x, orig_y, view_width, view_ht) self.gview2d = QGraphicsView(scene2d) scene_ratio = sceneRect2d.width() / sceneRect2d.height() oversize_fraction = 1.2 if scene_ratio > view_ratio: view_scale = view_width / (oversize_fraction * sceneRect2d.width()) else: view_scale = view_ht / (oversize_fraction * sceneRect2d.height()) self.gview2d.scale(view_scale, view_scale) layout.addWidget(self.gview2d) sub.show() return sub