def onOkClick(self, event): logger.debug('onOkClick') sqlExecuter = SQLExecuter() sqlTypeObjectList = sqlExecuter.getSqlObjects() if len(sqlTypeObjectList) == 0: sqlExecuter.createOpalTables() sqlExecuter.addNewConnectionRow( self.GetParent().CreateOpenConnectionPanel.filePath, self.GetParent().CreateOpenConnectionPanel.connectionNameText. GetValue()) # data = self.GetTopLevelParent().createImportingCsvPanel.data # tableName = self.GetTopLevelParent().createImportingCsvPanel.tableNameText.GetValue() # fileOperations = FileOperations() # # data = fileOperations.readCsvFile(filePath=filePath, columnNameFirstRow=True, delimiter=",", quotechar='|') # # print(len(data)) # # print(data) # createTableScript = fileOperations.createTableScript(tableName=tableName, columnHeader=data[0]) # print(createTableScript) # sqlList = fileOperations.sqlScript(tableName=tableName, data=data) # print(sqlList) # connectionName = self.GetTopLevelParent().connectionName # importStatus = SQLUtils().importingData(connectionName=connectionName, sqlList=sqlList) # dlg = wx.MessageDialog(self, "Some status", # 'Importing data status', # wx.OK | wx.ICON_INFORMATION # #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION # ) # dlg.ShowModal() # dlg.Destroy() self.GetTopLevelParent().Destroy()
def onRefresh(self, event=None): logger.debug('onRefresh') ''' 1. find current active connection. 2. refresh only that connection. ''' ################################################################################## sqlExecuter = SQLExecuter(database='_opal.sqlite') textCtrl = self.GetTopLevelParent()._ctrl selectedItemText = textCtrl.GetValue() dbFilePath = sqlExecuter.getDbFilePath(selectedItemText) logger.debug("dbFilePath: %s", dbFilePath)
def findingConnectionName(self): ''' This method defines connection name based on selected connection in the tree. @return: (connectionName, databaseAbsolutePath) ''' ################################################################################## sqlExecuter = SQLExecuter(database='_opal.sqlite') textCtrl = self.GetTopLevelParent()._ctrl connectionName = textCtrl.GetValue() databaseAbsolutePath = sqlExecuter.getDbFilePath(connectionName) logger.debug("databaseAbsolutePath: %s", databaseAbsolutePath) ################################################################################## return connectionName, databaseAbsolutePath
def createNewDatabase(self, databaseAbsolutePath=None, connectionName=None): try: manageSqliteDatabase = ManageSqliteDatabase( databaseAbsolutePath=databaseAbsolutePath, connectionName=connectionName) manageSqliteDatabase.createTable() sqlExecuter = SQLExecuter() sqlTypeObjectList = sqlExecuter.getSqlObjects() if len(sqlTypeObjectList) == 0: sqlExecuter.createOpalTables() sqlExecuter.addNewConnectionRow(databaseAbsolutePath, connectionName) except OperationalError as err: logger.error(err, exc_info=True)
def onDeleteWithDatabaseTable(self, event): logger.debug('onDeleteWithDatabaseTable') # self.onDeleteConnection(event) ################################################################################## sqlExecuter = SQLExecuter(database='_opal.sqlite') selectedItemId = self.tree.GetSelection() selectedItemText = self.tree.GetItemText(self.tree.GetSelection()) dbFilePath = sqlExecuter.getDbFilePath(selectedItemText) logger.debug("dbFilePath: %s", dbFilePath) ################################################################################## fileOperations = FileOperations() fileRemoved = fileOperations.removeFile(filename=dbFilePath) if selectedItemText and fileRemoved: self.sqlExecuter.removeConnctionRow(selectedItemText) self.recreateTree()
def onCreateErDiagramItem(self, event): logger.debug('onCreateErDiagramItem') ################################################################################## sqlExecuter = SQLExecuter(database='_opal.sqlite') textCtrl = self.GetTopLevelParent()._ctrl selectedItemText = textCtrl.GetValue() dbFilePath = sqlExecuter.getDbFilePath(selectedItemText) logger.debug("dbFilePath: %s", dbFilePath) ################################################################################## depth = self.tree.GetItemData(self.tree.GetSelection())['depth'] if os.path.isfile(dbFilePath): dbObjects = ManageSqliteDatabase(connectionName=selectedItemText , databaseAbsolutePath=dbFilePath).getObject() createErDiagramFrame = CreateErDiagramFrame(None) createErDiagramFrame.setDbObjects(dbObjects=dbObjects) createErDiagramFrame.Show()
def OnDropFiles(self, x, y, fileNams): logger.debug("dropFiles {}".format(fileNams)) try: for fileAbsoluteName in fileNams: if os.path.isdir(fileAbsoluteName): continue logger.debug(fileAbsoluteName) if self.isSQLite3(fileAbsoluteName): self.getConnectionName(filePath=fileAbsoluteName) sqlExecuter = SQLExecuter() obj = sqlExecuter.getObject() if len(obj[1]) == 0: sqlExecuter.createOpalTables() sqlExecuter.addNewConnectionRow(fileAbsoluteName, self.getConnectionName(filePath=fileAbsoluteName)) self.dirwin.recreateTree() except Exception as ex: logger.error(ex) return True
def __init__(self, parent=None, *args, **kw): wx.Panel.__init__(self, parent, id=-1) self.parent = parent self.fileOperations = FileOperations() self.connDict = dict() vBox = wx.BoxSizer(wx.VERTICAL) #################################################################### self.sqlExecuter = SQLExecuter() self._treeList = self.sqlExecuter.getObject() self.treeMap = {} self.searchItems = {} self.tree = DatabaseNavigationTree(self) self.filter = wx.SearchCtrl(self, style=wx.TE_PROCESS_ENTER) self.filter.SetDescriptiveText("Type filter table name") self.filter.ShowCancelButton(True) self.filter.Bind(wx.EVT_TEXT, self.recreateTree) self.filter.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, lambda e: self.filter.SetValue('')) self.filter.Bind(wx.EVT_TEXT_ENTER, self.OnSearch) self.recreateTree() # add drop target self.SetDropTarget(MyFileDropTarget(self)) # self.tree.SetExpansionState(self.expansionState) self.tree.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded) self.tree.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed) self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged) self.tree.Bind(wx.EVT_LEFT_DOWN, self.OnTreeLeftDown) self.tree.Bind(wx.EVT_LEFT_DCLICK, self.OnTreeDoubleclick) self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.onTreeItemActivated) self.tree.Bind(wx.EVT_TREE_KEY_DOWN, self.onTreeKeyDown) self.tree.Bind(wx.EVT_TREE_BEGIN_DRAG, self.onTreeBeginDrag) self.tree.Bind(wx.EVT_RIGHT_DOWN, self.OnTreeRightDown) self.tree.Bind(wx.EVT_RIGHT_UP, self.OnTreeRightUp) # self.tree.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown, self) #################################################################### vBox.Add(self.filter , 0, wx.EXPAND | wx.ALL) vBox.Add(self.tree , 1, wx.EXPAND | wx.ALL) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(vBox, 1, wx.EXPAND , 0) self.SetSizer(sizer)
def onDeleteTable(self, event): logger.debug('onDeleteTable') try: # data = self.tree.GetPyData(self.tree.GetSelection()).Data depth = self.tree.GetItemData(self.tree.GetSelection())['depth'] ################################################################################## sqlExecuter = SQLExecuter(database='_opal.sqlite') textCtrl = self.GetTopLevelParent()._ctrl selectedItemText = textCtrl.GetValue() databaseAbsolutePath = sqlExecuter.getDbFilePath(selectedItemText) logger.debug("dbFilePath: %s", databaseAbsolutePath) ################################################################################## # connectionName = data['connection_name'] # databaseAbsolutePath = data['db_file_path'] if os.path.isfile(databaseAbsolutePath) and depth == 3: text = "DROP TABLE '{}'".format(self.tree.GetItemText(self.tree.GetSelection())) dbObjects = ManageSqliteDatabase(connectionName=selectedItemText , databaseAbsolutePath=databaseAbsolutePath).executeText(text) self.recreateTree(event) except Exception as e: logger.error(e, exc_info=True)
def __init__(self, parent, model=None, data=None): gridlib.Grid.__init__(self, parent, -1) self.CreateGrid(0, 0) # Somebody changed the grid so the type registry takes precedence # over the default attribute set for editors and renderers, so we # have to set null handlers for the type registry before the # default editor will get used otherwise... # self.RegisterDataType(wxGRID_VALUE_STRING, None, None) # self.SetDefaultEditor(MyCellEditor()) # Or we could just do it like this: # self.RegisterDataType(wx.GRID_VALUE_STRING, # wx.GridCellStringRenderer(), # MyCellEditor()) # ) # but for this example, we'll just set the custom editor on one cell # self.SetCellEditor(1, 0, MyCellEditor()) # self.SetCellValue(1, 0, "Try to edit this box") # # # and on a column # attr = gridlib.GridCellAttr() # attr.SetEditor(MyCellEditor()) # self.SetColAttr(2, attr) # self.SetCellValue(1, 2, "or any in this column") # # self.SetColSize(0, 150) # self.SetColSize(1, 150) # self.SetColSize(2, 150) sqlExecuter = SQLExecuter(database='_opal.sqlite') sqlText='select * from sql_log order by created_time desc;' sqlOutput = sqlExecuter.executeText(sqlText) if sqlOutput: self.addData(data=sqlOutput)
logger.error(e, exc_info=True) elif tabName == 'ER diagram': resultPanel = wx.Panel() return resultPanel, toolbar def findingConnectionName(self): ''' This method defines connection name based on selected connection in the tree. @return: (connectionName, databaseAbsolutePath) ''' ################################################################################## sqlExecuter = SQLExecuter(database='_opal.sqlite') textCtrl = self.GetTopLevelParent()._ctrl connectionName = textCtrl.GetValue() databaseAbsolutePath = sqlExecuter.getDbFilePath(connectionName) logger.debug("databaseAbsolutePath: %s", databaseAbsolutePath) ################################################################################## return connectionName, databaseAbsolutePath if __name__ == '__main__': app = wx.App(False) sqlExecuter = SQLExecuter(database='_opal.sqlite') frame = CreatingTableInfoFrame(None, 'Open Existing Connection', dataSourceTreeNode=None) frame.Show() app.MainLoop()
def createDefaultNode(self): logger.debug("TreePanel.createDefaultNode") sqlExecuter = SQLExecuter() dbList = sqlExecuter.getListDatabase() fullSearch = False expansionState = self.tree.GetExpansionState() current = None item = self.tree.GetSelection() if item: prnt = self.tree.GetItemParent(item) if prnt: current = (self.tree.GetItemText(item), self.tree.GetItemText(prnt)) self.tree.Freeze() self.tree.DeleteAllItems() self.root = self.tree.AddRoot("Connections") self.tree.SetItemImage(self.root, 0) data = dict() data['depth'] = 0 self.tree.SetItemData(self.root, data) treeFont = self.tree.GetFont() catFont = self.tree.GetFont() # The native treectrl on MSW has a bug where it doesn't draw # all of the text for an item if the font is larger than the # default. It seems to be clipping the item's label as if it # was the size of the same label in the default font. if 'wxMSW' not in wx.PlatformInfo: treeFont.SetPointSize(treeFont.GetPointSize() + 2) treeFont.SetWeight(wx.BOLD) catFont.SetWeight(wx.BOLD) self.tree.SetItemFont(self.root, treeFont) firstChild = None selectItem = None filter = self.filter.GetValue() count = 0 for db in dbList: data = dict() data['depth'] = 1 data['connection_name'] = db[1] data['db_file_path'] = db[2] if db[3] == 3: image = 17 elif db[3] == 1: image = 16 # elif db[3]==1: # image=16 # Appending connections item=self.addNode(targetNode=self.root, nodeLabel=db[1], pydata=data, image=image) # self.connDict[db[1]]['itemId']=item if db[1] in self.connDict.keys(): self.getNodeOnOpenConnection(selectedItemId=item) # for key, value in self.connDict.items(): # if value['isConnected']: # logger.debug("{}:{}".format(key, value)) self.tree.Expand(self.root) if firstChild: self.tree.Expand(firstChild) # if filter: # self.tree.ExpandAll() if expansionState: self.tree.SetExpansionState(expansionState) if selectItem: self.skipLoad = True self.tree.SelectItem(selectItem) self.skipLoad = False