📄 runqt23.py
字号:
#!/usr/bin/env python
# -*- coding: gb2312 -*-
#########3
import sys
from qt import *
#import gadfly
import sqlite
from qt23 import Form1
import connect23
ConnectDialog=connect23.Form1
from dbpar import *
import operator
TRUE = 1
FALSE = 0
def showError(err, parent):
errStr = QString("The database reported an error:\n\n")
if not err.databaseText().isEmpty():
errStr.append(err.databaseText())
errStr.append("\n")
if not err.driverText().isEmpty():
errStr.append(err.driverText())
errStr.append("\n")
QMessageBox.warning(parent, "Error", errStr)
class MainWindow(Form1):
def __init__(self,parent = None,name = None,fl = 0):
self.database=None
Form1.__init__(self,parent,name,fl)
self.conDiag = ConnectDialog(self, "Connection Dialog", TRUE)
##~ self.firstconn = TRUE
self.connect(self.PushButton1,SIGNAL("clicked()"),self.refreshtable)
self.connect(self.PushButton3,SIGNAL("clicked()"),self.dbConnect)
self.connect(self.PushButton2,SIGNAL("clicked()"),self.execQuery)
self.connect(self.ListView1,SIGNAL("doubleClicked(QListViewItem*)"),self.showTable)
self.PushButton2.setEnabled(FALSE)
def dbConnect(self):
if self.conDiag.exec_loop() != QDialog.Accepted:
return
if self.database!=None:
self.database.close()
# open the new connection
directory=str(self.conDiag.leDir.text())
db=str(self.conDiag.leDb.text())
self.database =sqlite.connect(directory+"\\"+db)
self.TextLabel1.setText("Double-Click on a table-name to view the contents")
self.refreshtable()
self.PushButton2.setEnabled(TRUE)
#self.connect(self.pushButton4,SIGNAL("clicked()"),self.refreshTable)
def refreshtable(self):
self.ListView1.clear()
cur=self.database.cursor()
cur.execute("select tbl_name from sqlite_master where type='table' order by tbl_name")
tables = []
for row in cur.fetchall():
tables.append(row.tbl_name)
for t in tables:
lvi = QListViewItem(self.ListView1, t)
self.ListView1.insertItem(lvi)
def execQuery(self):
curs = self.database.cursor()
curs.execute(str(self.MultiLineEdit1.text()))
self.pp(curs)
self.database.commit()
def showTable(self, item):
i = item.parent()
if not i:
i = item
print i.text(0)
self.MultiLineEdit1.clear()
self.MultiLineEdit1.append("select * from "+str(i.text(0)))
self.execQuery()
def pp(self,cursor):
try:
rows = cursor.fetchall()
except:
return "No description"
desc = cursor.description
self.Table1.setNumCols(len(desc))
self.Table1.setNumRows(len(rows)+1)
i=0
n=len(desc)
while i<n:
self.Table1.setText(0,i,QString(desc[i][0]))
i=i+1
i=0
n=len(desc)
m=len(rows)
while i<m:
print "i"
print i
print rows[i]
j=0
while j<n:
print "j"
print j
print rows[i][j]
self.Table1.setText(i+1,j,QString(str(rows[i][j])))
j=j+1
i=i+1
return ''
if __name__ == "__main__":
a = QApplication(sys.argv)
QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
w = MainWindow()
a.setMainWidget(w)
w.show()
a.exec_loop()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -