#                            PyQt4 HardwareManager
# 声明:
# 本软件主要是由于朋友说想要一个产品缺陷记录软件,主要用于记录产品缺陷,
# 通过产品序列号进行插入、查询,本来想用VC++ 6.0做,但是每次打开开发环境就
# 奔溃了,所以只能换一个开发环境,于是尝试用PyQt4进行原型开发,在开发过程中
# 发现,这确实是一个很好的思路,该软件可以换一种思路用于其他环境下,但就
# 目前而已,这仅仅是一个原型。
#
# 2015-10-23 晴 深圳 南山平山村 曾剑锋 \\\\\\\\\\\\\-*- 目录 -*-////////////
| 一、cat main.pyw
| 二、cat HardwareDialog.pyw
| 三、cat Ui_HardwareManager.pyw
| 四、cat hardwaremanager.ui
| 五、cat autorun.bat
| 六、cat readme.txt
------------------------------------ 一、cat main.pyw
#coding=utf-8 # 参考文章:
# 1. pyqt 使用 Qt Designer 设计的ui文件
# http://blog.csdn.net/lainegates/article/details/8656145
# 2. PyQt 4.11.4 Reference Guide Using Qt Designer
# http://pyqt.sourceforge.net/Docs/PyQt4/designer.html
# 3. Create dynamic button in PyQt
# http://stackoverflow.com/questions/10730131/create-dynamic-button-in-pyqt
# 4. How can I hide the console window in a PyQt app running on Windows?
# http://stackoverflow.com/questions/466203/how-can-i-hide-the-console-window-in-a-pyqt-app-running-on-windows
# 5. pyqt如何关闭dos窗口
# http://www.wosoni.com/osk/230860_91298.html import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import * from HardwareDialog import HardwareDialog def main(): app = QApplication(sys.argv)
app.setWindowIcon(QIcon("./logo.ico")) hardwareDialog = HardwareDialog()
hardwareDialog.show() sys.exit(app.exec_()) if __name__ == '__main__':
main() 二、cat HardwareDialog.pyw
#coding=utf-8 import sys
import os
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sqlite3 from ui_hardwaremanager import Ui_HardwareManager class HardwareDialog(QDialog): def __init__(self): QDialog.__init__(self) self.ui = Ui_HardwareManager()
self.ui.setupUi(self) self.setWindowTitle("HardwareManager")
self.setFixedHeight(self.height())
self.setFixedWidth(self.width())
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint); # http://stackoverflow.com/questions/10730131/create-dynamic-button-in-pyqt
# Error: TypeError: connect() slot argument should be a callable or a signal, not 'NoneType' #
# Note the lambda will avoid the evaluation of the function call, so it'll call
# self.commander(command) only when clicked
# self.ui.insert.clicked.connect(lambda: self.insertData())
self.ui.insert.clicked.connect(self.insertData)
self.ui.query.clicked.connect(self.queryData)
self.ui.clean.clicked.connect(self.cleanData) self.cpFilePath = "" def insertData(self): # 这里必须这么处理一下才能将serial插入sqlite3数据,否则总是会报如下错误:
# sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
serial = ("%s" % (self.ui.serial.text())).strip()
filePath = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time())) # To prevent the string length is less than 0
if ( len(serial) > 0 ) : hmConnect = sqlite3.connect("./HardwareManager.db")
cursor = hmConnect.cursor() cursor.execute('CREATE TABLE if not exists HardwareManager (id INTEGER PRIMARY KEY, serial VARCHAR(40), path VARCHAR(100))') # check serial NO. was only one
cursor.execute('SELECT id, path from HardwareManager where serial = ?', [serial])
if ( cursor.fetchone() != None ) :
QMessageBox.about(self, "ERROR","Please check the serial number is the only one")
hmConnect.close()
return # insert data
argument=(serial, filePath)
cursor.execute('INSERT INTO HardwareManager (id, serial, path) VALUES(NULL, ?, ?)', argument)
hmConnect.commit() # save readme data
readmeFilePath = "./managerFile/%s" % filePath
os.makedirs(readmeFilePath)
readme = open( "%s/readme.txt" % readmeFilePath, "w" )
readme.write(self.ui.readme.toPlainText())
readme.flush()
readme.close() self.ui.id.setText( "%s" % cursor.lastrowid )
self.ui.path.setText("%s/readme.txt" % readmeFilePath) ## debug
#print argument
#cursor.execute('SELECT * FROM HardwareManager')
#print cursor.fetchall() hmConnect.close() # mesage for costomer
QMessageBox.about(self, "Mesg","Insert OK.") def queryData(self): serial = ("%s" % (self.ui.serial.text())).strip() if ( len(serial) > 0 ) : hmConnect = sqlite3.connect("./HardwareManager.db")
cursor = hmConnect.cursor() # create data if HardwareManager table don't exists
cursor.execute('CREATE TABLE if not exists HardwareManager (id INTEGER PRIMARY KEY, serial VARCHAR(40), path VARCHAR(100))') # check data
cursor.execute('SELECT id, path from HardwareManager where serial = ?', [serial])
row = cursor.fetchone()
if ( row == None ) :
QMessageBox.about(self, "ERROR","Please check your serial number")
hmConnect.close()
return self.ui.id.setText( "%s" % row[0] )
self.ui.path.setText( "./managerFile/%s/readme.txt" % row[1] ) # maybe this file has lost
if ( os.path.exists("./managerFile/%s/readme.txt" % row[1]) == True) :
readme = open( "./managerFile/%s/readme.txt" % row[1] )
self.ui.readme.setPlainText(readme.read())
readme.close()
else :
QMessageBox.about(self, "Mesg","can't find the readme.txt file") hmConnect.close() def cleanData(self): '''
clean EditLine widget data
''' self.ui.id.setText("")
self.ui.serial.setText("")
self.ui.path.setText("")
self.ui.readme.setPlainText("") 三、cat Ui_HardwareManager.pyw
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'E:\python\HardWareManager\hardwaremanager.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig) class Ui_HardwareManager(object):
def setupUi(self, HardwareManager):
HardwareManager.setObjectName(_fromUtf8("HardwareManager"))
HardwareManager.resize(465, 300)
self.verticalLayout_2 = QtGui.QVBoxLayout(HardwareManager)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.frame = QtGui.QVBoxLayout()
self.frame.setObjectName(_fromUtf8("frame"))
self.serialIDPath = QtGui.QGridLayout()
self.serialIDPath.setSizeConstraint(QtGui.QLayout.SetNoConstraint)
self.serialIDPath.setContentsMargins(20, -1, -1, -1)
self.serialIDPath.setHorizontalSpacing(30)
self.serialIDPath.setObjectName(_fromUtf8("serialIDPath"))
self.label_path = QtGui.QLabel(HardwareManager)
self.label_path.setAlignment(QtCore.Qt.AlignCenter)
self.label_path.setObjectName(_fromUtf8("label_path"))
self.serialIDPath.addWidget(self.label_path, 5, 0, 1, 1)
self.label_id = QtGui.QLabel(HardwareManager)
self.label_id.setAlignment(QtCore.Qt.AlignCenter)
self.label_id.setObjectName(_fromUtf8("label_id"))
self.serialIDPath.addWidget(self.label_id, 2, 0, 1, 1)
self.pathClean = QtGui.QHBoxLayout()
self.pathClean.setObjectName(_fromUtf8("pathClean"))
self.path = QtGui.QLineEdit(HardwareManager)
self.path.setObjectName(_fromUtf8("path"))
self.pathClean.addWidget(self.path)
self.clean = QtGui.QPushButton(HardwareManager)
self.clean.setObjectName(_fromUtf8("clean"))
self.pathClean.addWidget(self.clean)
self.serialIDPath.addLayout(self.pathClean, 5, 1, 1, 1)
self.label_serial = QtGui.QLabel(HardwareManager)
self.label_serial.setAlignment(QtCore.Qt.AlignCenter)
self.label_serial.setObjectName(_fromUtf8("label_serial"))
self.serialIDPath.addWidget(self.label_serial, 1, 0, 1, 1)
self.serial = QtGui.QLineEdit(HardwareManager)
self.serial.setObjectName(_fromUtf8("serial"))
self.serialIDPath.addWidget(self.serial, 1, 1, 1, 1)
self.id = QtGui.QLineEdit(HardwareManager)
self.id.setObjectName(_fromUtf8("id"))
self.serialIDPath.addWidget(self.id, 2, 1, 1, 1)
self.frame.addLayout(self.serialIDPath)
self.insertQueryButton = QtGui.QHBoxLayout()
self.insertQueryButton.setObjectName(_fromUtf8("insertQueryButton"))
self.insert = QtGui.QPushButton(HardwareManager)
self.insert.setObjectName(_fromUtf8("insert"))
self.insertQueryButton.addWidget(self.insert)
self.query = QtGui.QPushButton(HardwareManager)
self.query.setObjectName(_fromUtf8("query"))
self.insertQueryButton.addWidget(self.query)
self.frame.addLayout(self.insertQueryButton)
self.readme = QtGui.QPlainTextEdit(HardwareManager)
self.readme.setObjectName(_fromUtf8("readme"))
self.frame.addWidget(self.readme)
self.verticalLayout_2.addLayout(self.frame) self.retranslateUi(HardwareManager)
QtCore.QMetaObject.connectSlotsByName(HardwareManager)
HardwareManager.setTabOrder(self.serial, self.id)
HardwareManager.setTabOrder(self.id, self.path)
HardwareManager.setTabOrder(self.path, self.insert)
HardwareManager.setTabOrder(self.insert, self.query)
HardwareManager.setTabOrder(self.query, self.readme)
HardwareManager.setTabOrder(self.readme, self.clean) def retranslateUi(self, HardwareManager):
HardwareManager.setWindowTitle(_translate("HardwareManager", "HardwareManager", None))
self.label_path.setText(_translate("HardwareManager", "Path:", None))
self.label_id.setText(_translate("HardwareManager", "ID:", None))
self.clean.setText(_translate("HardwareManager", "Clean", None))
self.label_serial.setText(_translate("HardwareManager", "Serial NO.:", None))
self.insert.setText(_translate("HardwareManager", "Insert", None))
self.query.setText(_translate("HardwareManager", "Query", None)) 四、cat hardwaremanager.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HardwareManager</class>
<widget class="QDialog" name="HardwareManager">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>465</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>HardwareManager</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="frame">
<item>
<layout class="QGridLayout" name="serialIDPath">
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<property name="leftMargin">
<number>20</number>
</property>
<property name="horizontalSpacing">
<number>30</number>
</property>
<item row="" column="">
<widget class="QLabel" name="label_path">
<property name="text">
<string>Path:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="" column="">
<widget class="QLabel" name="label_id">
<property name="text">
<string>ID:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="" column="">
<layout class="QHBoxLayout" name="pathClean">
<item>
<widget class="QLineEdit" name="path"/>
</item>
<item>
<widget class="QPushButton" name="clean">
<property name="text">
<string>Clean</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="" column="">
<widget class="QLabel" name="label_serial">
<property name="text">
<string>Serial NO.:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="" column="">
<widget class="QLineEdit" name="serial"/>
</item>
<item row="" column="">
<widget class="QLineEdit" name="id"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="insertQueryButton">
<item>
<widget class="QPushButton" name="insert">
<property name="text">
<string>Insert</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="query">
<property name="text">
<string>Query</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="readme"/>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>
<tabstop>serial</tabstop>
<tabstop>id</tabstop>
<tabstop>path</tabstop>
<tabstop>insert</tabstop>
<tabstop>query</tabstop>
<tabstop>readme</tabstop>
<tabstop>clean</tabstop>
</tabstops>
<resources/>
<connections/>
</ui> 五、cat autorun.bat
start pythonw.exe main.pyw
exit 六、cat readme.txt
一、文件说明:
1. managerFile目录主要是程序生成的信息文件,不要去动它;
2. pyhon2.7目录包含了python2.7、pyqt4的安装文件;
3. autorun.bat是windows的批处理文件,双击运行,会自动main.pyw文件;
4. 所有的.pyw文件是python程序文件;
5. hardwaremanager.ui文件是qt Designer生成的文件,通过pyuic4.bat将ui文件转成ui_hardwaremanager.pyw;
6. logo.ico是程序的ico文件。
二、程序运行说明:
1. 可以通过双击main.pyw文件运行;
2. 可以通过双击autorun.bat文件运行。

