#############################################################################
##
## Copyright (C) 2017 Riverbank Computing Limited.
## Copyright (C) 2006 Thorsten Marek.
## All right reserved.
##
## This file is part of PyQt.
##
## You may use this file under the terms of the GPL v2 or the revised BSD
## license as follows:
##
## "Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions are
## met:
## * Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimer.
## * Redistributions in binary form must reproduce the above copyright
## notice, this list of conditions and the following disclaimer in
## the documentation and/or other materials provided with the
## distribution.
## * Neither the name of the Riverbank Computing Limited nor the names
## of its contributors may be used to endorse or promote products
## derived from this software without specific prior written
## permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
##
#############################################################################
import sys
import logging
import os.path
import re
from xml.etree.ElementTree import parse, SubElement
from .objcreator import QObjectCreator
from .properties import Properties
logger = logging.getLogger(__name__)
DEBUG = logger.debug
QtCore = None
QtWidgets = None
def _parse_alignment(alignment):
""" Convert a C++ alignment to the corresponding flags. """
align_flags = None
for qt_align in alignment.split('|'):
_, qt_align = qt_align.split('::')
align = getattr(QtCore.Qt, qt_align)
if align_flags is None:
align_flags = align
else:
align_flags |= align
return align_flags
def _layout_position(elem):
""" Return either (), (0, alignment), (row, column, rowspan, colspan) or
(row, column, rowspan, colspan, alignment) depending on the type of layout
and its configuration. The result will be suitable to use as arguments to
the layout.
"""
row = elem.attrib.get('row')
column = elem.attrib.get('column')
alignment = elem.attrib.get('alignment')
# See if it is a box layout.
if row is None or column is None:
if alignment is None:
return ()
return (0, _parse_alignment(alignment))
# It must be a grid or a form layout.
row = int(row)
column = int(column)
rowspan = int(elem.attrib.get('rowspan', 1))
colspan = int(elem.attrib.get('colspan', 1))
if alignment is None:
return (row, column, rowspan, colspan)
return (row, column, rowspan, colspan, _parse_alignment(alignment))
class WidgetStack(list):
topwidget = None
def push(self, item):
DEBUG("push %s %s" % (item.metaObject().className(),
item.objectName()))
self.append(item)
if isinstance(item, QtWidgets.QWidget):
self.topwidget = item
def popLayout(self):
layout = list.pop(self)
DEBUG("pop layout %s %s" % (layout.metaObject().className(),
layout.objectName()))
return layout
def popWidget(self):
widget = list.pop(self)
DEBUG("pop widget %s %s" % (widget.metaObject().className(),
widget.objectName()))
for item in reversed(self):
if isinstance(item, QtWidgets.QWidget):
self.topwidget = item
break
else:
self.topwidget = None
DEBUG("new topwidget %s" % (self.topwidget,))
return widget
def peek(self):
return self[-1]
def topIsLayout(self):
return isinstance(self[-1], QtWidgets.QLayout)
def topIsLayoutWidget(self):
# A plain QWidget is a layout widget unless it's parent is a
# QMainWindow or a container widget. Note that the corresponding uic
# test is a little more complicated as it involves features not
# supported by pyuic.
if type(self[-1]) is not QtWidgets.QWidget:
return False
if len(self) < 2:
return False
parent = self[-2]
return isinstance(parent, QtWidgets.QWidget) and type(parent) not in (
QtWidgets.QMainWindow,
QtWidgets.QStackedWidget,
QtWidgets.QToolBox,
QtWidgets.QTabWidget,
QtWidgets.QScrollArea,
QtWidgets.QMdiArea,
QtWidgets.QWizard,
QtWidgets.QDockWidget)
class ButtonGroup(object):
""" Encapsulate the configuration of a button group and its implementation.
"""
def __init__(self):
""" Initialise the button group. """
self.exclusive = True
self.object = None
class UIParser(object):
def __init__(self, qtcore_module, qtgui_module, qtwidgets_module, creatorPolicy):
self.factory = QObjectCreator(creatorPolicy)
self.wprops = Properties(self.factory, qtcore_module, qtgui_module,
qtwidgets_module)
global QtCore, QtWidgets
QtCore = qtcore_module
QtWidgets = qtwidgets_module
self.reset()
def uniqueName(self, name):
"""UIParser.uniqueName(string) -> string
Create a unique name from a string.
>>> p = UIParser(QtCore, QtGui, QtWidgets)
>>> p.uniqueName("foo")
'foo'
>>> p.uniqueName("foo")
'foo1'
"""
try:
suffix = self.name_suffixes[name]
except KeyError:
self.name_suffixes[name] = 0
return name
suffix += 1
self.name_suffixes[name] = suffix
return "%s%i" % (name, suffix)
def reset(self):
try: self.wprops.reset()
except AttributeError: pass
self.toplevelWidget = None
self.stack = WidgetStack()
self.name_suffixes = {}
self.defaults = {'spacing': -1, 'margin': -1}
self.actions = []
self.currentActionGroup = None
self.resources = []
self.button_groups = {}
def setupObject(self, clsname, parent, branch, is_attribute=True):
name = self.uniqueName(branch.attrib.get('name') or clsname[1:].lower())
if parent is None:
args = ()
else:
args = (parent, )
obj = self.factory.createQObject(clsname, name, args, is_attribute)
self.wprops.setProperties(obj, branch)
obj.setObjectName(name)
if is_attribute:
setattr(self.toplevelWidget, name, obj)
return obj
def getProperty(self, elem, name):
for prop in elem.findall('property'):
if prop.attrib['name'] == name:
return prop
return None
def createWidget(self, elem):
self.column_counter = 0
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
安装PyQt5,避免了下载速度慢,安装时间长。(python是3.6版本的) 步骤-1 将压缩文件中的文件添加到anaconda安装目录:D:\Anaconda3\Lib\site-packages 如果想在pycharm中使用Qt的designer,那么参考步骤二 步骤-2 参考:https://www.cnblogs.com/rhxuza1993/p/7304923.html 跳过前几部分,从file- setting-external tools(外部工具)这步开始 祝大家好运啊
资源推荐
资源详情
资源评论



















