标签:
pyqt5
python
|
分类:
PyQt5
|
本文在上文的基础上重新实现支持多线程的服务器。
以下为TCP客户端的程序代码:
#!/usr/bin/env python3
import sys
from PyQt5.QtCore import (QByteArray, QDataStream, QDate,
QIODevice,
QRegExp, Qt)
from PyQt5.QtWidgets import (QApplication, QDateEdit, QFrame,
QGridLayout,
QHBoxLayout, QLabel,
QLineEdit, QPushButton,
QWidget)
from PyQt5.QtGui import QRegExpValidator
from PyQt5.QtNetwork import (QTcpSocket,)
MAC = True
try:
from PyQt5.QtGui import
qt_mac_set_native_menubar
except ImportError:
MAC = False
PORT = 9407
SIZEOF_UINT16 = 2
class BuildingServicesClient(QWidget):
def __init__(self, parent=None):
&
(2017-04-28 13:50)
标签:
pyqt5
python
|
分类:
PyQt5
|
本文在上文的基础上重新实现支持多线程的服务器。
以下为TCP客户端的程序代码:
本文通过python3+PyQt5实现《python Qt GUI快速编程》第18章的例子Building Services
application。本例分别创建一个TCP客户端和TCP服务器,采用PyQt的QtNetwork模块,而不是Python标准库或Twisted网络引擎。
以下为TCP客户端的程序代码:
#!/usr/bin/env python3
import sys
from PyQt5.QtCore import (QByteArray, QDataStream, QDate,
QIODevice,
QRegExp, Qt)
from PyQt5.QtWidgets import (QApplication, QDateEdit, QFrame,
QGridLayout,
QHBoxLayout, QLabel, QLineEdit, QPushButton,
&
(2017-04-19 14:44)
标签:
pyqt5
python
|
分类:
PyQt5
|
本文通过python3+pyqt5改写实现了python Qt gui 编程变成15章的excise例子。
#!/usr/bin/env python3
import os
import sys
from PyQt5.QtCore import (QFile, QVariant, Qt)
from PyQt5.QtWidgets import (QApplication, QDialog,
QDialogButtonBox, QMenu,
QMessageBox, QTableView,
QVBoxLayout)
from PyQt5.QtSql import (QSqlDatabase, QSqlQuery,
QSqlTableModel)
MAC = True
try:
from PyQt5.QtGui import
qt_mac_set_native_menubar
except ImportError:
MAC = False
ID, CATEGORY, SHORTDESC, LONGDESC = range(4)
class ReferenceDataDlg(QDialog):
def __init__(self, parent=None):
super(ReferenceDataDlg,
self).__init__(parent)
self.model =
QSqlTableModel(self)
(2017-04-18 09:04)
标签:
pyqt5
python
|
分类:
PyQt5
|
本文通过将创建自定义模型保存船只数据,并会用两个不同的表格视图形式来显示同样的模型。
实现自定义模型,继承QAbstractTableModel,具体参照QT库。
/home/yrd/eric_workspace/chap14/ships_model/ships.py
#!/usr/bin/env python3
import platform
from PyQt5.QtCore import (QAbstractTableModel, QDataStream,
QFile,
QIODevice,
QModelIndex,QVariant, Qt,pyqtSignal)
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QApplication
NAME, OWNER, COUNTRY, DESCRIPTION, TEU = range(5)
MAGIC_NUMBER = 0x570C4
FILE_VERSION = 1
class Ship(object):
def __init__(self, name, owner, country, teu=0,
description=''):
self.name = name
self.owner = owner
&nb
(2017-01-23 15:43)
标签:
pyqt5
python
|
分类:
PyQt5
|
本文是用Python3+PyQt5进行改写《Python Qt
GUI快速编程》的第9章的练习题实现Tab标签页式编辑器。
注:import qrc_resources,资源文件resources.qrc如下:
http://s1/mw690/003ytqMFzy78bzZLtks20&690
sudo pyrcc5 -o qrc_resources.py resources.qrc
生成qrc_resources.py
/home/yrd/eric_workspace/chap09/textedit.py
from PyQt5.QtCore import (QFile, QFileInfo, QIODevice,
QTextStream, Qt)
from PyQt5.QtWidgets import (QFileDialog, QMessageBox,
QTextEdit)
class TextEdit(QTextEdit):
NextId = 1
def __init__(self, filename='',
parent=None):
(2017-01-22 16:18)
标签:
pyqt5
python
|
分类:
PyQt5
|
本文是对《Python Qt
GUI快速编程》的第9章的多文档界面的例子texteditor用Python3+PyQt5进行改写。
注:import qrc_resources,资源文件resources.qrc如下:
http://s1/mw690/003ytqMFzy78bzZLtks20&690
sudo pyrcc5 -o qrc_resources.py resources.qrc
生成qrc_resources.py
/home/yrd/eric_workspace/chap09/textedit.py
from PyQt5.QtCore import (QFile, QFileInfo, QIODevice,
QTextStream, Qt)
from PyQt5.QtWidgets import (QFileDialog, QMessageBox,
QTextEdit)
class TextEdit(QTextEdit):
NextId = 1
def __init__(self, filename='',
parent=None):
super(TextEdi
(2017-01-20 14:40)
标签:
pyqt5
python
|
分类:
PyQt5
|
本文是对《Python Qt GUI快速编程》的第9章的窗口切分条例子News Reader
用Python3+PyQt5进行改写。
注:import qrc_resources,资源文件resources.qrc如下:
===========================
images/icon.png
images/filenew.png
images/fileopen.png
images/filesave.png
images/filesaveas.png
images/filequit.png
images/filequit.png
images/editcut.png
images/editcopy.png
images/editpaste.png
images/editadd.png
images/editedit.png
images/editdelete.png
======
sudo pyrcc5 -o qrc_resources.py resources.qrc
生成qrc_resources.py
import sys
from PyQt5.QtCore import (QSettings, Qt,QByteArray)
from PyQt5.QtWidgets import (QAction, QApplication,
QListWidget,
QMainWindow, Q
(2017-01-17 16:16)
标签:
pyqt5
python
qtdesigner
|
分类:
PyQt5
|
本文是对《Python Qt GUI快速编程》的第9章的堆叠窗口例子Vehicle
Rental用Python3+PyQt5+Qt Designer进行改写。
第一部分无借用Qt Designer,完全用代码实现。
第二部分则借用Qt Designer,快速实现。
第一部分:
import sys
from PyQt5.QtCore import (Qt)
from PyQt5.QtWidgets import (QApplication, QComboBox,
QDialog,
QDialogButtonBox,
QFrame, QGridLayout, QHBoxLayout, QLabel,
QSpinBox,
QStackedWidget, QVBoxLayout, QWidget)
class VehicleRentalDlg(QDialog):
def __init__(self, parent=None):
super(VehicleRentalDlg,
self).__init__(parent)
vehicleLabel =
QLabel('&Vehicle Type:')
self.vehicleComboBox =
QComboBox()
&nb
(2017-01-17 10:28)
标签:
python
pyqt5
qtdesigner
|
分类:
PyQt5
|
本文是对《Python Qt GUI快速编程》的第9章的Tab标签页窗口的例子payment
form用Python3+PyQt5+Qt Designer进行改写。
第一部分无借用Qt Designer,完全用代码实现。
第二部分则借用Qt Designer,快速实现。
import sys
from PyQt5.QtCore import (QDate, Qt)
from PyQt5.QtWidgets import (QApplication, QCheckBox, QDateEdit,
QDialog,
QDialogButtonBox,
QDoubleSpinBox, QGridLayout, QHBoxLayout,
QLabel, QLineEdit,
QSpinBox, QTabWidget, QVBoxLayout, QWidget)
class PaymentDlg(QDialog):
def __init__(self, parent=None):
super(PaymentDlg,
self).__init__(parent)
forenameLabel =
QLabel('&Forename:')
&nbs
(2017-01-15 10:24)
标签:
pyqt5
python
|
分类:
PyQt5
|
本文基于PyQt对XML文件进行保存和加载,保存为xml依然使用QTextStream的方式,但解析XML文件则通过两种方式:DOM和SAX。两者的区别是前者适合编辑文档结构,后者采用递归工作方式,适用于XML文档的搜索和处理。
下例通过QTextStream将不同类型的数据保存为XML格式如下:
from PyQt5.QtCore import QFile, QFileInfo,
QIODevice,QTextStream
from PyQt5.QtXml import (QDomDocument, QDomNode,
QXmlDefaultHandler,
QXmlInputSource, QXmlSimpleReader)
import datetime
CODEC = 'UTF-8'
NEWPARA = chr(0x2029)
NEWLINE = chr(0x2028)
def encodedNewlines(text):
return text.replace('\n\n',
NEWPARA).replace('\n', NEWLINE)
def decodedNewlines(te