当前位置: 首页>>代码示例>>Python>>正文


Python DataBase.open方法代码示例

本文整理汇总了Python中database.DataBase.open方法的典型用法代码示例。如果您正苦于以下问题:Python DataBase.open方法的具体用法?Python DataBase.open怎么用?Python DataBase.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在database.DataBase的用法示例。


在下文中一共展示了DataBase.open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CategoryParam

# 需要导入模块: from database import DataBase [as 别名]
# 或者: from database.DataBase import open [as 别名]
class CategoryParam(QDialog):
	def __init__(self, parent=None):
		QDialog.__init__(self)

		self.categoryParam = Ui_CatParam()
		self.categoryParam.setupUi(self)

		self.showParam()

		self.connect(self.categoryParam.btnSet,SIGNAL('clicked()'),self.setParam)
		self.connect(self.categoryParam.btnDefault,SIGNAL('clicked()'),self.setDefault)
	def setDefault(self):
		conn = sqlite3.connect('dakar.sqlite')
		cursor = conn.cursor()

		query = "UPDATE category set minRange ='0' ,maxRange ='50' where id = 1"
		cursor.execute(query)
		query = "UPDATE category set minRange ='51' ,maxRange ='99' where id = 2"
		cursor.execute(query)
		query = "UPDATE category set minRange ='100' ,maxRange ='200' where id = 3"
		cursor.execute(query)
		conn.commit()

		self.showParam()

	def setParam(self):
		conn = sqlite3.connect('dakar.sqlite')
		cursor = conn.cursor()

		minMoto = self.categoryParam.lnMinMoto.text()
		maxMoto = self.categoryParam.lnMaxMoto.text()
		minQuad = self.categoryParam.lnMinQuad.text()
		maxQuad = self.categoryParam.lnMaxQuad.text()
		minCar = self.categoryParam.lnMinCar.text()
		maxCar = self.categoryParam.lnMaxCar.text()

		query = "UPDATE category set minRange ='%i' ,maxRange ='%i' where id = 1"%(int(minMoto),int(maxMoto))
		cursor.execute(query)
		query = "UPDATE category set minRange ='%i' ,maxRange ='%i' where id = 2"%(int(minQuad),int(maxQuad))
		cursor.execute(query)
		query = "UPDATE category set minRange ='%i' ,maxRange ='%i' where id = 3"%(int(minCar),int(maxCar))
		cursor.execute(query)
		conn.commit()

		self.showParam()
	def showParam(self):
		self.db = DataBase()
		self.db.open('dakar.sqlite')
		rows = self.db.get_category()

		self.categoryParam.lnMinMoto.setText(str(rows[0][2]))
		self.categoryParam.lnMaxMoto.setText(str(rows[0][3]))
		self.categoryParam.lnMinQuad.setText(str(rows[1][2]))
		self.categoryParam.lnMaxQuad.setText(str(rows[1][3]))
		self.categoryParam.lnMinCar.setText(str(rows[2][2]))
		self.categoryParam.lnMaxCar.setText(str(rows[2][3]))
开发者ID:rbistolfi,项目名称:gps-tracking,代码行数:58,代码来源:classCategoryParam.py

示例2: EditZone

# 需要导入模块: from database import DataBase [as 别名]
# 或者: from database.DataBase import open [as 别名]
class EditZone(QDialog):
	def __init__(self, parent=None):
		QDialog.__init__(self)

		self.editZone = Ui_editZone()
		self.editZone.setupUi(self)
		self.conn = None
		self.cursor = None
		self.db = DataBase()
		self.db.open('dakar.sqlite')

		self.createTable()
		self.connect(self.editZone.btnDeleteZone,SIGNAL('clicked()'),self.deleteZone)
		self.connect(self.editZone.btnAdd,SIGNAL('clicked()'),self.addZone)

	def deleteZone(self):
		self.editZone.lnNumZone.setText("1")
		self.db.deleteZone()
		self.createTable()		

	def createTable(self):
		
		rows = self.db.getZone()
		self.editZone.tblZone.setRowCount(len(rows))
		for i,table in enumerate(rows):
			for m,data in enumerate(table):
				if m != 0:
					self.editZone.tblZone.setItem(i,m - 1,QTableWidgetItem(str(data)))
					self.editZone.tblZone.resizeColumnsToContents()
					self.editZone.tblZone.resizeRowsToContents()
			
		
			pass
	def addZone(self):
		valueZone = self.editZone.lnZone.text()
		numZone = self.editZone.lnNumZone.text()
		tmpZone = int(numZone) + 1
		self.db.insertZone(numZone,valueZone)
		self.editZone.lnNumZone.setText(str(tmpZone))
		self.editZone.lnZone.setText("")
		self.createTable()
