本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.header方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.header方法的具体用法?Python QTreeWidget.header怎么用?Python QTreeWidget.header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.header方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
def __init__(self, parent: QWidget, filename: str, torrent_info: TorrentInfo,
control_thread: 'ControlManagerThread'):
super().__init__(parent)
self._torrent_info = torrent_info
download_info = torrent_info.download_info
self._control_thread = control_thread
self._control = control_thread.control
vbox = QVBoxLayout(self)
self._download_dir = get_directory(self._control.last_download_dir)
vbox.addWidget(QLabel('Download directory:'))
vbox.addWidget(self._get_directory_browse_widget())
vbox.addWidget(QLabel('Announce URLs:'))
url_tree = QTreeWidget()
url_tree.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
url_tree.header().close()
vbox.addWidget(url_tree)
for i, tier in enumerate(torrent_info.announce_list):
tier_item = QTreeWidgetItem(url_tree)
tier_item.setText(0, 'Tier {}'.format(i + 1))
for url in tier:
url_item = QTreeWidgetItem(tier_item)
url_item.setText(0, url)
url_tree.expandAll()
vbox.addWidget(url_tree, 1)
file_tree = QTreeWidget()
file_tree.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
file_tree.setHeaderLabels(('Name', 'Size'))
file_tree.header().setSectionResizeMode(0, QHeaderView.ResizeToContents)
self._file_items = []
self._traverse_file_tree(download_info.suggested_name, download_info.file_tree, file_tree)
file_tree.sortItems(0, Qt.AscendingOrder)
file_tree.expandAll()
file_tree.itemClicked.connect(self._update_checkboxes)
vbox.addWidget(file_tree, 3)
self._selection_label = QLabel(TorrentAddingDialog.SELECTION_LABEL_FORMAT.format(
len(download_info.files), humanize_size(download_info.total_size)))
vbox.addWidget(self._selection_label)
self._button_box = QDialogButtonBox(self)
self._button_box.setOrientation(Qt.Horizontal)
self._button_box.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok)
self._button_box.button(QDialogButtonBox.Ok).clicked.connect(self.submit_torrent)
self._button_box.button(QDialogButtonBox.Cancel).clicked.connect(self.close)
vbox.addWidget(self._button_box)
self.setFixedSize(450, 550)
self.setWindowTitle('Adding "{}"'.format(filename))
示例2: DiscoveryDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class DiscoveryDialog(QDialog):
def __init__(self, parent=None):
super(DiscoveryDialog, self).__init__(parent)
self.setModal(True)
self.setMinimumSize(200,200) # To prevent Geometry error
self.hosts = []
layout = QVBoxLayout()
self.setLayout(layout)
self.serverview = QTreeWidget()
self.serverview.setHeaderLabels(['Server', 'Ports'])
self.serverview.setIndentation(0)
self.serverview.setStyleSheet('padding:0px')
self.serverview.header().resizeSection(0, 180)
layout.addWidget(self.serverview)
btns = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
layout.addWidget(btns)
btns.accepted.connect(self.on_accept)
btns.rejected.connect(parent.closeEvent)
bs.net.server_discovered.connect(self.add_srv)
def add_srv(self, address, ports):
for host in self.hosts:
if address == host.address and ports == host.ports:
# We already know this server, skip
return
host = QTreeWidgetItem(self.serverview)
host.address = address
host.ports = ports
host.hostname = 'This computer' if address == get_ownip() else address
host.setText(0, host.hostname)
host.setText(1, '{},{}'.format(*ports))
self.hosts.append(host)
def on_accept(self):
host = self.serverview.currentItem()
if host:
bs.net.stop_discovery()
hostname = host.address
eport, sport = host.ports
bs.net.connect(hostname=hostname, event_port=eport, stream_port=sport)
self.close()
示例3: ErrorsTree
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class ErrorsTree(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
IDE.register_service("errors_tree", self)
box = QVBoxLayout(self)
box.setContentsMargins(0, 0, 0, 0)
self._tree = QTreeWidget()
self._tree.header().setHidden(True)
self._tree.setAnimated(True)
box.addWidget(self._tree)
def refresh(self, errors, path):
self._tree.clear()
parent = QTreeWidgetItem(self._tree, [path])
for lineno, msg in errors.items():
item = QTreeWidgetItem(parent, [msg])
self._tree.addTopLevelItem(item)
def display_name(self):
return 'Errors'
示例4: Results
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class Results(QWidget):
"""Show results of occurrences in files inside the tools dock."""
def __init__(self, parent):
super(Results, self).__init__(parent)
self._parent = parent
vbox = QVBoxLayout(self)
self._tree = QTreeWidget()
self._tree.setHeaderLabels((translations.TR_CONTENT,
translations.TR_FILE, translations.TR_LINE))
self._tree.header().setHorizontalScrollMode(
QAbstractItemView.ScrollPerPixel)
self._tree.header().setSectionResizeMode(0, QHeaderView.ResizeToContents)
self._tree.header().setSectionResizeMode(1, QHeaderView.ResizeToContents)
self._tree.header().setSectionResizeMode(2, QHeaderView.ResizeToContents)
self._tree.header().setStretchLastSection(True)
self._tree.sortByColumn(1, Qt.AscendingOrder)
vbox.addWidget(self._tree)
#Signals
self._tree.itemActivated['QTreeWidgetItem*', int].connect(self._open_result)
self._tree.itemClicked['QTreeWidgetItem*', int].connect(self._open_result)
def _open_result(self, item, col):
"""Get the data of the selected item and open the file."""
filename = item.toolTip(1)
line = int(item.text(2)) - 1
main_container = IDE.get_service('main_container')
if main_container:
main_container.open_file(filename=filename, line=line)
self._parent.hide()
def update_result(self, items):
"""Update the result tree with the new items."""
self._tree.clear()
for i in items:
item = QTreeWidgetItem(self._tree, (i[3], i[0], str(i[2] + 1)))
item.setToolTip(1, i[1])
示例5: ConfigurationWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
#.........这里部分代码省略.........
self.vboxlayout.addItem(spacerItem)
self.emptyPagePixmap = QLabel(self.emptyPage)
self.emptyPagePixmap.setAlignment(Qt.AlignCenter)
self.emptyPagePixmap.setObjectName("emptyPagePixmap")
self.emptyPagePixmap.setPixmap(
QPixmap(os.path.join(getConfig('ericPixDir'), 'eric.png')))
self.vboxlayout.addWidget(self.emptyPagePixmap)
self.textLabel1 = QLabel(self.emptyPage)
self.textLabel1.setAlignment(Qt.AlignCenter)
self.textLabel1.setObjectName("textLabel1")
self.vboxlayout.addWidget(self.textLabel1)
spacerItem1 = QSpacerItem(
20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.vboxlayout.addItem(spacerItem1)
self.configStack.addWidget(self.emptyPage)
self.verticalLayout_2.addWidget(self.configSplitter)
self.buttonBox = QDialogButtonBox(self)
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(
QDialogButtonBox.Apply | QDialogButtonBox.Cancel |
QDialogButtonBox.Ok | QDialogButtonBox.Reset)
self.buttonBox.setObjectName("buttonBox")
if not self.fromEric and \
self.displayMode == ConfigurationWidget.DefaultMode:
self.buttonBox.button(QDialogButtonBox.Apply).hide()
self.buttonBox.button(QDialogButtonBox.Apply).setEnabled(False)
self.buttonBox.button(QDialogButtonBox.Reset).setEnabled(False)
self.verticalLayout_2.addWidget(self.buttonBox)
self.setWindowTitle(self.tr("Preferences"))
self.configList.header().hide()
self.configList.header().setSortIndicator(0, Qt.AscendingOrder)
self.configList.setSortingEnabled(True)
self.textLabel1.setText(
self.tr("Please select an entry of the list \n"
"to display the configuration page."))
QMetaObject.connectSlotsByName(self)
self.setTabOrder(self.configList, self.configStack)
self.configStack.setCurrentWidget(self.emptyPage)
self.configList.setFocus()
def __searchTextChanged(self, text):
"""
Private slot to handle a change of the search text.
@param text text to search for (string)
"""
self.__searchChildItems(self.configList.invisibleRootItem(), text)
def __searchChildItems(self, parent, text):
"""
Private method to enable child items based on a search string.
@param parent reference to the parent item (QTreeWidgetItem)
@param text text to search for (string)
@return flag indicating an enabled child item (boolean)
"""
childEnabled = False
text = text.lower()
for index in range(parent.childCount()):
示例6: DebugViewer
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
#.........这里部分代码省略.........
self.framenr = frmnr
self.debugServer.remoteClientVariables(0, self.localsFilter, frmnr)
if self.__autoViewSource:
self.__showSource()
def __setGlobalsFilter(self):
"""
Private slot to set the global variable filter.
"""
filter = self.globalsFilterEdit.text()
self.debugServer.remoteClientSetFilter(1, filter)
self.debugServer.remoteClientVariables(2, self.globalsFilter)
def __setLocalsFilter(self):
"""
Private slot to set the local variable filter.
"""
filter = self.localsFilterEdit.text()
self.debugServer.remoteClientSetFilter(0, filter)
if self.currentStack:
self.debugServer.remoteClientVariables(
0, self.localsFilter, self.framenr)
def handleDebuggingStarted(self):
"""
Public slot to handle the start of a debugging session.
This slot sets the variables filter expressions.
"""
self.__setGlobalsFilter()
self.__setLocalsFilter()
self.showVariablesTab(False)
def currentWidget(self):
"""
Public method to get a reference to the current widget.
@return reference to the current widget (QWidget)
"""
return self.__tabWidget.currentWidget()
def setCurrentWidget(self, widget):
"""
Public slot to set the current page based on the given widget.
@param widget reference to the widget (QWidget)
"""
self.__tabWidget.setCurrentWidget(widget)
def showThreadList(self, currentID, threadList):
"""
Public method to show the thread list.
@param currentID id of the current thread (integer)
@param threadList list of dictionaries containing the thread data
"""
citm = None
self.__threadList.clear()
for thread in threadList:
if thread['broken']:
state = self.tr("waiting at breakpoint")
else:
state = self.tr("running")
itm = QTreeWidgetItem(self.__threadList,
["{0:d}".format(thread['id']),
thread['name'], state])
if thread['id'] == currentID:
citm = itm
self.__threadList.header().resizeSections(QHeaderView.ResizeToContents)
self.__threadList.header().setStretchLastSection(True)
if citm:
self.__doThreadListUpdate = False
self.__threadList.setCurrentItem(citm)
self.__doThreadListUpdate = True
def __threadSelected(self, current, previous):
"""
Private slot to handle the selection of a thread in the thread list.
@param current reference to the new current item (QTreeWidgetItem)
@param previous reference to the previous current item
(QTreeWidgetItem)
"""
if current is not None and self.__doThreadListUpdate:
tid = int(current.text(0))
self.debugServer.remoteSetThread(tid)
def __callStackFrameSelected(self, frameNo):
"""
Private slot to handle the selection of a call stack entry of the
call stack viewer.
@param frameNo frame number (index) of the selected entry (integer)
"""
if frameNo >= 0:
self.stackComboBox.setCurrentIndex(frameNo)
示例7: SqlConnectionWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class SqlConnectionWidget(QWidget):
"""
Class implementing a widget showing the SQL connections.
@signal tableActivated(str) emitted after the entry for a table has been
activated
@signal schemaRequested(str) emitted when the schema display is requested
@signal cleared() emitted after the connection tree has been cleared
"""
tableActivated = pyqtSignal(str)
schemaRequested = pyqtSignal(str)
cleared = pyqtSignal()
def __init__(self, parent=None):
"""
Constructor
@param parent reference to the parent widget (QWidget)
"""
super(SqlConnectionWidget, self).__init__(parent)
layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
self.__connectionTree = QTreeWidget(self)
self.__connectionTree.setObjectName("connectionTree")
self.__connectionTree.setHeaderLabels([self.tr("Database")])
if qVersion() >= "5.0.0":
self.__connectionTree.header().setSectionResizeMode(
QHeaderView.Stretch)
else:
self.__connectionTree.header().setResizeMode(QHeaderView.Stretch)
refreshAction = QAction(self.tr("Refresh"), self.__connectionTree)
self.__schemaAction = QAction(
self.tr("Show Schema"), self.__connectionTree)
refreshAction.triggered.connect(self.refresh)
self.__schemaAction.triggered.connect(self.showSchema)
self.__connectionTree.addAction(refreshAction)
self.__connectionTree.addAction(self.__schemaAction)
self.__connectionTree.setContextMenuPolicy(Qt.ActionsContextMenu)
layout.addWidget(self.__connectionTree)
self.__activating = False
self.__connectionTree.itemActivated.connect(self.__itemActivated)
self.__connectionTree.currentItemChanged.connect(
self.__currentItemChanged)
self.__activeDb = ""
def refresh(self):
"""
Public slot to refresh the connection tree.
"""
self.__connectionTree.clear()
self.cleared.emit()
connectionNames = QSqlDatabase.connectionNames()
foundActiveDb = False
for name in connectionNames:
root = QTreeWidgetItem(self.__connectionTree)
db = QSqlDatabase.database(name, False)
root.setText(0, self.__dbCaption(db))
if name == self.__activeDb:
foundActiveDb = True
self.__setActive(root)
if db.isOpen():
tables = db.tables()
for table in tables:
itm = QTreeWidgetItem(root)
itm.setText(0, table)
if not foundActiveDb and connectionNames:
self.__activeDb = connectionNames[0]
self.__setActive(self.__connectionTree.topLevelItem(0))
def showSchema(self):
"""
Public slot to show schema data of a database.
"""
cItm = self.__connectionTree.currentItem()
if cItm is None or cItm.parent() is None:
return
self.__setActive(cItm.parent())
self.schemaRequested.emit(cItm.text(0))
def __itemActivated(self, itm, column):
"""
Private slot handling the activation of an item.
@param itm reference to the item (QTreeWidgetItem)
@param column column that was activated (integer)
"""
if itm is None:
return
#.........这里部分代码省略.........
示例8: AddToProject
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class AddToProject(QDialog):
def __init__(self, pathProjects, parent=None):
#pathProjects must be a list
super(AddToProject, self).__init__(parent)
self.setWindowTitle(_translate("AddToProject", "Add File to Project"))
self.pathSelected = ''
vbox = QVBoxLayout(self)
self._tree = QTreeWidget()
self._tree.header().setHidden(True)
self._tree.setSelectionMode(QTreeWidget.SingleSelection)
self._tree.setAnimated(True)
vbox.addWidget(self._tree)
hbox = QHBoxLayout()
btnAdd = QPushButton(_translate("AddToProject", "Add here!"))
btnCancel = QPushButton(_translate("AddToProject", "Cancel"))
hbox.addWidget(btnCancel)
hbox.addWidget(btnAdd)
vbox.addLayout(hbox)
#load folders
self._root = None
self._loading_items = {}
self.loading_projects(pathProjects)
self._thread_execution = ThreadExecution(
self._thread_load_projects, args=[pathProjects])
self._thread_execution.finished.connect(self._callback_load_project)
self._thread_execution.start()
btnCancel.clicked['bool'].connect(self.close)
btnAdd.clicked['bool'].connect(self._select_path)
def loading_projects(self, projects):
for project in projects:
loadingItem = LoadingItem()
item = loadingItem.add_item_to_tree(project, self._tree,
parent=self)
self._loading_items[project] = item
def _thread_load_projects(self, projects):
structures = []
for pathProject in projects:
folderStructure = file_manager.open_project(pathProject)
structures.append((folderStructure, pathProject))
self._thread_execution.storage_values = structures
def _callback_load_project(self):
structures = self._thread_execution.storage_values
if structures:
for structure, path in structures:
item = self._loading_items.pop(path, None)
if item is not None:
index = self._tree.indexOfTopLevelItem(item)
self._tree.takeTopLevelItem(index)
self._load_project(structure, path)
def _select_path(self):
item = self._tree.currentItem()
if item:
self.pathSelected = item.toolTip(0)
self.close()
def _load_project(self, folderStructure, folder):
if not folder:
return
name = file_manager.get_basename(folder)
item = QTreeWidgetItem(self._tree)
item.setText(0, name)
item.setToolTip(0, folder)
item.setIcon(0, QIcon(resources.IMAGES['tree-folder']))
if folderStructure[folder][1] is not None:
folderStructure[folder][1].sort()
self._load_folder(folderStructure, folder, item)
item.setExpanded(True)
self._root = item
def _load_folder(self, folderStructure, folder, parentItem):
items = folderStructure[folder]
if items[1] is not None:
items[1].sort()
for _file in items[1]:
if _file.startswith('.'):
continue
subfolder = QTreeWidgetItem(parentItem)
subfolder.setText(0, _file)
subfolder.setToolTip(0, os.path.join(folder, _file))
subfolder.setIcon(0, QIcon(resources.IMAGES['tree-folder']))
self._load_folder(folderStructure,
os.path.join(folder, _file), subfolder)
示例9: ImperiumWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class ImperiumWidget(QWidget):
def __init__(self, parent=None):
super(ImperiumWidget, self).__init__(parent)
# objects, sub-windows
self._world = XNovaWorld_instance()
self._layout = None
self._layout_topbuttons = None
self._tree = None
self._btn_reload = None
# initialization
self.setup_ui()
def setup_ui(self):
self._layout = QVBoxLayout()
self.setLayout(self._layout)
# create layout for top line of buttons
self._layout_topbuttons = QHBoxLayout()
self._layout.addLayout(self._layout_topbuttons)
# create reload button
self._btn_reload = QPushButton(self.tr('Refresh imperium'), self)
self._btn_reload.setIcon(QIcon(':i/reload.png'))
self._btn_reload.clicked.connect(self.on_btn_refresh_imperium)
self._layout_topbuttons.addWidget(self._btn_reload)
# finalize top buttons layout
self._layout_topbuttons.addStretch()
# create tree
self._tree = QTreeWidget(self)
self._tree.setAnimated(False)
self._tree.setExpandsOnDoubleClick(True)
self._tree.setHeaderHidden(False)
self._tree.setItemsExpandable(True)
self._tree.setRootIsDecorated(True)
self._tree.setSortingEnabled(False)
self._tree.setColumnCount(1)
self._tree.setHeaderLabels(['None'])
self._layout.addWidget(self._tree)
self._tree.show()
# called once after full world load
def update_planets(self):
def additem_helper(item_texts, twi_parent=None, align_flag=0):
# align_flag = Qt::AlignLeft / Qt::AlignRight / Qt::AlignHCenter
if align_flag == 0:
align_flag = Qt.AlignHCenter | Qt.AlignVCenter
twi = QTreeWidgetItem(item_texts)
for it_col in range(len(item_texts)):
if it_col > 0:
# void QTreeWidgetItem::setTextAlignment(int column, int alignment)
twi.setTextAlignment(it_col, align_flag)
if twi_parent is None:
self._tree.addTopLevelItem(twi)
else:
twi_parent.addChild(twi)
return True
self._tree.clear() # clear the tree first
planets = self._world.get_planets() # get planets from the world
#
# setup header and its labels
header_labels = ['-']
for i in range(len(planets)):
header_labels.append(planets[i].name)
header_labels.append(self.tr('Total')) # last column - totals
self._tree.setHeaderLabels(header_labels)
# alignment of text in header labels
self._tree.header().setDefaultAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
# default column widths
for i in range(len(planets)):
if i < 1:
self._tree.setColumnWidth(i, 150)
else:
self._tree.setColumnWidth(i, 75)
#
# planets names
item_strings = [self.tr('Name')]
for pl in planets:
item_strings.append(pl.name)
additem_helper(item_strings)
#
# planets coords
item_strings = [self.tr('Coords')]
for pl in planets:
item_strings.append('[{0}:{1}:{2}]'.format(pl.coords.galaxy, pl.coords.system, pl.coords.position))
additem_helper(item_strings)
#
# planets fields
item_strings = [self.tr('Fields')]
total_busy = 0
total_fields = 0
for pl in planets:
total_busy += pl.fields_busy
total_fields = pl.fields_total
item_strings.append('{0} / {1}'.format(pl.fields_busy, pl.fields_total))
item_strings.append('{0} / {1}'.format(total_busy, total_fields))
additem_helper(item_strings)
#
# resources
res_root = QTreeWidgetItem([self.tr('Resources')])
item_strings = [self.tr('Metal')]
total_res = 0
#.........这里部分代码省略.........
示例10: QrcPackageEditor
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class QrcPackageEditor(QGridLayout):
""" A resource file system package editor. Note that this is a QLayout and
not a QWidget.
"""
# Emitted when the package has changed.
package_changed = pyqtSignal()
def __init__(self, show_root=False, scan="Scan", scan_whats_this='', whats_this=''):
""" Initialise the editor. """
super().__init__()
self.package = None
self.project = None
self._show_root = show_root
self._package_edit = QTreeWidget(whatsThis=whats_this)
self._package_edit.header().hide()
self._package_edit.itemChanged.connect(self._package_changed)
self.addWidget(self._package_edit, 0, 0, 3, 1)
self._scan_button = QPushButton(scan, whatsThis=scan_whats_this,
clicked=self._scan, enabled=False)
self.addWidget(self._scan_button, 0, 1)
self._remove_button = QPushButton("Remove all",
whatsThis="Remove all of the scanned directories and files.",
clicked=self._remove_all, enabled=False)
self.addWidget(self._remove_button, 0, 2)
self._include_button = QPushButton("Include all",
whatsThis="Select all of the scanned directories and files.",
clicked=self._include_all, enabled=False)
self.addWidget(self._include_button, 1, 1)
self._exclude_button = QPushButton("Exclude all",
whatsThis="Deselect all of the scanned directories and files.",
clicked=self._exclude_all, enabled=False)
self.addWidget(self._exclude_button, 1, 2)
self._exclusions_edit = QTreeWidget(
whatsThis="Any directory or file that matches any of the "
"these patterns will be automatically ignored when "
"scanning. Double-click on a pattern to edit or remove "
"it. Double-click below the last pattern in order to "
"add a new one.")
self._exclusions_edit.setHeaderLabel("Exclusions")
self._exclusions_edit.setEditTriggers(
QTreeWidget.DoubleClicked|QTreeWidget.SelectedClicked|
QTreeWidget.EditKeyPressed)
self._exclusions_edit.setRootIsDecorated(False)
self._exclusions_edit.itemChanged.connect(self._exclusion_changed)
self.addWidget(self._exclusions_edit, 2, 1, 1, 2)
def configure(self, package, project):
""" Configure the editor with the contents of the given package and
project.
"""
# Save the configuration.
self.package = package
self.project = project
# Set the package itself.
self._visualise()
# Set the exclusions.
self._exclusions_edit.clear()
for exclude in package.exclusions:
self._add_exclusion_item(exclude)
# Add one to be edited to create a new entry.
self._add_exclusion_item()
self._scan_button.setEnabled(package is not None)
def get_root_dir(self):
""" Return the root directory to scan, or '' if there was an error or
the user cancelled.
"""
raise NotImplementedError
def filter(self, name):
""" See if a scanned name should be discarded. """
# Include everything by default.
return False
def required(self, name):
""" See if a scanned name is required. """
# Nothing is required by default.
return False
def _add_exclusion_item(self, exclude=''):
#.........这里部分代码省略.........
示例11: select_param
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class select_param(QWidget):
def init(self,treeview):
self.dest_treeview=treeview
def __init__(self):
QWidget.__init__(self)
self.win_list=windows()
self.setFixedSize(400,700)
self.main_vbox=QVBoxLayout()
self.setWindowIcon(QIcon(os.path.join(get_image_file_path(),"scan.png")))
self.setWindowTitle(_("Select simulation parameter (www.gpvdm.com)"))
self.tab = QTreeWidget()
#self.tab.setHeaderItem("Scan items")
self.main_vbox.addWidget(self.tab)
self.hwidget=QWidget()
okButton = QPushButton("OK")
cancelButton = QPushButton("Cancel")
hbox = QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(okButton)
hbox.addWidget(cancelButton)
self.hwidget.setLayout(hbox)
self.main_vbox.addWidget(self.hwidget)
self.setLayout(self.main_vbox)
okButton.clicked.connect(self.tree_apply_click)
cancelButton.clicked.connect(self.close)
#self.tab.itemSelectionChanged.connect(self.tree_apply_click)
self.tab.header().close()
self.update()
return
def make_entry(self,root,text):
depth=0
pointer=root
for depth in range(0,len(text)):
found=False
for i in range(0,pointer.childCount()):
if pointer.child(i).text(0)==text[depth]:
found=True
pointer=pointer.child(i)
break
if found==False:
pointer=QTreeWidgetItem(pointer, [text[depth]])
def update(self):
self.tab.clear()
root = QTreeWidgetItem(self.tab, [_("Simulation parameters")])
root.setExpanded(True)
param_list=scan_items_get_list()
i=0
for item in range(0, len(param_list)):
div_str=param_list[item].name.replace("\\", "/")
div_str=div_str.split("/")
piter=None
self.make_entry(root,div_str)
def on_destroy(self):
self.win_list.update(self,"scan_select")
self.hide()
return True
def cal_path(self):
getSelected = self.tab.selectedItems()
if getSelected:
item = getSelected[0]
# getChildNode = baseNode.text(0)
path = []
while item is not None:
path.append(str(item.text(0)))
item = item.parent()
ret="/".join(reversed(path))
ret=ret.split('/', 1)[-1]
ret=ret.replace("/", os.path.sep)
return ret
def tree_apply_click(self):
index = self.dest_treeview.selectionModel().selectedRows()
if len(index)>0:
#.........这里部分代码省略.........
示例12: Preferences
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class Preferences(QDialog):
#
configuration = {}
weight = 0
#
savePreferences = pyqtSignal()
#
def __init__(self, parent=None):
super(Preferences, self).__init__(parent, Qt.Dialog)
self.setWindowTitle(translations.TR_PREFERENCES_TITLE)
self.setMinimumSize(QSize(900, 600))
vbox = QVBoxLayout(self)
hbox = QHBoxLayout()
vbox.setContentsMargins(0, 0, 5, 5)
hbox.setContentsMargins(0, 0, 0, 0)
#
self.tree = QTreeWidget()
self.tree.header().setHidden(True)
self.tree.setSelectionMode(QTreeWidget.SingleSelection)
self.tree.setAnimated(True)
self.tree.header().setHorizontalScrollMode(
QAbstractItemView.ScrollPerPixel)
self.tree.header().setSectionResizeMode(0, QHeaderView.ResizeToContents)
self.tree.header().setStretchLastSection(False)
self.tree.setFixedWidth(200)
self.stacked = QStackedLayout()
hbox.addWidget(self.tree)
hbox.addLayout(self.stacked)
vbox.addLayout(hbox)
#
hbox_footer = QHBoxLayout()
self._btnSave = QPushButton(translations.TR_SAVE)
self._btnCancel = QPushButton(translations.TR_CANCEL)
hbox_footer.addSpacerItem(QSpacerItem(1, 0, QSizePolicy.Expanding))
hbox_footer.addWidget(self._btnCancel)
hbox_footer.addWidget(self._btnSave)
vbox.addLayout(hbox_footer)
#
self.tree.itemSelectionChanged.connect(self._change_current)
self._btnCancel.clicked['bool'].connect(self.close)
self._btnSave.clicked['bool'].connect(self._save_preferences)
#
self.load_ui()
self.tree.setCurrentItem(self.tree.topLevelItem(0))
#
def _save_preferences(self):
self.savePreferences.emit()
self.close()
#
def load_ui(self):
sections = sorted(
list(Preferences.configuration.keys()),
key=lambda item: Preferences.configuration[item]['weight'])
for section in sections:
text = Preferences.configuration[section]['text']
Widget = Preferences.configuration[section]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
item = QTreeWidgetItem([text])
item.setData(0, Qt.UserRole, index)
self.tree.addTopLevelItem(item)
#
#Sort Item Children
subcontent = Preferences.configuration[section].get(
'subsections', {})
subsections = sorted(list(subcontent.keys()),
key=lambda item: subcontent[item]['weight'])
for sub in subsections:
text = subcontent[sub]['text']
Widget = subcontent[sub]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
subitem = QTreeWidgetItem([text])
subitem.setData(0, Qt.UserRole, index)
item.addChild(subitem)
#
self.tree.expandAll()
#
def _change_current(self):
item = self.tree.currentItem()
index = item.data(0, Qt.UserRole)
self.stacked.setCurrentIndex(index)
#
@classmethod
def register_configuration(cls, section, widget, text, weight=None,
subsection=None):
if weight is None:
Preferences.weight += 1
weight = Preferences.weight
if not subsection:
Preferences.configuration[section] = {'widget': widget,
'weight': weight,
#.........这里部分代码省略.........
示例13: Ui_Ucics
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
#.........这里部分代码省略.........
# ------------添加到布局
toolLayout.addWidget(self.qzoneButton, 0, Qt.AlignLeft)
toolLayout.addWidget(self.skinButton, 1, Qt.AlignLeft)
# --------添加到布局
headInfoLayout.addWidget(self.nameLabel)
headInfoLayout.addWidget(self.moodEdit)
headInfoLayout.addWidget(self.toolWidget)
# ----天气
self.weatherLabel = QLabel(self.headWidget)
self.weatherLabel.setMinimumWidth(60)
self.weatherLabel.setMaximumWidth(60)
self.weatherLabel.setCursor(QCursor(Qt.PointingHandCursor))
self.weatherLabel.setObjectName("weatherLabel")
# ----添加到布局中
headLayout.addWidget(self.headLabel, 0, Qt.AlignLeft)
headLayout.addWidget(self.headInfoWidget, 0, Qt.AlignCenter)
headLayout.addWidget(self.weatherLabel, 0, Qt.AlignRight)
# 搜索输入框
self.searchEdit = LineEdit(self.bgWidget)
self.searchEdit.setFrame(False)
# self.searchEdit.setClearButtonEnabled(True)
self.searchEdit.setObjectName("searchEdit")
# tab
self.tabWidget = QTabWidget(self.bgWidget)
self.tabWidget.setUsesScrollButtons(False) # 取消两个切换按钮
self.tabWidget.setDocumentMode(True) # 取消边框
self.tabWidget.setObjectName("tabWidget")
# --分组
self.tabGroup = QWidget(self.tabWidget)
self.tabGroup.setObjectName("tabGroup")
# ----分组布局
groupVerticalLayout = QVBoxLayout(self.tabGroup)
groupVerticalLayout.setSpacing(0)
groupVerticalLayout.setContentsMargins(0, 0, 0, 0)
groupVerticalLayout.setObjectName("groupVerticalLayout")
# ------分组list控件
self.groupTreeWidget = QTreeWidget(self.tabGroup)
self.groupTreeWidget.setFrameShape(QFrame.NoFrame)
self.groupTreeWidget.setFrameStyle(QFrame.NoFrame)
self.groupTreeWidget.setLineWidth(0)
self.groupTreeWidget.setIndentation(0)
self.groupTreeWidget.setRootIsDecorated(False)
self.groupTreeWidget.setExpandsOnDoubleClick(False)
self.groupTreeWidget.header().setVisible(False)
self.groupTreeWidget.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.groupTreeWidget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.groupTreeWidget.setObjectName("groupTreeWidget")
# ----添加到布局
groupVerticalLayout.addWidget(self.groupTreeWidget)
# --历史
self.tabHistory = QWidget(self.tabWidget)
self.tabHistory.setObjectName("tabHistory")
# ----历史布局
historyVerticalLayout = QVBoxLayout(self.tabHistory)
historyVerticalLayout.setSpacing(0)
historyVerticalLayout.setContentsMargins(0, 0, 0, 0)
historyVerticalLayout.setObjectName("historyVerticalLayout")
# ------历史list控件
self.historyTreeWidget = QTreeWidget(self.tabHistory)
self.historyTreeWidget.setFrameShape(QFrame.NoFrame)
self.historyTreeWidget.setFrameStyle(QFrame.NoFrame)
self.historyTreeWidget.setLineWidth(0)
self.historyTreeWidget.setIndentation(0)
self.historyTreeWidget.setRootIsDecorated(False)
self.historyTreeWidget.setExpandsOnDoubleClick(False)
self.historyTreeWidget.header().setVisible(False)
self.historyTreeWidget.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.historyTreeWidget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.historyTreeWidget.setObjectName("historyTreeWidget")
# ----添加到布局
historyVerticalLayout.addWidget(self.historyTreeWidget)
# 添加到tab中
self.tabWidget.addTab(self.tabGroup, "")
self.tabWidget.addTab(self.tabHistory, "")
# 整体布局
verticalLayout = QVBoxLayout(self.bgWidget)
verticalLayout.setSpacing(0)
verticalLayout.setContentsMargins(0, 0, 0, 0)
verticalLayout.setObjectName("verticalLayout")
verticalLayout.addWidget(self.topWidget)
verticalLayout.addWidget(self.headWidget)
verticalLayout.addWidget(self.searchEdit)
verticalLayout.addWidget(self.tabWidget)
# bg
layout = QVBoxLayout(Ucics)
layout.setSpacing(0)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.bgWidget)
# 初始化一些设置
_translate = QCoreApplication.translate
Ucics.setWindowTitle(_translate("Ucics", "UCICS"))
self.tabWidget.setCurrentIndex(0)
self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.tabGroup), _translate("tabGroup", "分组"))
self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.tabHistory), _translate("tabHistory", "历史"))
QMetaObject.connectSlotsByName(Ucics)
示例14: Preferences
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class Preferences(QDialog):
configuration = {}
weight = 0
# Signals
savePreferences = pyqtSignal()
def __init__(self, parent=None):
super().__init__(parent, Qt.Dialog)
self.setWindowTitle(translations.TR_PREFERENCES_TITLE)
self.setMinimumSize(900, 650)
box = QVBoxLayout(self)
box.setContentsMargins(3, 3, 3, 3)
self.setAutoFillBackground(True)
# Header
self._header_label = QLabel("")
header_font = self._header_label.font()
header_font.setBold(True)
header_font.setPointSize(header_font.pointSize() + 4)
self._header_label.setFont(header_font)
hbox = QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
self.tree = QTreeWidget()
self.tree.header().setHidden(True)
self.tree.setSelectionMode(QTreeWidget.SingleSelection)
self.tree.setAnimated(True)
self.tree.header().setSectionResizeMode(
0, QHeaderView.ResizeToContents)
self.tree.setFixedWidth(200)
hbox.addWidget(self.tree)
self.stacked = QStackedLayout()
header_layout = QVBoxLayout()
header_layout.setContentsMargins(0, 0, 0, 0)
header_layout.addWidget(self._header_label)
header_layout.addLayout(self.stacked)
hbox.addLayout(header_layout)
box.addLayout(hbox)
# Footer buttons
button_box = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
box.addWidget(button_box)
# Connections
button_box.rejected.connect(self.close)
button_box.accepted.connect(self._save_preferences)
self.tree.selectionModel().currentRowChanged.connect(
self._change_current)
self.load_ui()
@pyqtSlot()
def _save_preferences(self):
self.savePreferences.emit()
self.close()
def load_ui(self):
sections = sorted(
Preferences.configuration.keys(),
key=lambda item: Preferences.configuration[item]['weight'])
for section in sections:
text = Preferences.configuration[section]['text']
Widget = Preferences.configuration[section]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
item = QTreeWidgetItem([text])
item.setData(0, Qt.UserRole, index)
self.tree.addTopLevelItem(item)
# Sort Item Children
subcontent = Preferences.configuration[section].get(
'subsections', {})
subsections = sorted(
subcontent.keys(), key=lambda item: subcontent[item]['weight'])
for sub in subsections:
text = subcontent[sub]['text']
Widget = subcontent[sub]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
subitem = QTreeWidgetItem([text])
subitem.setData(0, Qt.UserRole, index)
item.addChild(subitem)
self.tree.expandAll()
self.tree.setCurrentIndex(self.tree.model().index(0, 0))
def _change_current(self):
item = self.tree.currentItem()
index = item.data(0, Qt.UserRole)
#.........这里部分代码省略.........
示例15: CueListDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import header [as 别名]
class CueListDialog(QDialog):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.setMinimumSize(400, 300)
self._cues = []
self.list = QTreeWidget(self)
self.list.setSelectionMode(self.list.SingleSelection)
self.list.setSelectionBehavior(self.list.SelectRows)
self.list.setAlternatingRowColors(True)
self.list.setIndentation(0)
self.list.setHeaderLabels(['Index', 'Name'])
self.list.header().setSectionResizeMode(QHeaderView.Fixed)
self.list.header().setSectionResizeMode(1, QHeaderView.Stretch)
self.list.header().setStretchLastSection(False)
self.setLayout(QVBoxLayout())
self.layout().addWidget(self.list)
self.buttons = QDialogButtonBox(self)
self.buttons.addButton(QDialogButtonBox.Cancel)
self.buttons.addButton(QDialogButtonBox.Ok)
self.layout().addWidget(self.buttons)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
def add_cue(self, cue):
try:
item = QTreeWidgetItem()
item.setTextAlignment(0, Qt.AlignCenter)
for n, prop in enumerate(['index', 'name']):
item.setText(n, str(cue.properties().get(prop, 'Undefined')))
self._cues.append(cue)
self.list.addTopLevelItem(item)
except Exception:
pass
def add_cues(self, cues):
for cue in cues:
self.add_cue(cue)
def remove_cue(self, index):
self.list.takeTopLevelItem(index)
return self._cues.pop(index)
def reset(self):
self.list.clear()
self._cues.clear()
def selected_cues(self):
cues = []
for item in self.list.selectedItems():
index = self.list.indexOfTopLevelItem(item)
cues.append(self._cues[index])
return cues