def OnTreeRightClick(self, evt): item, _flags = self.HitTest(evt.GetPosition()) self.currentNode = None self.currentItem = item frame = self.GetFrame() if item: if item != self.GetSelection(): self.SelectItem(item) self.currentNode = self.GetNode(item) if self.currentNode: cm = Menu(frame) registerproc = self.currentNode.moduleinfo( )['serverclass'].Register cm.Add( registerproc, xlt("Register new %s") % self.currentNode.moduleinfo()['name']) cm.Add(self.OnEdit, xlt("Edit registration")) cm.Add(self.OnUnregister, xlt("Remove registration")) if not self.currentNode.settings.get('group'): cm.Add(self.OnAddGroup, xlt("New group")) else: cm = self.GetFrame().registermenu.Dup() if item: menuItem = cm.Add(self.OnDelGroup, xlt("Remove group")) if self.GetChildrenCount(item) > 0: cm.Enable(menuItem, False) else: cm.Add(self.OnAddGroup, xlt("New group")) cm.Popup(evt)
def OnGridRightClick(self, evt): property = self.grid.GetSelection() if property: oid = property.GetName() if oid: name = self.dialog.attribs[oid].name cm = Menu(self.dialog) cm.Add(self.OnDelAttrs, xlt("Remove %s") % name, xlt("Remove attribute \"%s\"") % name) cm.Popup(evt)
def OnLabelRightClick(self, evt): if evt.Row >= 0: self.SelectRow(evt.Row, evt.ControlDown()) rows=self.GetAllSelectedRows() try: rows.remove(len(self.table.rows)) except: pass if self.tableSpecs.keyCols and rows: cm=Menu(self.GetParent()) if len(rows) > 1: cm.Add(self.OnDeleteRows, xlt("Delete rows")) else: cm.Add(self.OnDeleteRows, xlt("Delete row")) cm.Popup(evt)
def OnCellRightClick(self, evt): self.GoToCell(evt.Row, evt.Col) self.cmRow=evt.Row self.cmCol=evt.Col colname=self.table.colNames[evt.Col] cd=self.tableSpecs.colSpecs.get(colname) cm=Menu(self.GetParent()) if cd: item=cm.Add(self.OnSetNull, xlt("Set NULL")) if cd.notNull: cm.Enable(item, False) cm.Popup(evt)
def OnRightClickAcl(self, evt): cm = Menu(self) cm.Add(self.OnAddAcl, xlt("Add"), xlt("Add user with rights")) sel = self['ACL'].GetSelection() if len(sel) == 1: cm.Add(self.OnEditAcl, xlt("Edit"), xlt("Edit user's acl")) if len(sel): cm.Add(self.OnDelAcl, xlt("Remove"), xlt("Remove user acl")) cm.Popup(evt)
def OnLoglineRightClick(self, evt): cm = Menu(adm.GetCurrentFrame(self)) sel = self.control.GetSelection() if not sel: sel = [evt.GetIndex()] self.control.SetSelection(sel) cm.Add(self.OnCopy, xlt("Copy"), xlt("Copy line to clipboard")) q = self.log[sel[0]][self.getIndex('query')] if q: cm.Add(self.OnQuery, xlt("Query"), xlt("Execute query")) cm.Add(self.OnLoglinesDclick, xlt("Details"), xlt("Show details")) cm.Popup(evt)
def OnItemRightClick(self, evt): if self.node: if hasattr(evt, 'GetIndex'): index = evt.GetIndex() else: index = -1 page = self.pages[self.GetSelection()] if not hasattr(evt, 'page'): evt.page = page if hasattr(page, 'menus'): cm = Menu(self) menus = page.menus for cls in menus: if hasattr(cls, "CheckAvailableOn" ) and not cls.CheckAvailableOn(page): continue cls.OnExecute._classname_ = cls.__name__ item = cm.Add(cls.OnExecute, cls.name, cls.help) if hasattr(cls, "CheckEnabled") and not cls.CheckEnabled(page): cm.Enable(item, False) if cm.GetMenuItemCount(): cm.Popup(evt) elif hasattr(self.node, "OnItemRightClick"): evt.currentPage = page self.node.OnItemRightClick(evt) elif hasattr(self.node, "GetItemNode"): node = self.node.GetItemNode(evt.page, index) if node: node.RefreshVolatile() node.GetProperties() w = adm.GetCurrentFrame(self) cm = w.GetContextMenu(node) w.currentNode = node cm.Popup(evt) w.currentNode = None
def __init__(self, parentWin, node, params={}): SqlFrame.__init__(self, parentWin, xlt("Query Tool"), "SqlQuery") self.server=node.GetServer() self.application="%s Query Tool" % adm.appTitle snippet_table=self.server.info.get('snippet_table') if self.server.adminspace and snippet_table: self.snippet_table="%s.%s" % (quoteIdent(self.server.adminspace), quoteIdent(snippet_table)) else: self.snippet_table=None dbName=params.get('dbname') if not dbName: if hasattr(node, "GetDatabase"): dbName=node.GetDatabase().name else: dbName=self.server.maintDb self.worker=None self.sqlChanged=False self.previousCols=[] self.fileManager=FileManager(self, adm.config) toolbar=self.toolbar toolbar.Add(self.OnFileOpen, xlt("Load from file"),"file_open") toolbar.Add(self.OnFileSave, xlt("Save to file"), "file_save") toolbar.Add(self.OnToggleSnippets, xlt("Show snippets browser"), "snippets") toolbar.AddSeparator() toolbar.Add(self.OnCopy, xlt("Copy"), "clip_copy") toolbar.Add(self.OnCut, xlt("Cut"), "clip_cut") toolbar.Add(self.OnPaste, xlt("Paste"), "clip_paste") toolbar.Add(self.OnClear, xlt("Clear"), "edit_clear") toolbar.AddSeparator() toolbar.Add(self.OnUndo, xlt("Undo"), "edit_undo") toolbar.Add(self.OnRedo, xlt("Redo"), "edit_redo") # toolbar.Add((self.OnFind, xlt("Find"), "edit_find") toolbar.AddSeparator() cbClass=xmlres.getControlClass("whComboBox") allDbs=self.server.GetConnectableDbs() size=max(map(lambda db: toolbar.GetTextExtent(db)[0], allDbs)) BUTTONOFFS=30 self.databases=cbClass(toolbar, size=(size+BUTTONOFFS, -1)) self.databases.Append(allDbs) self.databases.Append(xlt("Connect...")) self.databases.SetStringSelection(dbName) self.OnChangeDatabase() self.databases.Bind(wx.EVT_COMBOBOX, self.OnChangeDatabase) toolbar.Add(self.OnExecuteQuery, xlt("Execute Query"), "query_execute") toolbar.Add(self.OnExplainQuery, xlt("Explain Query"), "query_explain") toolbar.Add(self.OnCancelQuery, xlt("Execute Query"), "query_cancel") toolbar.AddControl(self.databases) toolbar.AddSeparator() toolbar.Add(self.OnAddSnippet, xlt("Add snippet"), "snippet_add") toolbar.Add(self.OnReplaceSnippet, xlt("Replace snippet"), "snippet_replace") toolbar.Realize() menubar=wx.MenuBar() self.filemenu=menu=Menu(self) menu.Add(self.OnFileOpen, xlt("&Open"), xlt("Open query file")) menu.AppendMenu(-1, xlt("Open recent..."), self.fileManager.GetRecentFilesMenu()) menu.Add(self.OnFileInsert, xlt("&Insert"), xlt("Insert query file")) menu.Add(self.OnFileSave, xlt("&Save"), xlt("Save current file")) menu.Add(self.OnFileSaveAs, xlt("Save &as.."), xlt("Save file under new name")) menu.AppendSeparator() # menu.Add(xlt("Preferences"), xlt("Preferences"), self.OnPreferences) menu.Add(self.OnClose, xlt("Quit SQL"), xlt("Quit Sql")) menubar.Append(menu, xlt("&File")) self.viewmenu=menu=Menu(self) menu.AddCheck(self.OnToggleSnippets, xlt("Snippets"), xlt("Show or hide snippet browser")) self.registerToggles(True, True) menubar.Append(self.viewmenu, xlt("&View")) self.editmenu=menu=Menu(self) menu.Add(self.OnUndo, xlt("&Undo"), xlt("Undo last action")) menu.Add(self.OnRedo, xlt("&Redo"), xlt("Redo last action")) # menu.Add(xlt("&Find"), xlt("Find string"), self.OnFind) menu.AppendSeparator() menu.Add(self.OnCut, xlt("Cu&t"), xlt("Cut selected text to clipboard")) menu.Add(self.OnCopy, xlt("&Copy"), xlt("Copy selected text to clipboard")) menu.Add(self.OnPaste, xlt("&Paste"), xlt("Paste text from clipboard")) menu.Add(self.OnClear, xlt("C&lear"), xlt("Clear editor")) menu.AppendSeparator() menu.Add(self.OnAddSnippet, xlt("Add snippet"), xlt("Add selected text to snippets")) menu.Add(self.OnReplaceSnippet, xlt("Modify snippet"), xlt("Replace snippet with selected text")) menubar.Append(menu, xlt("&Edit")) self.querymenu=menu=Menu(self) menu.Add(self.OnExecuteQuery, xlt("Execute"), xlt("Execute query")) menu.Add(self.OnExplainQuery, xlt("Explain"), xlt("Explain query")) menu.Add(self.OnCancelQuery, xlt("Cancel"), xlt("Cancel query execution")) menubar.Append(menu, xlt("&Query")) self.helpmenu=menu=Menu(self) menu.Add(self.OnHelp, xlt("Help"), xlt("Show help"), wx.ID_HELP) menubar.Append(menu, xlt("&Help")) self.EnableMenu(self.querymenu, self.OnCancelQuery, False) self.SetMenuBar(menubar) ah=AcceleratorHelper(self) ah.Add(wx.ACCEL_CTRL, 'X', self.OnCut) ah.Add(wx.ACCEL_CTRL, 'C', self.OnCopy) ah.Add(wx.ACCEL_CTRL, 'V', self.OnPaste) ah.Add(wx.ACCEL_NORMAL,wx.WXK_F5, self.OnExecuteQuery) ah.Add(wx.ACCEL_NORMAL,wx.WXK_F7, self.OnExplainQuery) ah.Add(wx.ACCEL_ALT,wx.WXK_PAUSE, self.OnCancelQuery) ah.Realize() self.editor=SqlEditor(self) self.editor.SetAcceleratorTable(ah.GetTable()) self.editor.BindProcs(self.OnChangeStc, self.OnStatusPos) self.manager.AddPane(self.editor, wx.aui.AuiPaneInfo().Top().PaneBorder().Resizable().MinSize((200,100)).BestSize((400,200)).CloseButton(False) \ .Name("sqlQuery").Caption(xlt("SQL Query"))) self.snippets=SnippetTree(self, self.server, self.editor) self.manager.AddPane(self.snippets, wx.aui.AuiPaneInfo().Left().Top().PaneBorder().Resizable().MinSize((100,100)).BestSize((100,100)).CloseButton(True) \ .Name("snippets").Caption(xlt("SQL Snippets"))) if not self.snippet_table: self.manager.GetPane("snippets").Show(False) self.output=wx.Notebook(self) self.result=SqlResultGrid(self.output) self.explain = ExplainCanvas(self.output) self.explain.Hide() font=self.editor.GetFont() self.messages=wx.TextCtrl(self.output, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP) self.msgHistory=wx.TextCtrl(self.output, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP) self.messages.SetFont(font) self.msgHistory.SetFont(font) self.output.AddPage(self.result, xlt("Output")) self.output.AddPage(self.messages, xlt("Messages")) self.output.AddPage(self.msgHistory, xlt("History")) self.manager.AddPane(self.output, wx.aui.AuiPaneInfo().Center().MinSize((200,100)).BestSize((400,200)).CloseButton(False) \ .Name("Result").Caption(xlt("Result")).CaptionVisible(False)) self.manager.Bind(wx.aui.EVT_AUI_PANE_CLOSE, self.OnAuiCloseEvent) self.SetStatus(xlt("ready")) self.restorePerspective() self.manager.GetPane("Result").Show() self.manager.Update() self.viewmenu.Check(self.OnToggleSnippets, self.manager.GetPane("snippets").IsShown()) self.OnToggleToolBar() self.OnToggleStatusBar() self.updateMenu() query=params.get('query') if query: self.editor.SetText(query) pos=params.get('errline', -1) if pos: line=self.editor.LineFromPosition(int(pos)) self.editor.MarkerSet(line) msg=params.get('message') if msg: self.messages.AppendText(msg) hint=params.get('hint') if hint: self.messages.AppendText("\n\nHINT:\n") self.messages.AppendText(hint) self.output.SetSelection(1) self.Show() self.editor.SetFocus()
def __init__(self, parentWin, connectionPool, name, server): self.tableSpecs=TableSpecs(connectionPool, name) self.connectionPool=connectionPool self.worker=None self.output=None self.server=server querypreset_table=self.server.info.get('querypreset_table') if self.server.adminspace and querypreset_table: self.querypreset_table="%s.%s" % (quoteIdent(self.server.adminspace), quoteIdent(querypreset_table)) else: self.querypreset_table=None title=xlt("%(appTitle)s Data Tool - %(tableName)s") % { 'appTitle': adm.appTitle, 'tableName': name} SqlFrame.__init__(self, parentWin, title, "SqlData") toolbar=self.GetToolBar() toolbar.Add(self.OnRefresh, xlt("Refresh"), "data_refresh") toolbar.Add(self.OnCancelRefresh, xlt("Cancel refresh"), "query_cancel") toolbar.Add(self.OnSave, xlt("Save data"), "data_save") toolbar.Add(self.OnToggleFilter, xlt("Show filter window"), "filter") toolbar.AddSeparator() toolbar.Add(self.OnCopy, xlt("Copy"), "clip_copy") toolbar.Add(self.OnCut, xlt("Cut"), "clip_cut") toolbar.Add(self.OnPaste, xlt("Paste"), "clip_paste") toolbar.Add(self.OnUndo, xlt("Undo"), "edit_undo") toolbar.AddSeparator() toolbar.Add(self.OnDelete, xlt("Delete"), "delete") menubar=wx.MenuBar() self.filemenu=menu=Menu(self) menu.Add(self.OnClose, xlt("Quit tool"), xlt("Quit data tool")) menubar.Append(menu, xlt("&File")) self.datamenu=menu=Menu(self) menu.Add(self.OnRefresh, xlt("Refresh"), xlt("Refresh data")) menu.Add(self.OnCancelRefresh, xlt("Cancel"), xlt("Cancel refresh")) menu.Add(self.OnSave, xlt("Save"), xlt("Save data")) menu.Add(self.OnDelete, xlt("Delete"), xlt("Delete row(s)")) menubar.Append(menu, xlt("&Data")) self.viewmenu=menu=Menu(self) menu.AddCheck(self.OnToggleFilter, xlt("Filter"), xlt("Show or hide filter window")) self.registerToggles(True, True) menubar.Append(menu, xlt("&View")) self.editmenu=menu=Menu(self) menu.Add(self.OnCut, xlt("Cu&t"), xlt("Cut selected data to clipboard")) menu.Add(self.OnCopy, xlt("&Copy"), xlt("Copy selected data to clipboard")) menu.Add(self.OnPaste, xlt("&Paste"), xlt("Paste data from clipboard")) menu.Add(self.OnUndo, xlt("&Undo"), xlt("discard last editing")) menubar.Append(menu, xlt("&Edit")) self.helpmenu=menu=Menu(self) menu.Add(self.OnHelp, xlt("Help"), xlt("Show help"), wx.ID_HELP) menubar.Append(menu, xlt("&Help")) self.EnableMenu(self.datamenu, self.OnCancelRefresh, False) self.SetMenuBar(menubar) toolbar.Realize() ah=AcceleratorHelper(self) ah.Add(wx.ACCEL_CTRL, 'X', self.OnCut) ah.Add(wx.ACCEL_CTRL, 'C', self.OnCopy) ah.Add(wx.ACCEL_CTRL, 'V', self.OnPaste) ah.Add(wx.ACCEL_CTRL, 'S', self.OnSave) ah.Add(wx.ACCEL_NORMAL,wx.WXK_F5, self.OnRefresh) ah.Add(wx.ACCEL_ALT,wx.WXK_PAUSE, self.OnCancelRefresh) ah.Realize() self.notebook=wx.Notebook(self) self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnCheck) self.filter=FilterPanel(self, self.notebook) self.notebook.AddPage(self.filter, xlt("Filter, Order, Limit")) self.editor=SqlEditor(self.notebook) self.editor.SetAcceleratorTable(ah.GetTable()) self.notebook.AddPage(self.editor, xlt("Manual SQL")) self.manager.AddPane(self.notebook, wx.aui.AuiPaneInfo().Top().PaneBorder().Resizable().MinSize((200,200)).BestSize((400,200)).CloseButton(True) \ .Name("filter").Caption(xlt("SQL query parameter")).Hide()) self.output = SqlEditGrid(self, self.tableSpecs) self.manager.AddPane(self.output, wx.aui.AuiPaneInfo().Center().MinSize((200,100)).BestSize((400,200)).CloseButton(False) \ .Name("Edit Data").Caption(xlt("Edit Data")).CaptionVisible(False)) self.restorePerspective() self.manager.GetPane("Edit data").Show() self.manager.Update() self.manager.Bind(wx.aui.EVT_AUI_PANE_CLOSE, self.OnAuiCloseEvent) self.viewmenu.Check(self.OnToggleFilter, self.manager.GetPane("filter").IsShown()) self.OnToggleToolBar() self.OnToggleStatusBar() self.updateMenu() self.filter.Go(self.tableSpecs) if not self.editor.GetText(): # otherwise set from default preset self.editor.SetText("/*\n%s\n*/\n\n%s" % (xlt( "Caution: Don't mess with table and column names!\nYou may experience unwanted behaviour or data loss."), self.filter.GetQuery()))
def GetContextMenu(self, node): contextMenu=Menu(self) if not len(node.properties): node.GetProperties() newcls=self.getNewClass(node) newmenu=Menu(self) if newcls: newmenu.Add(newcls.New, xlt("New %s") % newcls.shortname, xlt("Create new %s") % newcls.typename) morenew=node.nodeinfo().get('new', []) if isinstance(morenew, list): morenew=list(morenew) # copy else: morenew=[morenew] children=node.nodeinfo().get('children', []) for child in children: childnodeinfo=node.nodeinfo(child) childclass=childnodeinfo['class'] if childclass not in morenew: morenew.append(childclass) childnew=childnodeinfo.get('new', []) if not isinstance(childnew, list): childnew=[childnew] for childclass in childnew: if childclass not in morenew: morenew.append(childclass) for cls in morenew: if cls == newcls: continue if hasattr(cls, "New"): newmenu.Add(cls.New, xlt("New %s") % cls.shortname, xlt("Create new %s") % cls.typename) contextMenu.AppendOneMenu(newmenu, xlt("New Object"), xlt("Creates a new object")) if hasattr(node, "Delete"): if not hasattr(node, "deleteDisable") or not node.deleteDisable: contextMenu.Add(self.OnDelete, xlt("Delete %s") % node.shortname, xlt("Delete %s %s") % (node.typename,node.name)) if hasattr(node, "Disconnect"): contextMenu.Add(self.OnDisconnect, xlt("Disconnect %s") % node.name, xlt("Disconnect %s \"%s\"") % (node.typename,node.name)) if contextMenu.GetMenuItemCount(): contextMenu.AppendSeparator() contextMenu.Add(self.OnRefresh, xlt("Refresh"), xlt("Refresh %s") % node.typename) contextMenu.Add(self.OnDetach, xlt("Detach view"), xlt("Show %s in detached window") % node.typename) needSeparator=True for mi in node.menuinfos(): if self.menuAvailableOnNode(mi, node): if needSeparator: contextMenu.AppendSeparator() needSeparator=False cls=mi['class'] item=contextMenu.Add(cls.OnExecute, cls.name, cls.help) if hasattr(cls, "CheckEnabled") and not cls.CheckEnabled(node): contextMenu.Enable(item, False) if hasattr(node, "Edit"): contextMenu.AppendSeparator() contextMenu.Add(self.OnEdit, xlt("Properties"), xlt("Edit properties of %s") % node.typename) return contextMenu
def __init__(self, parentWin, name, args=None, title=None): if not title: title=name style=wx.MAXIMIZE_BOX|wx.RESIZE_BORDER|wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX adm.Frame.__init__(self, parentWin, title, style, (600,400), None) self.SetIcon(name) self.name=name self.lastNode=None self.appArgs=args self.manager=wx.aui.AuiManager(self) self.manager.SetFlags(wx.aui.AUI_MGR_ALLOW_FLOATING|wx.aui.AUI_MGR_TRANSPARENT_HINT | \ wx.aui.AUI_MGR_HINT_FADE| wx.aui.AUI_MGR_TRANSPARENT_DRAG) self.toolbar=ToolBar(self, 32); self.toolbar.Add(self.OnShowServers, xlt("Show registered servers"), "connect") self.toolbar.Add(self.OnDetach, xlt("Detach view"), "detach") self.toolbar.Add(self.OnRefresh, xlt("Refresh"), "refresh") self.toolbar.AddSeparator() self.toolbar.Add(self.OnEdit, xlt("Edit"), "edit") self.toolbar.Add(self.OnNew, xlt("New"), "new") self.toolbar.Add(self.OnDelete, xlt("Delete"), "delete") self.toolbar.Add(self.OnFindObject, xlt("Find"), "edit_find") self.toolbar.AddSeparator() self.standardToolsCount=self.toolbar.GetToolsCount() self.toolbar.Realize() menubar=wx.MenuBar() self.filemenu=menu=Menu(self) self.registermenu=Menu(self) for modulename in adm.modules.keys(): moduleinfo=adm.modules[modulename].moduleinfo registerproc=moduleinfo['serverclass'].Register self.registermenu.Add(registerproc, xlt("Register new %s") % moduleinfo['name']) self.filemenu.AppendOneMenu(self.registermenu, xlt("Register Server")) if wx.Platform != "__WXMAC__": menu.AppendSeparator() menu.Add(self.OnPreferences, xlt("Preferences"), xlt("Preferences"), wx.ID_PREFERENCES, adm.app.SetMacPreferencesMenuItemId) menu.Add(self.OnQuit, xlt("Quit"), xlt("Quit Admin4"), wx.ID_EXIT, adm.app.SetMacExitMenuItemId) menubar.Append(menu, xlt("&File")) self.viewmenu=menu=Menu(self) menu.Add(self.OnShowServers, xlt("Show Servers"), xlt("Show registered servers to connect")) menu.AddCheck(self.OnToggleTree, xlt("Tree"), xlt("Show or hide tree"), adm.config.Read("TreeShown", True, self)) self.registerToggles(True, True) menubar.Append(menu, xlt("&View")) self.editmenu=menu=Menu(self) menu.Add(self.OnEdit, xlt("Edit"), xlt("edit")) menu.Add(self.OnNew, xlt("New"), xlt("new object")) menu.Add(self.OnDelete, xlt("Delete"), xlt("delete object")) menu.Add(self.OnFindObject, xlt("Find"), xlt("find object")) menubar.Append(menu, xlt("&Edit")) self.helpmenu=menu=Menu(self) menu.Add(self.OnHelp, xlt("Help"), xlt("Show help"), wx.ID_HELP) menu.Add(self.OnLogging, xlt("Logging"), xlt("Show logged problems")) menu.Add(self.OnUpdate, xlt("Update"), xlt("Update program modules")) menu.Add(self.OnAbout, xlt("About"), xlt("About %s") % adm.appTitle, wx.ID_ABOUT, adm.app.SetMacAboutMenuItemId) menubar.Append(menu, xlt("&Help")) self.SetMenuBar(menubar) self.CreateStatusBar() self.details = Notebook(self) self.manager.AddPane(self.details, wx.aui.AuiPaneInfo().Center().CloseButton(False) \ .Name("objectDetails").Caption(xlt("Object details"))) self.nodePanel=NodeTreePanel(self, name) self.tree=self.nodePanel.tree self.nodePanel.DoShow(False) self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeSelChange) self.manager.AddPane(self.nodePanel, wx.aui.AuiPaneInfo().Left().Layer(1).Floatable() \ .Name("objectBrowser").Caption(xlt("Object browser")) \ .MinSize((200,300)).BestSize((250,350))) self.servers=ServerTreeCtrl(self) self.manager.AddPane(self.servers, wx.aui.AuiPaneInfo().Bottom().Layer(1).Float() \ .Name("servers").Caption(xlt("Registered Servers")) \ .MinSize((70,70)).BestSize((100,80))) str=adm.config.GetPerspective(self) if str: self.manager.LoadPerspective(str) ah=AcceleratorHelper(self) ah.Add(wx.ACCEL_CTRL, 'F', self.OnFindObject) ah.Add(wx.ACCEL_NORMAL, wx.WXK_F5, self.OnRefresh) ah.Realize() self.OnToggleTree() self.OnToggleToolBar() self.OnToggleStatusBar() self.manager.Update() self.manager.Bind(wx.aui.EVT_AUI_PANE_CLOSE, self.OnAuiCloseEvent) self.Bind(wx.EVT_ACTIVATE, self.OnActivate) self.activated=False
class DetailFrame(Frame): def __init__(self, parentWin, name, args=None, title=None): if not title: title=name style=wx.MAXIMIZE_BOX|wx.RESIZE_BORDER|wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX adm.Frame.__init__(self, parentWin, title, style, (600,400), None) self.SetIcon(name) self.name=name self.lastNode=None self.appArgs=args self.manager=wx.aui.AuiManager(self) self.manager.SetFlags(wx.aui.AUI_MGR_ALLOW_FLOATING|wx.aui.AUI_MGR_TRANSPARENT_HINT | \ wx.aui.AUI_MGR_HINT_FADE| wx.aui.AUI_MGR_TRANSPARENT_DRAG) self.toolbar=ToolBar(self, 32); self.toolbar.Add(self.OnShowServers, xlt("Show registered servers"), "connect") self.toolbar.Add(self.OnDetach, xlt("Detach view"), "detach") self.toolbar.Add(self.OnRefresh, xlt("Refresh"), "refresh") self.toolbar.AddSeparator() self.toolbar.Add(self.OnEdit, xlt("Edit"), "edit") self.toolbar.Add(self.OnNew, xlt("New"), "new") self.toolbar.Add(self.OnDelete, xlt("Delete"), "delete") self.toolbar.Add(self.OnFindObject, xlt("Find"), "edit_find") self.toolbar.AddSeparator() self.standardToolsCount=self.toolbar.GetToolsCount() self.toolbar.Realize() menubar=wx.MenuBar() self.filemenu=menu=Menu(self) self.registermenu=Menu(self) for modulename in adm.modules.keys(): moduleinfo=adm.modules[modulename].moduleinfo registerproc=moduleinfo['serverclass'].Register self.registermenu.Add(registerproc, xlt("Register new %s") % moduleinfo['name']) self.filemenu.AppendOneMenu(self.registermenu, xlt("Register Server")) if wx.Platform != "__WXMAC__": menu.AppendSeparator() menu.Add(self.OnPreferences, xlt("Preferences"), xlt("Preferences"), wx.ID_PREFERENCES, adm.app.SetMacPreferencesMenuItemId) menu.Add(self.OnQuit, xlt("Quit"), xlt("Quit Admin4"), wx.ID_EXIT, adm.app.SetMacExitMenuItemId) menubar.Append(menu, xlt("&File")) self.viewmenu=menu=Menu(self) menu.Add(self.OnShowServers, xlt("Show Servers"), xlt("Show registered servers to connect")) menu.AddCheck(self.OnToggleTree, xlt("Tree"), xlt("Show or hide tree"), adm.config.Read("TreeShown", True, self)) self.registerToggles(True, True) menubar.Append(menu, xlt("&View")) self.editmenu=menu=Menu(self) menu.Add(self.OnEdit, xlt("Edit"), xlt("edit")) menu.Add(self.OnNew, xlt("New"), xlt("new object")) menu.Add(self.OnDelete, xlt("Delete"), xlt("delete object")) menu.Add(self.OnFindObject, xlt("Find"), xlt("find object")) menubar.Append(menu, xlt("&Edit")) self.helpmenu=menu=Menu(self) menu.Add(self.OnHelp, xlt("Help"), xlt("Show help"), wx.ID_HELP) menu.Add(self.OnLogging, xlt("Logging"), xlt("Show logged problems")) menu.Add(self.OnUpdate, xlt("Update"), xlt("Update program modules")) menu.Add(self.OnAbout, xlt("About"), xlt("About %s") % adm.appTitle, wx.ID_ABOUT, adm.app.SetMacAboutMenuItemId) menubar.Append(menu, xlt("&Help")) self.SetMenuBar(menubar) self.CreateStatusBar() self.details = Notebook(self) self.manager.AddPane(self.details, wx.aui.AuiPaneInfo().Center().CloseButton(False) \ .Name("objectDetails").Caption(xlt("Object details"))) self.nodePanel=NodeTreePanel(self, name) self.tree=self.nodePanel.tree self.nodePanel.DoShow(False) self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeSelChange) self.manager.AddPane(self.nodePanel, wx.aui.AuiPaneInfo().Left().Layer(1).Floatable() \ .Name("objectBrowser").Caption(xlt("Object browser")) \ .MinSize((200,300)).BestSize((250,350))) self.servers=ServerTreeCtrl(self) self.manager.AddPane(self.servers, wx.aui.AuiPaneInfo().Bottom().Layer(1).Float() \ .Name("servers").Caption(xlt("Registered Servers")) \ .MinSize((70,70)).BestSize((100,80))) str=adm.config.GetPerspective(self) if str: self.manager.LoadPerspective(str) ah=AcceleratorHelper(self) ah.Add(wx.ACCEL_CTRL, 'F', self.OnFindObject) ah.Add(wx.ACCEL_NORMAL, wx.WXK_F5, self.OnRefresh) ah.Realize() self.OnToggleTree() self.OnToggleToolBar() self.OnToggleStatusBar() self.manager.Update() self.manager.Bind(wx.aui.EVT_AUI_PANE_CLOSE, self.OnAuiCloseEvent) self.Bind(wx.EVT_ACTIVATE, self.OnActivate) self.activated=False def OnFindObject(self, evt): self.nodePanel.DoShow(True) self.nodePanel['Find'].SetFocus() def OnActivate(self, evt): if not self.activated: self.activated=True CheckAutoUpdate(self) if not wx.GetKeyState(wx.WXK_SHIFT): self.AutoConnect(evt) evt.Skip() def AutoConnect(self, evt): haveOne=False if self.appArgs: for server in self.servers.nodes: if "%s/%s" % (server.module, server.name) in self.appArgs: rc=self.servers.ConnectServer(server, self.tree.name) haveOne = haveOne or rc else: for server in self.servers.nodes: if server.settings.get("autoconnect"): #try: rc=self.servers.ConnectServer(server, self.tree.name) haveOne = haveOne or rc # except StringException: # pass if not haveOne: self.OnShowServers(None) self.servers.ExpandFirst() def OnAuiCloseEvent(self, evt): if evt.GetPane().name == "objectBrowser": self.viewmenu.Check(self.OnToggleTree, False) def OnQuit(self, evt): self.details=None # this is for Win C++ dtor self.Close() def OnToggleTree(self, evt=None): show=self.viewmenu.IsChecked(self.OnToggleTree) self.manager.GetPane("objectBrowser").Show(show) if evt: self.manager.Update() adm.config.Write("TreeShown", show, self) def OnLogging(self, evt): dlg=LoggingDialog(self) dlg.Go() dlg.Show() def OnUpdate(self, evt=None): dlg=UpdateDlg(self) dlg.GoModal() def GetNode(self): if self.currentNode: return self.currentNode else: return self.tree.GetNode() def OnHelp(self, evt): wx.LaunchDefaultBrowser("http://www.admin4.org/docs") def OnPreferences(self, evt): dlg=PreferencesDlg(self) dlg.Go() dlg.Show() def OnAbout(self, evt): about=AboutDlg(self) about.ShowModal() def OnShowServers(self, evt): self.manager.GetPane("servers").Show(True) self.manager.Update() def OnDetach(self, evt): node=self.GetNode() if node: if not node.detachedWindow: node.detachedWindow = DetachFrame(self, node) node.detachedWindow.Show() node.detachedWindow.Raise() def OnRefresh(self, evt): node=self.GetNode() if node: node.Refresh() node.PopulateChildren() info=node.GetInfo() self.SetStatus(info) def OnNew(self, evt): node=self.GetNode() if node: newcls=self.getNewClass(node) if newcls: newcls.New(self, node.parentNode) def OnEdit(self, evt): node=self.GetNode() if node and hasattr(node, "Edit"): node.Edit(self) def OnDelete(self, evt): node=self.tree.GetNode() if node and hasattr(node, "Delete"): if not adm.ConfirmDelete(xlt("Delete \"%s\"?") % node.name, xlt("Deleting %s") % node.typename): return if node.Delete(): node.RemoveFromTree() self.SetStatus(xlt("%s \"%s\" deleted.") % (node.typename, node.name)) else: self.SetStatus(xlt("%s \"%s\" NOT deleted: %s.") % (node.typename, node.name, node.GetServer().GetLastError())) def OnDisconnect(self, evt): node=self.tree.GetNode() if node and hasattr(node, "Disconnect"): node.Disconnect() node.RemoveFromTree() self.SetStatus(xlt("%s \"%s\" disconnected.") % (node.typename, node.name)) def GetNodePath(self, item): node=self.tree.GetNode(item) if not node: return None parentItem=self.tree.GetItemParent(item) if parentItem: pp=self.GetNodePath(parentItem) if pp: return "%s/%s" % (pp, node.id.path()) return node.id.path() def OnTreeSelChange(self, evt): if not self.details: return item=evt.GetItem() if item != self.tree.GetSelection(): self.tree.SelectItem(item) self.tree.EnsureVisible(item) return node=self.tree.GetNode(item) self.details.Set(node) if node and hasattr(node, "GetHint"): hint=node.GetHint() if hint: if not hasattr(node, 'hintShown'): node.hintShown=True if isinstance(hint, tuple): title=hint[1] args=hint[2] hint=hint[0] else: title=None args=None adm.ShowHint(self, hint, node, title, args) self.manager.Update() if not self.lastNode or not node or self.lastNode.moduleClass() != node.moduleClass(): for _i in range(self.standardToolsCount, self.toolbar.GetToolsCount()): self.toolbar.DeleteToolByPos(self.standardToolsCount) if node: for mi in node.moduleinfo()['tools']: cls=mi['class'] self.toolbar.Add(cls) self.toolbar.Realize() self.lastNode=node if node: self.EnableMenu(self.editmenu, self.OnEdit, hasattr(node, "Edit")) self.EnableMenu(self.editmenu, self.OnDelete, hasattr(node, "Delete")) self.EnableMenu(self.editmenu, self.OnNew, self.getNewClass(node) != None) for mi in node.moduleinfo()['tools']: en=self.menuAvailableOnNode(mi, node) cls=mi['class'] if en: if hasattr(cls, 'CheckEnabled'): en=cls.CheckEnabled(node) self.toolbar.Enable(cls.OnExecute, en) server=node.GetServer() if server != node: # don't store a server's nodePath, this would overwrite the desired nodePath on disconnect nodePath=self.GetNodePath(item) if nodePath: server.settings['nodePath'] = nodePath adm.config.storeServerSettings(server, server.settings) self.tree.SetFocus() if not node: self.SetStatus("") return self.SetStatus(node.GetInfo()) def getNewClass(self, node): if hasattr(node, "New"): return node.__class__ elif isinstance(node, adm.Group) and node.memberclass and hasattr(node.memberclass, "New"): return node.memberclass elif isinstance(node, adm.Collection) and node.nodeclass and hasattr(node.nodeclass, "New"): return node.nodeclass return None def menuAvailableOnNode(self, mi, node): cls=mi['class'] if hasattr(cls, "CheckAvailableOn"): return cls.CheckAvailableOn(node) nodeclasses=mi.get('nodeclasses') if nodeclasses: for nc in nodeclasses: if isinstance(node, nc): return True else: logger.debug("no nodeclasses for %s", cls.__name__) return False def GetContextMenu(self, node): contextMenu=Menu(self) if not len(node.properties): node.GetProperties() newcls=self.getNewClass(node) newmenu=Menu(self) if newcls: newmenu.Add(newcls.New, xlt("New %s") % newcls.shortname, xlt("Create new %s") % newcls.typename) morenew=node.nodeinfo().get('new', []) if isinstance(morenew, list): morenew=list(morenew) # copy else: morenew=[morenew] children=node.nodeinfo().get('children', []) for child in children: childnodeinfo=node.nodeinfo(child) childclass=childnodeinfo['class'] if childclass not in morenew: morenew.append(childclass) childnew=childnodeinfo.get('new', []) if not isinstance(childnew, list): childnew=[childnew] for childclass in childnew: if childclass not in morenew: morenew.append(childclass) for cls in morenew: if cls == newcls: continue if hasattr(cls, "New"): newmenu.Add(cls.New, xlt("New %s") % cls.shortname, xlt("Create new %s") % cls.typename) contextMenu.AppendOneMenu(newmenu, xlt("New Object"), xlt("Creates a new object")) if hasattr(node, "Delete"): if not hasattr(node, "deleteDisable") or not node.deleteDisable: contextMenu.Add(self.OnDelete, xlt("Delete %s") % node.shortname, xlt("Delete %s %s") % (node.typename,node.name)) if hasattr(node, "Disconnect"): contextMenu.Add(self.OnDisconnect, xlt("Disconnect %s") % node.name, xlt("Disconnect %s \"%s\"") % (node.typename,node.name)) if contextMenu.GetMenuItemCount(): contextMenu.AppendSeparator() contextMenu.Add(self.OnRefresh, xlt("Refresh"), xlt("Refresh %s") % node.typename) contextMenu.Add(self.OnDetach, xlt("Detach view"), xlt("Show %s in detached window") % node.typename) needSeparator=True for mi in node.menuinfos(): if self.menuAvailableOnNode(mi, node): if needSeparator: contextMenu.AppendSeparator() needSeparator=False cls=mi['class'] item=contextMenu.Add(cls.OnExecute, cls.name, cls.help) if hasattr(cls, "CheckEnabled") and not cls.CheckEnabled(node): contextMenu.Enable(item, False) if hasattr(node, "Edit"): contextMenu.AppendSeparator() contextMenu.Add(self.OnEdit, xlt("Properties"), xlt("Edit properties of %s") % node.typename) return contextMenu
def OnItemRightClick(self, evt): if hasattr(self, 'OnCopy'): cm = Menu(self.dialog) cm.Add(self.OnCopy, xlt("Copy"), xlt("Copy")) cm.Popup(evt)
def OnRightClick(self, evt): self.cmRow = evt.GetRow() cm = Menu(self) cm.Add(self.OnDelete, xlt("Delete"), xlt("Delete line")) cm.Popup(evt)
def OnTreeRightClick(self, evt): item, _flags = self.HitTest(evt.GetPosition()) if item and item != self.GetSelection(): self.SelectItem(item) cm = Menu(self.frame) if item: snippet = self.GetNode(item) if snippet.IsGroup(): cm.Add(self.OnRenameSnippet, xlt("Rename"), xlt(("Rename group"))) item = cm.Add(self.OnDelSnippet, xlt("Delete"), xlt(("Delete group"))) for s in self.snippets.values(): if s.parent == snippet.id: cm.Enable(item, False) break else: cm.Add(self.OnReplaceSnippet, xlt("Replace"), xlt(("Replace snippet text"))) cm.Add(self.OnRenameSnippet, xlt("Rename"), xlt(("Rename snippet"))) item = cm.Add(self.OnRevertSnippet, xlt("Revert"), xlt(("Revert snippet to previous text"))) cm.Enable(item, snippet.prevText != None) cm.Add(self.OnDelSnippet, xlt("Delete"), xlt( ("Delete snippet"))) cm.AppendSeparator() cm.Add(self.OnAddGroup, xlt("Add group"), xlt(("Add group"))) cm.Popup(evt)