def __init__(self, parent: wx.Frame): wx.Panel.__init__(self, parent) parent.CreateStatusBar() menu = wx.Menu() menu.Append(wx.ID_ABORT, 'About', 'wxPython GUI') menu.AppendSeparator() menu.Append(wx.ID_EXIT, 'Exit', 'Exit the GUI') menu_bar = wx.MenuBar() menu_bar.Append(menu, 'File') parent.SetMenuBar(menu_bar) button = wx.Button(self, label='Print', pos=(0, 60)) self.Bind(wx.EVT_BUTTON, self.print_button, button) self.text_box = wx.TextCtrl(self, size=(280, 50), style=wx.TE_MULTILINE)
class BoaApp(wx.App): def OnInit(self): self.log = Log() wx.InitAllImageHandlers() #self.main = wxFrame1.create(None) #self.main = TestWindow(parent=self, log=None, frame=None) self.andyapptitle = 'PyNsource GUI - Python Reverse Engineering Tool - Python Code into UML.' self.frame = Frame(None, -1, self.andyapptitle, pos=(50,50), size=(0,0), style=wx.NO_FULL_REPAINT_ON_RESIZE|wx.DEFAULT_FRAME_STYLE) self.frame.CreateStatusBar() menuBar = wx.MenuBar() menu = wx.Menu() menu2 = wx.Menu() menu3 = wx.Menu() menu4 = wx.Menu() menu.Append(103, "File &Import...\tCtrl-I", "Import Python Source Files") wx.EVT_MENU(self, 103, self.FileImport) menu.Append(1055, "File Import &Recursive...", "Import Python Source Files PLUS all modules imported by your sources - WARNING - may generate lots of UML!!") wx.EVT_MENU(self, 1055, self.RecursivePathImport) menu.AppendSeparator() #menu.Append(102, "File &New\tCtrl-N", "New") menu.Append(102, "&Clear\tCtrl-N", "Clear Diagram") wx.EVT_MENU(self, 102, self.FileNew) menu.AppendSeparator() #menu.Append(104, "File &Open\tCtrl-O", "Open") #wx.EVT_MENU(self, 104, self.FileOpen) #menu.Append(105, "File &Save\tCtrl-S", "Save") #wx.EVT_MENU(self, 105, self.FileSave) #menu.AppendSeparator() menu.Append(1056, "File &Print / Preview...\tCtrl-P", "Print") wx.EVT_MENU(self, 1056, self.FilePrint) menu.AppendSeparator() menu.Append(101, "E&xit\tAlt-X", "Exit demo") wx.EVT_MENU(self, 101, self.OnButton) # ----------- menu2.Append(122, "&Delete Class", "Delete Node") wx.EVT_MENU(self, 122, self.OnDeleteNode) #menu2.AppendSeparator() menu4.Append(123, "&Layout UML", "Layout UML") wx.EVT_MENU(self, 123, self.OnLayout) menu4.Append(124, "&Refresh", "Refresh") wx.EVT_MENU(self, 124, self.OnRefresh) # ----------- menu3.Append(301, "&Help...", "Help") wx.EVT_MENU(self, 301, self.OnHelp) menu3.Append(302, "&Visit PyNSource Website...", "PyNSource Website") wx.EVT_MENU(self, 302, self.OnVisitWebsite) menu3.AppendSeparator() menu3.Append(303, "&Check for Updates...", "Check for Updates") wx.EVT_MENU(self, 303, self.OnCheckForUpdates) menu3.Append(106, "&About...", "About...") wx.EVT_MENU(self, 106, self.OnAbout) # ----------- menuBar.Append(menu, "&File") menuBar.Append(menu2, "&Edit") menuBar.Append(menu4, "&Layout") menuBar.Append(menu3, "&Help") self.frame.SetMenuBar(menuBar) self.frame.Show(True) wx.EVT_CLOSE(self.frame, self.OnCloseFrame) #win = self.demoModule.runTest(frame, frame, Log()) #win = runTest(frame, frame, ) self.win = TestWindow(self.frame, Log(), self.frame) self.win.secretredrawmethod = self.OnRefresh # Hack so can do a high level refresh screen after a delete node event. # a window will be returned if the demo does not create # its own top-level window if self.win: # so set the frame to a good size for showing stuff self.frame.SetSize(config.WINDOW_SIZE) self.win.SetFocus() else: # otherwise the demo made its own frame, so just put a # button in this one if hasattr(self.frame, 'otherWin'): b = wx.Button(self.frame, -1, " Exit ") self.frame.SetSize((200, 100)) wx.EVT_BUTTON(self.frame, b.GetId(), self.OnButton) else: # It was probably a dialog or something that is already # gone, so we're done. self.frame.Destroy() return True self.SetTopWindow(self.frame) #self.popupmenu = wx.Menu() # Creating a menu #item = self.popupmenu.Append(-1, "AAAAAAA") ##self.frame.Bind(wx.EVT_MENU, self.OnPopupItemSelected, item) ##self.win.Bind(wx.EVT_CONTEXT_MENU, self.OnShowPopup) ##self.frame(wx.EVT_CONTEXT_MENU, self.OnShowPopup) #self.frame.PopupMenu(self.popupmenu, wx.Point(10,110)) #self.main.Show() #self.SetTopWindow(self.main) return True #def OnShowPopup(self, event): # print "AAAAAAAAAAAAAAAAAAAA" # pos = event.GetPosition() # pos = self.panel.ScreenToClient(pos) # self.panel.PopupMenu(self.popupmenu, pos) #def OnPopupItemSelected(self, event): # item = self.popupmenu.FindItemById(event.GetId()) # text = item.GetText() # wx.MessageBox("You selected item '%s'" % text) def RecursivePathImport(self,event=None): dlg = wx.FileDialog(parent=self.frame, message="choose", defaultDir='.', defaultFile="", wildcard="*.py", style=wx.OPEN|wx.MULTIPLE, pos=wx.DefaultPosition) if dlg.ShowModal() == wx.ID_OK: filenames = dlg.GetPaths() # dlg.GetFilename() print 'Importing...' wx.BeginBusyCursor(cursor=wx.HOURGLASS_CURSOR) # self.fileloadhandler(filename) print filenames self.fileList = [] self.DoRecursivePathImport( os.path.split(filenames[0])[0] ) print self.fileList self.win.Go(files=self.fileList) self._HackToForceTheScrollbarToShowUp() wx.EndBusyCursor() print 'Import - Done.' def _HackToForceTheScrollbarToShowUp(self): """ sizeX,sizeY = config.WINDOW_SIZE self.frame.SetSize((sizeX+1,sizeY+1)) self.frame.SetSize((sizeX,sizeY)) """ # Actual size of the window oldSize = self.frame.GetSize() # Set the window size to something different self.frame.SetSize((oldSize[0]+1,oldSize[1]+1)) # Return the size to what it was self.frame.SetSize(oldSize) def DoRecursivePathImport(self,dir): if( os.path.split(dir)[1] == "CVS"): #print dir,os.path.split(dir)[0] return for f in os.listdir(dir): pathname = os.path.join( dir, f ) mode = os.stat(pathname)[stat.ST_MODE] if stat.S_ISDIR(mode): # It's a directory, ignore it pass # It's a directory, recurse into it #self.RecursivePathImport(pathname) elif stat.S_ISREG(mode): # It's a file if( os.path.splitext(f)[1] != ".pyc" and f != "__init__.py" ): self.fileList.append( os.path.join(dir,f) ) def FileImport(self, event): dlg = wx.FileDialog(parent=self.frame, message="choose", defaultDir='.', defaultFile="", wildcard="*.py", style=wx.OPEN|wx.MULTIPLE, pos=wx.DefaultPosition) if dlg.ShowModal() == wx.ID_OK: filenames = dlg.GetPaths() # dlg.GetFilename() print 'Importing...' wx.BeginBusyCursor(cursor=wx.HOURGLASS_CURSOR) # self.fileloadhandler(filename) print filenames self.win.Go(files=filenames) self.win.redraw2() #ADDED AT MAC PORT TIME wx.EndBusyCursor() print 'Import - Done.' self._HackToForceTheScrollbarToShowUp() def FileNew(self, event): self.win.Clear() def FileOpen(self, event): self.MessageBox("Sorry, FileOpen not implemented yet.") self.win.diagram.LoadFile('c:\\try\\testUml.txt') return """ dlg = wxFileDialog(parent=self.frame, message="choose", defaultDir='.', defaultFile="", wildcard="*.py", style=wxOPEN|wxMULTIPLE, pos=wxDefaultPosition) if dlg.ShowModal() == wxID_OK: filenames = dlg.GetPaths() # dlg.GetFilename() print 'Importing...' wxBeginBusyCursor(cursor=wxHOURGLASS_CURSOR) # self.fileloadhandler(filename) print filenames wxEndBusyCursor() print 'Import - Done.' """ def FileSave(self, event): self.MessageBox("Sorry, FileSave not implemented yet.") return self.win.diagram.SaveFile('c:\\try\\testUml.txt') """ dlg = wxFileDialog(parent=self.frame, message="choose", defaultDir='.', defaultFile="", wildcard="*.py", style=wxOPEN|wxMULTIPLE, pos=wxDefaultPosition) if dlg.ShowModal() == wxID_OK: filenames = dlg.GetPaths() # dlg.GetFilename() print 'Importing...' wxBeginBusyCursor(cursor=wxHOURGLASS_CURSOR) # self.fileloadhandler(filename) print filenames wxEndBusyCursor() print 'Import - Done.' """ def FilePrint(self, event): from printframework import MyPrintout self.printData = wx.PrintData() self.printData.SetPaperId(wx.PAPER_LETTER) self.box = wx.BoxSizer(wx.VERTICAL) self.canvas = self.win.GetDiagram().GetCanvas() #self.log.WriteText("OnPrintPreview\n") printout = MyPrintout(self.canvas, self.log) printout2 = MyPrintout(self.canvas, self.log) self.preview = wx.PrintPreview(printout, printout2, self.printData) if not self.preview.Ok(): self.log.WriteText("Houston, we have a problem...\n") return frame = wx.PreviewFrame(self.preview, self.frame, "This is a print preview") frame.Initialize() frame.SetPosition(self.frame.GetPosition()) frame.SetSize(self.frame.GetSize()) frame.Show(True) def OnAbout(self, event): self.MessageBox(aboutmsg.strip()) def OnVisitWebsite(self, event): import webbrowser webbrowser.open(WEB_PYNSOURCE_HOME_URL) def OnCheckForUpdates(self, event): import urllib2 s = urllib2.urlopen(WEB_VERSION_CHECK_URL).read() s = s.replace("\r", "") info = eval(s) ver = info["latest_version"] if ver > APP_VERSION: msg = """ There is a newer version of PyNSource GUI available: %s %s Do you wish to visit the download page now? """ % (ver, info["latest_announcement"].strip()) retCode = wx.MessageBox(msg.strip(), "Update Check", wx.YES_NO | wx.ICON_QUESTION) # MessageBox simpler than MessageDialog if (retCode == wx.YES): import webbrowser webbrowser.open(info["download_url"]) else: self.MessageBox("You already have the latest version: %s" % APP_VERSION) def OnHelp(self, event): self.MessageBox(""" PyNSource Gui Help: Import a python file and it will be reverse engineered and represented as UML. Import multiple files by multiple selecting files (hold ctrl and/or shift) in the file open dialog. Import recursively at your own peril - too many classes will clutter you diagrams. Layout is a bit dodgy so arrange your layout a little and then do a screen grab (using your favourite screen grabbing tool) or print. You cannot add new classes in the GUI, this is just a reverse engineering tool. You can however delete uncessesary classes by right clicking on the node. """.strip()) def OnDeleteNode(self, event): for shape in self.win.GetDiagram().GetShapeList(): if shape.Selected(): self.MessageBox("To delete a node, right click on it with your mouse (delete via main menu functionality coming soon) %d" % shape.GetX()) def OnLayout(self, event): if self.win.GetDiagram().GetCount() == 0: self.MessageBox("Nothing to layout. Import a python source file first.") return self.win.ArrangeShapes() self.win.redraw() self._HackToForceTheScrollbarToShowUp() def OnRefresh(self, event): self.win.redraw2() self._HackToForceTheScrollbarToShowUp() # this is just as necessary to get the screen to refresh. def MessageBox(self, msg): dlg = wx.MessageDialog(self.frame, msg, 'About', wx.OK | wx.ICON_INFORMATION) #wxYES_NO | wxNO_DEFAULT | wxCANCEL | wxICON_INFORMATION) dlg.ShowModal() dlg.Destroy() def OnButton(self, evt): self.frame.Close(True) def OnCloseFrame(self, evt): if hasattr(self, "window") and hasattr(self.window, "ShutdownDemo"): self.win.ShutdownDemo() evt.Skip()