def __init__(self, *args, **kwds): # begin wxGlade: MplFrame.__init__ kwds[ "style"] = wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.MAXIMIZE | wx.MAXIMIZE_BOX | wx.SYSTEM_MENU | wx.RESIZE_BORDER | wx.FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.mplmenubar = wx.MenuBar() self.File = wx.Menu() self.Open = wx.MenuItem(self.File, wx.NewId(), "Open", "", wx.ITEM_NORMAL) self.File.AppendItem(self.Open) self.File.AppendSeparator() self.Quit = wx.MenuItem(self.File, wx.NewId(), "Quit", "", wx.ITEM_NORMAL) self.File.AppendItem(self.Quit) self.mplmenubar.Append(self.File, "File") self.SetMenuBar(self.mplmenubar) # Menu Bar end self.mpltextctrl = wx.TextCtrl(self, -1, "/usr/share/dict/words") self.mplbutton = wx.Button(self, -1, "Parse this file") self.mplpanel = MplPanel(self, -1) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_MENU, self.onFileOpen, self.Open) self.Bind(wx.EVT_MENU, self.onFileQuit, self.Quit) self.Bind(wx.EVT_BUTTON, self.parse_file, self.mplbutton)
class MplFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MplFrame.__init__ kwds["style"] = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.MAXIMIZE|wx.MAXIMIZE_BOX|wx.SYSTEM_MENU|wx.RESIZE_BORDER|wx.FULL_REPAINT_ON_RESIZE|wx.CLIP_CHILDREN wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.mplmenubar = wx.MenuBar() self.File = wx.Menu() self.Open = wx.MenuItem(self.File, wx.NewId(), "Open", "", wx.ITEM_NORMAL) self.File.AppendItem(self.Open) self.File.AppendSeparator() self.Quit = wx.MenuItem(self.File, wx.NewId(), "Quit", "", wx.ITEM_NORMAL) self.File.AppendItem(self.Quit) self.mplmenubar.Append(self.File, "File") self.SetMenuBar(self.mplmenubar) # Menu Bar end self.mpltextctrl = wx.TextCtrl(self, -1, "/usr/share/dict/words") self.mplbutton = wx.Button(self, -1, "Parse this file") self.mplpanel = MplPanel(self, -1) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_MENU, self.onFileOpen, self.Open) self.Bind(wx.EVT_MENU, self.onFileQuit, self.Quit) self.Bind(wx.EVT_BUTTON, self.parse_file, self.mplbutton) # end wxGlade def __set_properties(self): # begin wxGlade: MplFrame.__set_properties self.SetTitle("Matplotlib In wxGlade - Count letters frequency in a file") self.SetSize((600, 460)) # end wxGlade def __do_layout(self): # begin wxGlade: MplFrame.__do_layout mplsizer1 = wx.BoxSizer(wx.VERTICAL) mplsizer2 = wx.BoxSizer(wx.HORIZONTAL) mplsizer2.Add(self.mpltextctrl, 1, wx.EXPAND, 0) mplsizer2.Add(self.mplbutton, 0, 0, 0) mplsizer1.Add(mplsizer2, 0, wx.EXPAND, 0) mplsizer1.Add(self.mplpanel, 1, wx.ALL|wx.EXPAND, 0) self.SetSizer(mplsizer1) self.Layout() # end wxGlade def onFileOpen(self, event): # wxGlade: MplFrame.<event_handler> filename = wx.FileSelector() if filename: self.mpltextctrl.SetValue(filename) def onFileQuit(self, event): # wxGlade: MplFrame.<event_handler> # closes the window self.Close(True) def parse_file(self, event): # wxGlade: MplFrame.<event_handler> self.mplpanel.update_graph(self.mpltextctrl.GetValue())
def __init__(self, *args, **kwds): # begin wxGlade: MainFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.menubar = wx.MenuBar() self.File = wx.Menu() self.Save = wx.MenuItem(self.File, wx.ID_SAVE, "&Save", "Have current figure", wx.ITEM_NORMAL) self.File.AppendItem(self.Save) self.Exit = wx.MenuItem(self.File, wx.ID_EXIT, "E&xit", "Terminate the program", wx.ITEM_NORMAL) self.File.AppendItem(self.Exit) self.menubar.Append(self.File, "&File") self.Options = wx.Menu() self.SetGrid = wx.MenuItem(self.Options, wx.ID_PROPERTIES, "Set grid", "Defined the size of the grid grid", wx.ITEM_NORMAL) self.Options.AppendItem(self.SetGrid) self.menubar.Append(self.Options, "&Options") self.Help = wx.Menu() self.About = wx.MenuItem(self.Help, wx.ID_ABOUT, "&About", "Information about this program", wx.ITEM_NORMAL) self.Help.AppendItem(self.About) self.menubar.Append(self.Help, "&Help") self.SetMenuBar(self.menubar) # Menu Bar end self.mplPanel = MplPanel(self, wx.ID_ANY) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_MENU, self.onSave, self.Save) self.Bind(wx.EVT_MENU, self.onExit, self.Exit) self.Bind(wx.EVT_MENU, self.onSetGrid, self.SetGrid) self.Bind(wx.EVT_MENU, self.onAbout, self.About)
def __init__(self, *args, **kwds): # begin wxGlade: MplFrame.__init__ kwds["style"] = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.MAXIMIZE|wx.MAXIMIZE_BOX|wx.SYSTEM_MENU|wx.RESIZE_BORDER|wx.FULL_REPAINT_ON_RESIZE|wx.CLIP_CHILDREN wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.mplmenubar = wx.MenuBar() self.File = wx.Menu() self.Open = wx.MenuItem(self.File, wx.NewId(), "Open", "", wx.ITEM_NORMAL) self.File.AppendItem(self.Open) self.File.AppendSeparator() self.Quit = wx.MenuItem(self.File, wx.NewId(), "Quit", "", wx.ITEM_NORMAL) self.File.AppendItem(self.Quit) self.mplmenubar.Append(self.File, "File") self.SetMenuBar(self.mplmenubar) # Menu Bar end self.mpltextctrl = wx.TextCtrl(self, -1, "/usr/share/dict/words") self.mplbutton = wx.Button(self, -1, "Parse this file") self.mplpanel = MplPanel(self, -1) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_MENU, self.onFileOpen, self.Open) self.Bind(wx.EVT_MENU, self.onFileQuit, self.Quit) self.Bind(wx.EVT_BUTTON, self.parse_file, self.mplbutton)
def __init__(self, *args, **kwds): self.dirname = "" self.filename = "" # begin wxGlade: MainFrame.__init__ kwds["style"] = ( wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.MAXIMIZE | wx.MAXIMIZE_BOX | wx.SYSTEM_MENU | wx.RESIZE_BORDER | wx.CLIP_CHILDREN ) wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.menubar = wx.MenuBar() wxglade_tmp_menu = wx.Menu() self.Open = wx.MenuItem(wxglade_tmp_menu, wx.ID_OPEN, "&Open", "Open a file to load", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Open) self.Save = wx.MenuItem(wxglade_tmp_menu, wx.ID_SAVE, "&Save", "Save data file", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Save) self.Exit = wx.MenuItem(wxglade_tmp_menu, wx.ID_EXIT, "E&xit", "Terminate the program", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Exit) self.menubar.Append(wxglade_tmp_menu, "File") wxglade_tmp_menu = wx.Menu() self.Preferences = wx.MenuItem( wxglade_tmp_menu, wx.ID_PREFERENCES, "&Preferences", "Figure and axes preferences", wx.ITEM_NORMAL ) wxglade_tmp_menu.AppendItem(self.Preferences) self.menubar.Append(wxglade_tmp_menu, "Settings") wxglade_tmp_menu = wx.Menu() self.About = wx.MenuItem( wxglade_tmp_menu, wx.ID_ABOUT, "&About", "Information about this program", wx.ITEM_NORMAL ) wxglade_tmp_menu.AppendItem(self.About) self.menubar.Append(wxglade_tmp_menu, "Help") self.SetMenuBar(self.menubar) # Menu Bar end self.statusbar = self.CreateStatusBar(1, 0) self.mplPanel = MplPanel(self, wx.ID_ANY) self.stgPanel = StgPanel(self, wx.ID_ANY) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_MENU, self.OnOpen, self.Open) self.Bind(wx.EVT_MENU, self.OnSave, self.Save) self.Bind(wx.EVT_MENU, self.OnExit, self.Exit) self.Bind(wx.EVT_MENU, self.onPreferences, self.Preferences) self.Bind(wx.EVT_MENU, self.OnAbout, self.About)
class MplFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MplFrame.__init__ kwds[ "style"] = wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.MAXIMIZE | wx.MAXIMIZE_BOX | wx.SYSTEM_MENU | wx.RESIZE_BORDER | wx.FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.mplmenubar = wx.MenuBar() self.File = wx.Menu() self.Open = wx.MenuItem(self.File, wx.NewId(), "Open", "", wx.ITEM_NORMAL) self.File.AppendItem(self.Open) self.File.AppendSeparator() self.Quit = wx.MenuItem(self.File, wx.NewId(), "Quit", "", wx.ITEM_NORMAL) self.File.AppendItem(self.Quit) self.mplmenubar.Append(self.File, "File") self.SetMenuBar(self.mplmenubar) # Menu Bar end self.mpltextctrl = wx.TextCtrl(self, -1, "/usr/share/dict/words") self.mplbutton = wx.Button(self, -1, "Parse this file") self.mplpanel = MplPanel(self, -1) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_MENU, self.onFileOpen, self.Open) self.Bind(wx.EVT_MENU, self.onFileQuit, self.Quit) self.Bind(wx.EVT_BUTTON, self.parse_file, self.mplbutton) # end wxGlade def __set_properties(self): # begin wxGlade: MplFrame.__set_properties self.SetTitle( "Matplotlib In wxGlade - Count letters frequency in a file") self.SetSize((600, 460)) # end wxGlade def __do_layout(self): # begin wxGlade: MplFrame.__do_layout mplsizer1 = wx.BoxSizer(wx.VERTICAL) mplsizer2 = wx.BoxSizer(wx.HORIZONTAL) mplsizer2.Add(self.mpltextctrl, 1, wx.EXPAND, 0) mplsizer2.Add(self.mplbutton, 0, 0, 0) mplsizer1.Add(mplsizer2, 0, wx.EXPAND, 0) mplsizer1.Add(self.mplpanel, 1, wx.ALL | wx.EXPAND, 0) self.SetSizer(mplsizer1) self.Layout() # end wxGlade def onFileOpen(self, event): # wxGlade: MplFrame.<event_handler> filename = wx.FileSelector() if filename: self.mpltextctrl.SetValue(filename) def onFileQuit(self, event): # wxGlade: MplFrame.<event_handler> # closes the window self.Close(True) def parse_file(self, event): # wxGlade: MplFrame.<event_handler> self.mplpanel.update_graph(self.mpltextctrl.GetValue())
class MainFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MainFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.menubar = wx.MenuBar() self.File = wx.Menu() self.Save = wx.MenuItem(self.File, wx.ID_SAVE, "&Save", "Have current figure", wx.ITEM_NORMAL) self.File.AppendItem(self.Save) self.Exit = wx.MenuItem(self.File, wx.ID_EXIT, "E&xit", "Terminate the program", wx.ITEM_NORMAL) self.File.AppendItem(self.Exit) self.menubar.Append(self.File, "&File") self.Options = wx.Menu() self.SetGrid = wx.MenuItem(self.Options, wx.ID_PROPERTIES, "Set grid", "Defined the size of the grid grid", wx.ITEM_NORMAL) self.Options.AppendItem(self.SetGrid) self.menubar.Append(self.Options, "&Options") self.Help = wx.Menu() self.About = wx.MenuItem(self.Help, wx.ID_ABOUT, "&About", "Information about this program", wx.ITEM_NORMAL) self.Help.AppendItem(self.About) self.menubar.Append(self.Help, "&Help") self.SetMenuBar(self.menubar) # Menu Bar end self.mplPanel = MplPanel(self, wx.ID_ANY) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_MENU, self.onSave, self.Save) self.Bind(wx.EVT_MENU, self.onExit, self.Exit) self.Bind(wx.EVT_MENU, self.onSetGrid, self.SetGrid) self.Bind(wx.EVT_MENU, self.onAbout, self.About) # end wxGlade def __set_properties(self): # begin wxGlade: MainFrame.__set_properties self.SetTitle("Main Window") self.SetSize((650, 490)) # end wxGlade def __do_layout(self): # begin wxGlade: MainFrame.__do_layout sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.mplPanel, 1, wx.EXPAND, 0) self.SetSizer(sizer) self.Layout() # end wxGlade def onAbout(self, event): # wxGlade: MainFrame.<event_handler> #Create a message dialog box dlg = wx.MessageDialog(self, "XRD MapGrid v0.1\nAuthor: Viktor Kopp", "XRD", wx.OK) dlg.ShowModal() dlg.Destroy() def onExit(self, event): # wxGlade: MainFrame.<event_handler> self.Close(True) def onSetGrid(self, event): # wxGlade: MainFrame.<event_handler> dialog = AxesGridDialog(self) if dialog.ShowModal() == wx.ID_OK: nr = int(dialog.scNbRows.GetValue()) nc = int(dialog.scNbColumns.GetValue()) self.mplPanel.set_grid(nr, nc) print "%s x %s grid has been defined" % (nr, nc) dialog.Destroy() def onSave(self, event): # wxGlade: MainFrame.<event_handler> if self.mplPanel.figure.get_axes():#if there is #base part base = "figure" #propose to save file with the same base as input file but with qfit extension dlg = wx.FileDialog(self, "Save image", cfg.USER_SAVE_DIR, base + '.eps', "*.*", wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) if dlg.ShowModal() == wx.ID_OK: #redefine save dir cfg.USER_SAVE_DIR = dlg.GetDirectory() # save content in the file path = dlg.GetPath() self.mplPanel.figure.savefig(path) else: #Create a message dialog box dlg = wx.MessageDialog(self, "Figure is empty", "Worning", wx.OK) dlg.ShowModal() dlg.Destroy()
class MainFrame(wx.Frame): def __init__(self, *args, **kwds): self.dirname = "" self.filename = "" # begin wxGlade: MainFrame.__init__ kwds["style"] = ( wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.MAXIMIZE | wx.MAXIMIZE_BOX | wx.SYSTEM_MENU | wx.RESIZE_BORDER | wx.CLIP_CHILDREN ) wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.menubar = wx.MenuBar() wxglade_tmp_menu = wx.Menu() self.Open = wx.MenuItem(wxglade_tmp_menu, wx.ID_OPEN, "&Open", "Open a file to load", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Open) self.Save = wx.MenuItem(wxglade_tmp_menu, wx.ID_SAVE, "&Save", "Save data file", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Save) self.Exit = wx.MenuItem(wxglade_tmp_menu, wx.ID_EXIT, "E&xit", "Terminate the program", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Exit) self.menubar.Append(wxglade_tmp_menu, "File") wxglade_tmp_menu = wx.Menu() self.Preferences = wx.MenuItem( wxglade_tmp_menu, wx.ID_PREFERENCES, "&Preferences", "Figure and axes preferences", wx.ITEM_NORMAL ) wxglade_tmp_menu.AppendItem(self.Preferences) self.menubar.Append(wxglade_tmp_menu, "Settings") wxglade_tmp_menu = wx.Menu() self.About = wx.MenuItem( wxglade_tmp_menu, wx.ID_ABOUT, "&About", "Information about this program", wx.ITEM_NORMAL ) wxglade_tmp_menu.AppendItem(self.About) self.menubar.Append(wxglade_tmp_menu, "Help") self.SetMenuBar(self.menubar) # Menu Bar end self.statusbar = self.CreateStatusBar(1, 0) self.mplPanel = MplPanel(self, wx.ID_ANY) self.stgPanel = StgPanel(self, wx.ID_ANY) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_MENU, self.OnOpen, self.Open) self.Bind(wx.EVT_MENU, self.OnSave, self.Save) self.Bind(wx.EVT_MENU, self.OnExit, self.Exit) self.Bind(wx.EVT_MENU, self.onPreferences, self.Preferences) self.Bind(wx.EVT_MENU, self.OnAbout, self.About) # end wxGlade def __set_properties(self): # begin wxGlade: MainFrame.__set_properties self.SetTitle("RSM Handler") self.statusbar.SetStatusWidths([-1]) # statusbar fields statusbar_fields = ["frame_1_statusbar"] for i in range(len(statusbar_fields)): self.statusbar.SetStatusText(statusbar_fields[i], i) # end wxGlade def __do_layout(self): # begin wxGlade: MainFrame.__do_layout sizer_1 = wx.BoxSizer(wx.HORIZONTAL) sizer_1.Add(self.mplPanel, 2, wx.ALL | wx.EXPAND, 5) sizer_1.Add(self.stgPanel, 1, wx.ALL | wx.EXPAND, 5) self.SetSizer(sizer_1) sizer_1.Fit(self) self.Layout() # end wxGlade def OnOpen(self, event): # wxGlade: MainFrame.<event_handler> """Open a file""" dlg = wx.FileDialog(self, "Choose a file", "", "/home/dreamcatcher/Research/Como/XRD/9417/", "*.xrdml", wx.OPEN) if dlg.ShowModal() == wx.ID_OK: self.filename = dlg.GetFilename() self.dirname = dlg.GetDirectory() self.SetStatusText(self.filename) # read xrdml datafile om, tt, psd = xu.io.getxrdml_map(os.path.join(self.dirname + os.sep, self.filename)) # setup mplPanel self.mplPanel.setup(om, tt, psd) # selector should be set to angular mode self.stgPanel.cbMode.SetSelection(0) # draw the map in angular mode self.stgPanel.updateFigure(0) self.stgPanel.updateControls(0) # destroy dialog dlg.Destroy() def OnExit(self, event): # wxGlade: MainFrame.<event_handler> self.Close(True) def OnAbout(self, event): # wxGlade: MainFrame.<event_handler> # Create a message dialog box dlg = wx.MessageDialog(self, "RSM Handler v0.7", "XRD", wx.OK) dlg.ShowModal() dlg.Destroy() def OnSave(self, event): # wxGlade: MainFrame.<event_handler> if self.filename: # split file into base part and extension part base, ext = os.path.splitext(self.filename) # propose to save file with the same base as input file but with qfit extension dlg = wx.FileDialog( self, "Save QFit file", self.dirname, base + ".qfit", "*.*", wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT ) if dlg.ShowModal() == wx.ID_OK: # save content in the file # this can be done with wxPython output streams: path = dlg.GetPath() self.saveFitDataFile(path) else: # Create a message dialog box dlg = wx.MessageDialog(self, "There is no file loaded.", "Error", wx.OK) dlg.ShowModal() dlg.Destroy() def saveFitDataFile(self, path): fout = open(path, "w") fout.write("#File created by RSM Handler from an experimental data\n") fout.write("#can be used for numerical fitting\n") fout.write("#[qx]\t[qz]\t[intensity]\n") # q data points qx, qz = self.mplPanel.get_q() # corresponding intensities intensity = self.mplPanel.get_intensity() # save data only on predefined limits qxmin, qxmax, qzmin, qzmax = self.mplPanel.getLimits() for i in range(len(intensity)): # save data only in predefined ranges if qx[i] > qxmin and qx[i] < qxmax and qz[i] > qzmin and qz[i] < qzmax: fout.write("{0}\t{1}\t{2}\n".format(qx[i], qz[i], intensity[i])) fout.close() def saveGpltDataFile(self, path, mode): pass def onPreferences(self, event): # wxGlade: MainFrame.<event_handler> dlg = PreferencesDialog(self) dlg.UpdateControls(self.mplPanel.figure) if dlg.ShowModal() == wx.ID_OK: dlg.UpdateFigure(self.mplPanel.figure)