PyQt4 HardwareManager的更多相关文章

  1. PyQt4 py2exe 打包 HardwareManager

    #!/usr/bin/env python # -*- coding: UTF-8 -*- # 1. 以下代码保存在HardwareManager项目的目录下,名称叫:setup.py: # 2. 打 ...

  2. PyQt4 ShowHMDB show sqlite3 with QTableWidget summary

    PyQt4 ShowHMDB show sqlite3 with QTableWidget summary Source Code: https://github.com/zengjfgit/Pyth ...

  3. PyQt4入门学习笔记(五)

    PyQt4里的对话框 对话框是大多数GUI应用中不可分割的一部分.一个对话框是两者或多者的会话.在GUI内,对话框是应用向人说话的方式.一个对话框可以用来输入数据,修改数据,改变应用设置等等. QtG ...

  4. PyQt4入门学习笔记(四)

    在PyQt4中的事件和信号 事件 所有的GUI应用都是事件驱动的.事件主要是来自于应用的使用者,但是像互联网连接,窗口管理器或者计时器也可以产生事件.当我们调用应用的exec_()方法时,应用就进入了 ...

  5. PyQt4入门学习笔记(三)

    # PyQt4入门学习笔记(三) PyQt4内的布局 布局方式是我们控制我们的GUI页面内各个控件的排放位置的.我们可以通过两种基本方式来控制: 1.绝对位置 2.layout类 绝对位置 这种方式要 ...

  6. 基于傅里叶变换和PyQt4开发一个简单的频率计数器

    小学期的<信号与系统>课,要求写一个频率计数器,下面是我个人理解的频率计数 傅里叶变换的代码: # coding=utf-8 import numpy as np from scipy.i ...

  7. PyQt4入门学习笔记(二)

    之前第一篇介绍了pyqt4的大小,移动位置,消息提示.这次我们介绍菜单和工具栏 QtGui.QmainWindow这个类可以给我们提供一个创建带有状态栏.工具栏和菜单栏的标准的应用. 状态栏 状态栏是 ...

  8. PyQt4入门学习笔记(一)

    PyQt4入门学习笔记(一) 一直没有找到什么好的pyqt4的教程,偶然在google上搜到一篇不错的入门文档,翻译过来,留以后再复习. 原始链接如下: http://zetcode.com/gui/ ...

  9. PyQt4入门

    PyQt4入门教程(6)_对话框 文中译者的话将用方括号[]标出.对话框(Dialogs)是现代GUI程序中不可缺少的一部分.对话本来指的是两个或者更多人之间的交流,而在计算机应用中,对话是一个可以让 ...