开发者ID:rbistolfi,项目名称:gps-tracking,代码行数:43,代码来源:classEditZone.py

示例3: Principal

# 需要导入模块: from database import DataBase [as 别名]
# 或者: from database.DataBase import open [as 别名]
class Principal(QMainWindow):
	def __init__(self):
		QMainWindow.__init__(self)
		self.conn = None
		self.cursor = None
		self.minMoto = 0
		self.maxMoto = 0
		self.minQuad = 0
		self.maxQuad = 0
		self.minCar = 0
		self.maxCar = 0
		self.tmpCountFile = []
		self.countZone = []
		self.mainWindow = Ui_MainWindow()
		self.mainWindow.setupUi(self)
		self.db = DataBase()
		self.db.open('dakar.sqlite')
		
		self.countZones()
		self.countVehicles()
		self.path()
		self.mainTable()
		#self.inputFiles()

		
		self.mainWindow.tblData.resizeRowsToContents()
		self.mainWindow.tblData.setColumnWidth(1, 70)
		self.mainWindow.lblWpt.setAlignment(Qt.AlignHCenter)
		self.mainWindow.lblDz.setAlignment(Qt.AlignHCenter)

		self.ctimer = QTimer()
		self.ctimer.start(10000)
		self.mainWindow.actionCategory.triggered.connect(self.openCategoryWindow)
		self.mainWindow.actionDirectoryPath.triggered.connect(self.searchPath)
		self.mainWindow.actionEditZone.triggered.connect(self.openEditZone)
		self.mainWindow.actionDeleteData.triggered.connect(self.deleteData)

		self.connect(self.ctimer,SIGNAL("timeout()"), self.checkNewFile)
		self.mainWindow.tblGralStatus.cellClicked.connect(self.otherTable)
		self.mainWindow.tblGralStatus.cellChanged.connect(self.saveCell)
		self.connect(self.mainWindow.btnExit,SIGNAL('clicked()'),self.exit)

	def path(self):
		f = open('path.txt')
		path = f.readline()
		self.mainWindow.lblPath.setText("Current Path: " + path)

	def exit(self):
		exit()

	def countZones(self):
		check = self.db.countZone()
		for i in check:
			self.countZone.append(i[0])
	
	def mainTable(self):
		"""Show the main table. Search data from sqlite
		"""
		rows = self.db.get_tables()
		self.mainWindow.tblGralStatus.setRowCount(len(rows))

		for i,table in enumerate(rows):
			for m,data in enumerate(table):
				if m != 0:
					self.mainWindow.tblGralStatus.setItem(i,m - 1,QTableWidgetItem(str(data).decode("utf-8")))
					if str(data) == 'OK':
						color = QColor(133, 222, 84)
					elif str(data) == 'NOK':
						color = QColor(255, 64, 16)
					else:
						color = QColor("white")
					self.mainWindow.tblGralStatus.item(i, m - 1).setBackground(QColor(color))
					self.mainWindow.tblGralStatus.item(i, m - 1).setTextAlignment(Qt.AlignCenter)
		self.mainWindow.tblGralStatus.resizeColumnsToContents()
		self.mainWindow.tblGralStatus.resizeRowsToContents()
		self.mainWindow.tblGralStatus.setColumnWidth(1,100)
		self.mainWindow.tblGralStatus.setColumnWidth(10,308)	
		self.mainWindow.tblGralStatus.setSortingEnabled(True)
		
				

	def openCategoryWindow(self):
		"""Open the windows who´s conteins the parameter of category
		"""
		mainWindow = CategoryParam().exec_()

	def openEditZone(self):
		mainWindow = EditZone().exec_()

	def searchPath(self):
		"""Search the path where are the files .csv
		"""
		dir_ = QFileDialog.getExistingDirectory(None, 'Select a folder:', 'C:\\', QFileDialog.ShowDirsOnly)
		f = open('path.txt','w')
		f.write(dir_)
		f.close()
		self.mainWindow.lblPath.setText("Current Path: " + dir_)
		self.inputFiles()
	
	def inputFiles(self):
#.........这里部分代码省略.........
开发者ID:rbistolfi,项目名称:gps-tracking,代码行数:103,代码来源:run.py


注:本文中的database.DataBase.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。