收起资源包目录





































































































共 1811 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19
资源评论

- 正版胡一星2023-07-26文件中的说明清晰易懂,帮助我顺利安装了PyQt5,省去了很多麻烦。
- 葡萄的眼泪2023-07-26阅读这个文件后,我对PyQt5的安装和使用有了清晰的认识,非常感谢作者的分享。
- 琉璃纱2023-07-26这个文件提供了非常实用的PyQt5安装指南,让我能够轻松上手使用。
- 南小鹏2023-07-26这篇文档提供了详细的步骤和示例代码,帮助我快速理解并使用PyQt5。
- H等等H2023-07-26这份文件对于初学者来说简直是一次福音,让我能够迅速入门PyQt5,很赞!

目标检测跟踪
- 粉丝: 38
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 网络营销战略计划的制定.pptx
- 上海大学逻辑与可编程控制器plc组态王交通灯实验课程报告.doc
- 基于AT89C51单片机温度报警系统设计与制作.doc
- 2023年人口与计划生育信息化竞赛试题目库.doc
- 网络营销试卷样卷A.doc
- 中小企业网络规划毕业设计网络专业.doc
- 网络安全22入侵检测系统ppt课件.ppt
- 互联网餐饮连锁股份有限公司创业计划书.doc
- 中国电信LTE网络质量评估测试规范样稿样本.docx
- ThinkCMF-移动应用开发资源
- 上海城市交通信息监控系统软件运维项目需求书.doc
- 如何写项目管理计划书.doc
- 新版网络安全技术解读PPT课件.pptx
- 拓贸隆综合布线设计方案.doc
- 项目管理规划[最终版].pdf
- Oracle试题.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