随机推荐

  1. cocos进阶教程(5)CC_CALLBACK_X系列的使用技巧

    CC_CALLBACK_1,CC_CALLBACK_2,CC_CALLBACK_3 这些都是std::bind的宏,数字1,2,3主要表示要占位的数量,也是将来传递参数的数量. // new call ...

  2. vim7.4在Win8下的安装及简单配置

    软件环境 vim74 git vim中文帮助 vundle安装——插件管理软件 cd vim所在路径/vimfiles/bundle git clone https://github.com/gmar ...

  3. Flask添加翻页功能(非sqlalchemy)

    最近做flask的项目,需要增加翻页的功能,网上找的教程都是结合sqlalchemy的,可是我用的不是sqlalchemy,肿木办呢? 以下是我的做法 一.前端 1.传递页码 前端我使用ajax提交表 ...

  4. DLL文件是怎么产生的,DLL文件是什么,DLL文件有什么用

    ①DLL文件是怎么产生的 许多应用程序被分割成一些相对独立的动态链接库,放置于系统中,就产生了DLL文件. ②DLL文件是什么 DLL(Dynamic Link Library)文件为动态链接库文件, ...

  5. java 加密之消息摘要算法

    简介 消息摘要算法的主要特征是加密过程不需要密钥,并且经过加密的数据无法被解密,即单向加密,只有输入相同的明文数据经过相同的消息摘要算法才能得到相同的密文. 消息摘要算法不存在密钥的管理与分发问题,适 ...

  6. IntelliJ idea的初次使用

    1. 首次使用Idea工具,需要安装.我安装的版本是14.0.2.安装包下载地址 http://pan.baidu.com/s/1gfFkrzt 2. 安装SVN. 3.配置JDK. 4.配置mave ...

  7. Mysql优化_ORDER BY和GROUP BY 的优化讲解(单路排序和双路排序)

    ORDER BY 子句尽量使用Index方式排序,避免使用FileSort方式排序,尽可能在索引列上外城排序操作,遵照索引键的最佳左前缀.如果不在索引列上,FileSort有两种算法,Mysql就要启 ...

  8. FromBottomToTop第十三周项目博客

    FromBottomToTop第十三周项目博客 本周项目计划 完成游戏核心算法以及界面相关类和怪物类 项目进展 用户可选择游戏模式,共有20张不同的地图. 炮台的建立和升级. 小怪的路径算法. 参考资 ...

  9. Java,vue.js,jsp for循环的写法

    vue.js <li v-for="student in studentList">{{student.name}}</li> jsp el表达式 < ...

  10. mysql更改数据文件目录及my.ini位置

    步骤: 1.查找my.ini位置,可通过windows服务所对应mysql启动项,查看其对应属性->可执行文件路径,获取my.ini路径. "C:\MySQL\MySQL Server ...