def simpleQuery(query): textbrowser=QTextBrowser() db=database.mysql_handler("project","localhost","root","alse") result=db.query(query) resultstr="" resultstr=resultstr.__add__("<table style='background-color:gray'>") for i in result: resultstr=resultstr.__add__("<tr>") for j in i: resultstr=resultstr.__add__("<td style='padding:5px'><a style='color:white'>%s</a></td>"%j) resultstr=resultstr.__add__("</tr>") resultstr=resultstr.__add__("</table>") textbrowser.append(resultstr) hbox=QHBoxLayout() hbox.addStretch(1) hbox.addWidget(textbrowser) return textbrowser
from __future__ import division from PyQt4.QtCore import * from PyQt4.QtGui import * import sys import os import subprocess from math import * #check whether the path has already been added if sys.path.count(os.getcwd())==0: sys.path.append(os.getcwd()) import database #this is from current directory db=database.mysql_handler("project","localhost","root","alse") print db.query("select * from user_info") db2=database.mysql_handler("ci_doctrine","localhost","root","alse") print db2.query("show tables") class Form(QDialog): def __init__(self,parent=None): super(Form,self).__init__(parent) self.browser=QTextBrowser() self.lineedit=QLineEdit("type command and press Enter") self.lineedit.selectAll() layout=QBoxLayout(QBoxLayout.BottomToTop) layout.addWidget(self.browser) layout.addWidget(self.lineedit) self.setLayout(layout) self.lineedit.setFocus() self.connect(self.lineedit,SIGNAL("returnPressed()"),self.updateUi) self.setWindowTitle("Shell") def updateUi(self): if unicode(self.lineedit.text())=="clear": self.browser.setText("")