def __init__(self, title): self.connectionMap = {} self.tableCache = {} # Create the Menu Bar # self.createMenuBar() # self.createStatusBar() wx.Frame.__init__(self, None, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition, size=wx.Size(900, 560), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) bSizer15 = wx.BoxSizer(wx.VERTICAL) self.m_splitter3 = wx.SplitterWindow(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SP_3D) self.m_splitter3.Bind(wx.EVT_IDLE, self.m_splitter3OnIdle) self.m_panel4 = wx.Panel(self.m_splitter3, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) bSizer18 = wx.BoxSizer(wx.VERTICAL) self.m_treeCtrl4 = wx.TreeCtrl(self.m_panel4, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TR_DEFAULT_STYLE) bSizer18.Add(self.m_treeCtrl4, 1, wx.ALL | wx.EXPAND, 5) self.TreeRoot = self.m_treeCtrl4.AddRoot("Connections") self.m_panel4.SetSizer(bSizer18) self.m_panel4.Layout() bSizer18.Fit(self.m_panel4) self.m_panel5 = wx.Panel(self.m_splitter3, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) bSizer19 = wx.BoxSizer(wx.VERTICAL) bSizer11 = wx.BoxSizer(wx.HORIZONTAL) self.m_button9 = wx.Button(self.m_panel5, wx.ID_ANY, u"Connect", wx.DefaultPosition, wx.DefaultSize, 0) bSizer11.Add(self.m_button9, 0, wx.ALL, 5) self.m_button16 = wx.Button(self.m_panel5, wx.ID_ANY, u"Disconnect", wx.DefaultPosition, wx.DefaultSize, 0) bSizer11.Add(self.m_button16, 0, wx.ALL | wx.ALIGN_RIGHT, 5) self.m_staticline5 = wx.StaticLine(self.m_panel5, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_VERTICAL) bSizer11.Add(self.m_staticline5, 0, wx.EXPAND | wx.ALL, 5) self.m_button17 = wx.Button(self.m_panel5, wx.ID_ANY, u"Export", wx.DefaultPosition, wx.DefaultSize, 0) bSizer11.Add(self.m_button17, 0, wx.ALL, 5) bSizer19.Add(bSizer11, 0, wx.ALIGN_RIGHT, 5) self.m_staticline2 = wx.StaticLine(self.m_panel5, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) bSizer19.Add(self.m_staticline2, 0, wx.EXPAND | wx.ALL, 5) gSizer7 = wx.GridSizer(0, 1, 0, 0) ##### This is for normal tab self.m_notebook2 = wx.Notebook(self.m_panel5, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0) ##### This is for AUI Tab. # self.m_notebook2 = wx.aui.AuiNotebook(self.m_panel5, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, # wx.aui.AUI_NB_DEFAULT_STYLE - wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) self.m_notebook2.SetBackgroundColour(wx.WHITE) self.m_panel6 = SchemaPanel(self.m_notebook2) self.m_notebook2.AddPage(self.m_panel6, u"Schema", False) self.m_panel7 = ERPanel(self.m_notebook2) self.m_notebook2.AddPage(self.m_panel7, u"ER Diagram", False) gSizer7.Add(self.m_notebook2, 1, wx.EXPAND | wx.ALL, 5) bSizer19.Add(gSizer7, 1, wx.EXPAND, 5) self.m_staticline51 = wx.StaticLine(self.m_panel5, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) bSizer19.Add(self.m_staticline51, 0, wx.EXPAND | wx.ALL, 5) bSizer21 = wx.BoxSizer(wx.VERTICAL) bSizer23 = wx.BoxSizer(wx.HORIZONTAL) self.m_gauge1 = wx.Gauge(self.m_panel5, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL) self.m_gauge1.SetValue(0) bSizer23.Add(self.m_gauge1, 0, wx.ALL | wx.EXPAND, 5) self.m_staticText15 = wx.StaticText(self.m_panel5, wx.ID_ANY, u"", wx.DefaultPosition, wx.DefaultSize, 0) self.m_staticText15.Wrap(-1) bSizer23.Add(self.m_staticText15, 1, wx.ALL, 5) bSizer21.Add(bSizer23, 0, wx.EXPAND, 5) bSizer19.Add(bSizer21, 0, wx.EXPAND, 5) self.m_panel5.SetSizer(bSizer19) self.m_panel5.Layout() bSizer19.Fit(self.m_panel5) self.m_splitter3.SplitVertically(self.m_panel4, self.m_panel5, 0) bSizer15.Add(self.m_splitter3, 1, wx.EXPAND, 5) self.SetSizer(bSizer15) self.Layout() self.m_menubar5 = wx.MenuBar(0) self.file = wx.Menu() self.m_menuItem4 = wx.MenuItem(self.file, wx.ID_ANY, u"New..", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem4) self.file.AppendSeparator() self.m_menuItem51 = wx.MenuItem(self.file, wx.ID_ANY, u"Connect", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem51) self.m_menuItem61 = wx.MenuItem(self.file, wx.ID_ANY, u"Disconnect", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem61) self.file.AppendSeparator() self.m_menuItem6 = wx.MenuItem(self.file, wx.ID_ANY, u"Close", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem6) self.m_menuItem7 = wx.MenuItem(self.file, wx.ID_ANY, u"Close All", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem7) self.file.AppendSeparator() self.m_menuItem5 = wx.MenuItem(self.file, wx.ID_ANY, u"Exit", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem5) self.m_menubar5.Append(self.file, u"File") self.edit = wx.Menu() self.m_menubar5.Append(self.edit, u"Edit") self.view = wx.Menu() self.m_menubar5.Append(self.view, u"View") self.window = wx.Menu() self.m_menubar5.Append(self.window, u"Window") self.help = wx.Menu() self.m_menubar5.Append(self.help, u"Help") self.SetMenuBar(self.m_menubar5) self.m_statusBar2 = self.CreateStatusBar(1, wx.ST_SIZEGRIP, wx.ID_ANY) self.Centre(wx.BOTH) # Connect Events self.m_button9.Bind(wx.EVT_BUTTON, self.connectDatabase) self.m_button16.Bind(wx.EVT_BUTTON, self.disconnectDatabase) self.m_button17.Bind(wx.EVT_BUTTON, self.exportReport) self.Bind(wx.EVT_MENU, self.connectDatabase, id=self.m_menuItem51.GetId()) self.Bind(wx.EVT_MENU, self.disconnectDatabase, id=self.m_menuItem61.GetId()) # self.AddNewDatabaseTree() self.passGaugeAndLabel(self.m_gauge1, self.m_staticText15)
class MyFrame(wx.Frame): def createMenuBar(self): menuFile = wx.Menu() menuFile.Append(1, "&About...", "this is about") menuFile.AppendSeparator() menuFile.Append(2, "E&xit") menuBar = wx.MenuBar() menuBar.Append(menuFile, "&File") newConnectionMenu = wx.Menu() newConnectionMenu.Append(3, "Connect Database") newConnectionMenu.AppendSeparator() newConnectionMenu.AppendCheckItem(4, "Check") menuBar.Append(newConnectionMenu, "New..") self.SetMenuBar(menuBar) self.Bind(wx.EVT_MENU, self.OnAbout, id=1) self.Bind(wx.EVT_MENU, self.OnQuit, id=2) def createStatusBar(self): self.CreateStatusBar() self.SetStatusText("Welcome to wxPython!") def __init__(self, title): self.connectionMap = {} self.tableCache = {} # Create the Menu Bar # self.createMenuBar() # self.createStatusBar() wx.Frame.__init__(self, None, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition, size=wx.Size(900, 560), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) bSizer15 = wx.BoxSizer(wx.VERTICAL) self.m_splitter3 = wx.SplitterWindow(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SP_3D) self.m_splitter3.Bind(wx.EVT_IDLE, self.m_splitter3OnIdle) self.m_panel4 = wx.Panel(self.m_splitter3, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) bSizer18 = wx.BoxSizer(wx.VERTICAL) self.m_treeCtrl4 = wx.TreeCtrl(self.m_panel4, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TR_DEFAULT_STYLE) bSizer18.Add(self.m_treeCtrl4, 1, wx.ALL | wx.EXPAND, 5) self.TreeRoot = self.m_treeCtrl4.AddRoot("Connections") self.m_panel4.SetSizer(bSizer18) self.m_panel4.Layout() bSizer18.Fit(self.m_panel4) self.m_panel5 = wx.Panel(self.m_splitter3, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) bSizer19 = wx.BoxSizer(wx.VERTICAL) bSizer11 = wx.BoxSizer(wx.HORIZONTAL) self.m_button9 = wx.Button(self.m_panel5, wx.ID_ANY, u"Connect", wx.DefaultPosition, wx.DefaultSize, 0) bSizer11.Add(self.m_button9, 0, wx.ALL, 5) self.m_button16 = wx.Button(self.m_panel5, wx.ID_ANY, u"Disconnect", wx.DefaultPosition, wx.DefaultSize, 0) bSizer11.Add(self.m_button16, 0, wx.ALL | wx.ALIGN_RIGHT, 5) self.m_staticline5 = wx.StaticLine(self.m_panel5, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_VERTICAL) bSizer11.Add(self.m_staticline5, 0, wx.EXPAND | wx.ALL, 5) self.m_button17 = wx.Button(self.m_panel5, wx.ID_ANY, u"Export", wx.DefaultPosition, wx.DefaultSize, 0) bSizer11.Add(self.m_button17, 0, wx.ALL, 5) bSizer19.Add(bSizer11, 0, wx.ALIGN_RIGHT, 5) self.m_staticline2 = wx.StaticLine(self.m_panel5, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) bSizer19.Add(self.m_staticline2, 0, wx.EXPAND | wx.ALL, 5) gSizer7 = wx.GridSizer(0, 1, 0, 0) ##### This is for normal tab self.m_notebook2 = wx.Notebook(self.m_panel5, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0) ##### This is for AUI Tab. # self.m_notebook2 = wx.aui.AuiNotebook(self.m_panel5, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, # wx.aui.AUI_NB_DEFAULT_STYLE - wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) self.m_notebook2.SetBackgroundColour(wx.WHITE) self.m_panel6 = SchemaPanel(self.m_notebook2) self.m_notebook2.AddPage(self.m_panel6, u"Schema", False) self.m_panel7 = ERPanel(self.m_notebook2) self.m_notebook2.AddPage(self.m_panel7, u"ER Diagram", False) gSizer7.Add(self.m_notebook2, 1, wx.EXPAND | wx.ALL, 5) bSizer19.Add(gSizer7, 1, wx.EXPAND, 5) self.m_staticline51 = wx.StaticLine(self.m_panel5, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) bSizer19.Add(self.m_staticline51, 0, wx.EXPAND | wx.ALL, 5) bSizer21 = wx.BoxSizer(wx.VERTICAL) bSizer23 = wx.BoxSizer(wx.HORIZONTAL) self.m_gauge1 = wx.Gauge(self.m_panel5, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL) self.m_gauge1.SetValue(0) bSizer23.Add(self.m_gauge1, 0, wx.ALL | wx.EXPAND, 5) self.m_staticText15 = wx.StaticText(self.m_panel5, wx.ID_ANY, u"", wx.DefaultPosition, wx.DefaultSize, 0) self.m_staticText15.Wrap(-1) bSizer23.Add(self.m_staticText15, 1, wx.ALL, 5) bSizer21.Add(bSizer23, 0, wx.EXPAND, 5) bSizer19.Add(bSizer21, 0, wx.EXPAND, 5) self.m_panel5.SetSizer(bSizer19) self.m_panel5.Layout() bSizer19.Fit(self.m_panel5) self.m_splitter3.SplitVertically(self.m_panel4, self.m_panel5, 0) bSizer15.Add(self.m_splitter3, 1, wx.EXPAND, 5) self.SetSizer(bSizer15) self.Layout() self.m_menubar5 = wx.MenuBar(0) self.file = wx.Menu() self.m_menuItem4 = wx.MenuItem(self.file, wx.ID_ANY, u"New..", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem4) self.file.AppendSeparator() self.m_menuItem51 = wx.MenuItem(self.file, wx.ID_ANY, u"Connect", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem51) self.m_menuItem61 = wx.MenuItem(self.file, wx.ID_ANY, u"Disconnect", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem61) self.file.AppendSeparator() self.m_menuItem6 = wx.MenuItem(self.file, wx.ID_ANY, u"Close", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem6) self.m_menuItem7 = wx.MenuItem(self.file, wx.ID_ANY, u"Close All", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem7) self.file.AppendSeparator() self.m_menuItem5 = wx.MenuItem(self.file, wx.ID_ANY, u"Exit", wx.EmptyString, wx.ITEM_NORMAL) self.file.AppendItem(self.m_menuItem5) self.m_menubar5.Append(self.file, u"File") self.edit = wx.Menu() self.m_menubar5.Append(self.edit, u"Edit") self.view = wx.Menu() self.m_menubar5.Append(self.view, u"View") self.window = wx.Menu() self.m_menubar5.Append(self.window, u"Window") self.help = wx.Menu() self.m_menubar5.Append(self.help, u"Help") self.SetMenuBar(self.m_menubar5) self.m_statusBar2 = self.CreateStatusBar(1, wx.ST_SIZEGRIP, wx.ID_ANY) self.Centre(wx.BOTH) # Connect Events self.m_button9.Bind(wx.EVT_BUTTON, self.connectDatabase) self.m_button16.Bind(wx.EVT_BUTTON, self.disconnectDatabase) self.m_button17.Bind(wx.EVT_BUTTON, self.exportReport) self.Bind(wx.EVT_MENU, self.connectDatabase, id=self.m_menuItem51.GetId()) self.Bind(wx.EVT_MENU, self.disconnectDatabase, id=self.m_menuItem61.GetId()) # self.AddNewDatabaseTree() self.passGaugeAndLabel(self.m_gauge1, self.m_staticText15) def __del__(self): pass def passGaugeAndLabel(self, gauge, label): self.m_panel6.acceptGaugeAndLabel(gauge, label) self.m_panel7.acceptGaugeAndLabel(gauge, label) # Virtual event handlers, override them in your derived class def connectDatabase(self, event): dialog = ConnectionDialog(self) if dialog.ShowModal() == wx.ID_OK: server = dialog.m_comboBox1.GetValue() database = dialog.m_comboBox5.GetValue() databaseType = dialog.dbTypeChoice.GetStringSelection() username = dialog.m_comboBox2.GetValue() password = dialog.m_textCtrl6.GetValue() credential = DBCredentials(server, database, databaseType, username, password) displayName = credential.getDisplayName() self.connectionMap[displayName] = credential tables = AbstractDBOperations().extractInformation(credential) self.tableCache[displayName] = tables self.AddNewDatabaseTree1(displayName, tables) self.passNewConnections() def passNewConnections(self): self.m_panel6.acceptNewConnection(self.connectionMap, self.tableCache) self.m_panel7.acceptNewConnection(self.connectionMap, self.tableCache) def disconnectDatabase(self, event): print("Disconnect Database") # self.m_panel7.saveSnap1() event.Skip() def exportReport(self, event): print("Export Report") wildcard = "OpenOffice Document (*.odt)|*.odt|OpenOffice SpreadSheet (*.ods)|*.ods" dlg = wx.FileDialog(self, message="Save", defaultDir="", defaultFile="", wildcard=wildcard, style=wx.SAVE) if dlg.ShowModal() == wx.ID_OK: self.filename = dlg.GetPath() # TODO: Uncomment this line. # fileExport = FileExportOperation() # if (self.filename.endswith(".ods")): # fileExport.exportODSFile(self.obj, dlg.GetPath()) # else: # fileExport.exportODTFile(self.obj, dlg.GetPath()) dlg.Destroy() event.Skip() def m_splitter3OnIdle(self, event): self.m_splitter3.SetSashPosition(0) self.m_splitter3.Unbind(wx.EVT_IDLE) def OnQuit(self, event): self.Close() def OnAbout(self, event): ConnectionDialog(self).ShowModal() # wx.MessageBox("This is a wxPython Hello world sample", "About Hello World", wx.OK | wx.ICON_INFORMATION, self) def updateStatusBarMessage(self, message): self.m_statusBar2.SetMessage(message) def AddNewDatabaseTree(self, connectionName, schemaBO): firstRoot = self.m_treeCtrl4.AppendItem(self.TreeRoot, connectionName) for schemaObjectType in schemaBO.schemaObjects: newItem = self.m_treeCtrl4.AppendItem(firstRoot, schemaBO.schemaObjectsNameMappings.get(schemaObjectType)) for objects in schemaBO.schemaObjects[schemaObjectType]: self.m_treeCtrl4.AppendItem(newItem, objects) def AddNewDatabaseTree1(self, displayName, tables): firstRoot = self.m_treeCtrl4.AppendItem(self.TreeRoot, displayName) for table in tables: self.m_treeCtrl4.AppendItem(firstRoot, str(table)) def AddTreeNodes(self, parent, items): for item in items: if type(item) == str: self.m_treeCtrl4.AppendItem(parent, item) else: newItem = self.m_treeCtrl4.AppendItem(parent, item[0]) self.AddTreeNodes(newItem, item[1])