def _LoadFile(self, event=None): self._ConfirmResetSession() wildcards = [("Model files", "*.cpymad.yml"), ("MAD-X files", "*.madx", "*.str", "*.seq"), ("All files", "*")] with OpenDialog(self, "Open model", wildcards) as dlg: dlg.Directory = self.app.conf.get('model_path', '.') ShowModal(dlg) name = dlg.Filename repo = FileResource(dlg.Directory) session = Session.load(self.madx_units, repo, name) self._ResetSession(session) if not session.madx.sequences: return with Dialog(self) as dialog: widget = ModelWidget(dialog, session) data = widget.Query(session.data) session.init_segment(data) segment = session.segment self.env['segment'] = segment self.env['sequence'] = segment.sequence self.env['elements'] = segment.elements self.env['twiss'] = segment.sequence.twiss_table TwissView.create(session, self, basename='env')
def _CreateMenu(self): """Create a menubar.""" # TODO: this needs to be done more dynamically. E.g. use resource # files and/or a plugin system to add/enable/disable menu elements. MenuItem = menu.Item Menu = menu.Menu Separator = menu.Separator menubar = self.menubar = wx.MenuBar() menu.extend(self, menubar, [ Menu('&Session', [ MenuItem('&New session window\tCtrl+N', 'Open a new session window', self.OnNewWindow), MenuItem('&Python shell\tCtrl+P', 'Open a tab with a python shell', self._NewCommandTab), Separator, MenuItem('&Open model\tCtrl+O', 'Load model or open new model from a MAD-X file.', self._LoadFile), MenuItem('&Save model as..\tCtrl+S', 'Save the current model (beam + twiss) to a file', self._SaveModel, self._CanSaveModel), Separator, MenuItem('&Reset session', 'Clear the MAD-X session state.', lambda _: self._ResetSession()), Separator, MenuItem('&Close', 'Close window', self.OnQuit, id=wx.ID_CLOSE), ]), Menu('&View', [ MenuItem('&Envelope', 'Open new tab with beam envelopes.', lambda _: TwissView.create(self.session, self, basename='env')), MenuItem('&Position', 'Open new tab with beam position.', lambda _: TwissView.create(self.session, self, basename='pos')), ]), Menu('&Manage', [ MenuItem('&Initial conditions', 'Add/remove/edit TWISS initial conditions.', self._EditTwiss), MenuItem('&Beam', 'Set beam.', self._SetBeam), Separator, MenuItem('Show &element indicators', 'Show indicators for beam line elements.', self._ShowIndicators, self._UpdateShowIndicators, wx.ITEM_CHECK), ]), Menu('&Help', [ MenuItem('&About', 'Show about dialog.', lambda _: show_about_dialog(self)), ]), ]) # Create menu items self.hook.menu(self, menubar) self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateMenu, menubar) self._IsEnabledTop = {self.ViewMenuIndex: True, self.TabMenuIndex: True} return menubar