本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.setHeaderLabels方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.setHeaderLabels方法的具体用法?Python QTreeWidget.setHeaderLabels怎么用?Python QTreeWidget.setHeaderLabels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.setHeaderLabels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_variable_table
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [as 别名]
def get_variable_table(self, context):
context_key = context.replace(' ', '-').lower()
if context_key in self.variable_tables:
table = self.variable_tables[context_key]
else:
table = QTreeWidget()
table.setColumnCount(3)
table.setHeaderLabels(['Name', 'Type', 'Value'])
table.setColumnWidth(0, 250)
table.setColumnWidth(1, 150)
self.variable_tables[context_key] = table
if context == 'Locals':
self.insertTab(0, table, context)
else:
self.addTab(table, context)
table.itemDoubleClicked.connect(
self.handle_variable_double_clicked
)
self.setCurrentIndex(0)
return table
示例2: __init__
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [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))
示例3: MemUsageDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [as 别名]
class MemUsageDialog(QDialog):
def __init__(self, parent=None, update=True):
QDialog.__init__(self, parent=parent)
layout = QVBoxLayout()
self.tree = QTreeWidget()
layout.addWidget(self.tree)
self.setLayout(layout)
self._mgr = CacheMemoryManager()
self._tracked_caches = {}
# tree setup code
self.tree.setHeaderLabels(
["cache", "memory", "roi", "dtype", "type", "info", "id"])
self._idIndex = self.tree.columnCount() - 1
self.tree.setColumnHidden(self._idIndex, True)
self.tree.setSortingEnabled(True)
self.tree.clear()
self._root = TreeNode()
# refresh every x seconds (see showEvent())
self.timer = QTimer(self)
if update:
self.timer.timeout.connect(self._updateReport)
def _updateReport(self):
# we keep track of dirty reports so we just have to update the tree
# instead of reconstructing it
reports = []
for c in self._mgr.getFirstClassCaches():
r = MemInfoNode()
c.generateReport(r)
reports.append(r)
self._root.handleChildrenReports(
reports, root=self.tree.invisibleRootItem())
def hideEvent(self, event):
self.timer.stop()
def showEvent(self, show):
# update once so we don't have to wait for initial report
self._updateReport()
# update every 5 sec.
self.timer.start(5*1000)
示例4: DiscoveryDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [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()
示例5: InfoDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [as 别名]
class InfoDialog(QDialog):
def __init__(self, parent, info, title):
super().__init__(parent)
self.setWindowTitle('Media Info - ' + title)
self.setWindowModality(QtCore.Qt.ApplicationModal)
self.setMinimumSize(500, 250)
self.resize(500, 250)
self.vLayout = QVBoxLayout(self)
self.infoTree = QTreeWidget(self)
self.infoTree.setColumnCount(2)
self.infoTree.setHeaderLabels(['Scope', 'Value'])
self.infoTree.setAlternatingRowColors(True)
self.infoTree.setSelectionMode(QAbstractItemView.NoSelection)
self.infoTree.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.vLayout.addWidget(self.infoTree)
self.__generate_widgets(info)
self.infoTree.setColumnWidth(0, 150)
self.buttonBox = QDialogButtonBox(self)
self.buttonBox.setStandardButtons(QDialogButtonBox.Close)
self.vLayout.addWidget(self.buttonBox)
self.buttonBox.rejected.connect(self.close)
def __generate_widgets(self, info, parent=None):
for key in sorted(info.keys()):
if(isinstance(info[key], dict)):
widget = QTreeWidgetItem([key])
self.__generate_widgets(info[key], widget)
else:
widget = QTreeWidgetItem([key, info[key]])
if(parent):
parent.addChild(widget)
else:
self.infoTree.addTopLevelItem(widget)
示例6: Results
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [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])
示例7: PugdebugExpressionViewer
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [as 别名]
class PugdebugExpressionViewer(QWidget):
expression_added_signal = pyqtSignal(int, str)
expression_changed_signal = pyqtSignal(int, str)
def __init__(self):
super(PugdebugExpressionViewer, self).__init__()
# Action for adding a new expression
self.add_action = QAction(QIcon.fromTheme('list-add'), "&Add", self)
self.add_action.triggered.connect(self.handle_add_action)
# Action for deleting selected expressions
self.delete_action = QAction(
QIcon.fromTheme('list-remove'),
"&Delete", self
)
self.delete_action.setShortcut(QKeySequence("Del"))
self.delete_action.triggered.connect(self.handle_delete_action)
self.toolbar = QToolBar()
self.toolbar.setIconSize(QSize(16, 16))
self.toolbar.addAction(self.add_action)
self.toolbar.addAction(self.delete_action)
self.tree = QTreeWidget()
self.tree.setColumnCount(3)
self.tree.setHeaderLabels(['Expression', 'Type', 'Value'])
self.tree.setSelectionMode(QAbstractItemView.ContiguousSelection)
self.tree.setContextMenuPolicy(Qt.CustomContextMenu)
self.tree.customContextMenuRequested.connect(self.show_context_menu)
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.tree)
self.setLayout(layout)
self.restore_state()
self.tree.itemChanged.connect(self.handle_item_changed)
def show_context_menu(self, point):
# Create the context menu on the tree widget
context_menu = QMenu(self)
# Add action is always visible
context_menu.addAction(self.add_action)
# If clicked on an row, offer to delete it
if self.tree.itemAt(point):
context_menu.addAction(self.delete_action)
point = self.tree.mapToGlobal(point)
context_menu.popup(point)
def add_expression(self, expression):
item = QTreeWidgetItem([expression, '', ''])
item.setFlags(
Qt.ItemIsEnabled |
Qt.ItemIsEditable |
Qt.ItemIsSelectable
)
self.tree.addTopLevelItem(item)
# Emit the signal to evaluate the expression
index = self.tree.indexOfTopLevelItem(item)
self.expression_added_signal.emit(index, expression)
def delete_selected(self):
"""Deletes currently selected items from the tree"""
for item in self.tree.selectedItems():
index = self.tree.indexOfTopLevelItem(item)
self.delete_expression(item)
self.select_next(index)
def select_next(self, index):
"""Selects the next item after an item has been deleted"""
prev_item = self.tree.topLevelItem(index - 1)
next_item = self.tree.topLevelItem(index)
if prev_item:
prev_item.setSelected(True)
elif next_item:
next_item.setSelected(True)
def clear_values(self):
"""Deletes values for all expressions"""
count = self.tree.topLevelItemCount()
for index in range(0, count):
item = self.tree.topLevelItem(index)
item.setData(1, Qt.DisplayRole, '')
item.setData(2, Qt.DisplayRole, '')
item.takeChildren()
def delete_expression(self, item):
"""Deletes the given item from the tree"""
index = self.tree.indexOfTopLevelItem(item)
self.tree.takeTopLevelItem(index)
def get_expressions(self):
#.........这里部分代码省略.........
示例8: JackConnectionsDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [as 别名]
class JackConnectionsDialog(QDialog):
def __init__(self, jack_client, parent=None, **kwargs):
super().__init__(parent)
self.resize(600, 400)
self.setLayout(QGridLayout())
# self.layout().setContentsMargins(0, 0, 0, 0)
self.output_widget = QTreeWidget(self)
self.output_widget.setHeaderLabels(['Output ports'])
self.input_widget = QTreeWidget(self)
self.input_widget.setHeaderLabels(['Input ports'])
self.connections_widget = ConnectionsWidget(self.output_widget,
self.input_widget,
parent=self)
self.output_widget.itemExpanded.connect(self.connections_widget.update)
self.output_widget.itemCollapsed.connect(self.connections_widget.update)
self.input_widget.itemExpanded.connect(self.connections_widget.update)
self.input_widget.itemCollapsed.connect(self.connections_widget.update)
self.input_widget.itemSelectionChanged.connect(
self.__input_selection_changed)
self.output_widget.itemSelectionChanged.connect(
self.__output_selection_changed)
self.layout().addWidget(self.output_widget, 0, 0)
self.layout().addWidget(self.connections_widget, 0, 1)
self.layout().addWidget(self.input_widget, 0, 2)
self.layout().setColumnStretch(0, 2)
self.layout().setColumnStretch(1, 1)
self.layout().setColumnStretch(2, 2)
self.connectButton = QPushButton('Connect', self)
self.connectButton.clicked.connect(self.__disconnect_selected)
self.connectButton.setEnabled(False)
self.layout().addWidget(self.connectButton, 1, 1)
self.dialogButtons = QDialogButtonBox(
QDialogButtonBox.Cancel | QDialogButtonBox.Ok)
self.dialogButtons.accepted.connect(self.accept)
self.dialogButtons.rejected.connect(self.reject)
self.layout().addWidget(self.dialogButtons, 2, 0, 1, 3)
self.__jack_client = jack_client
self.__selected_in = None
self.__selected_out = None
self.connections = []
self.update_graph()
def set_connections(self, connections):
self.connections = connections
self.connections_widget.connections = self.connections
self.connections_widget.update()
def update_graph(self):
input_ports = self.__jack_client.get_ports(is_audio=True, is_input=True)
self.output_widget.clear()
for port in range(8):
self.output_widget.addTopLevelItem(
QTreeWidgetItem(['output_' + str(port)]))
self.input_widget.clear()
clients = {}
for port in input_ports:
client_name = port.name[:port.name.index(':')]
if client_name not in clients:
clients[client_name] = ClientItem(client_name)
self.input_widget.addTopLevelItem(clients[client_name])
clients[client_name].add_port(port.name)
def __input_selection_changed(self):
if self.input_widget.selectedItems():
self.__selected_in = self.input_widget.selectedItems()[0]
else:
self.__selected_in = None
self.__check_selection()
def __output_selection_changed(self):
if self.output_widget.selectedItems():
self.__selected_out = self.output_widget.selectedItems()[0]
else:
self.__selected_out = None
self.__check_selection()
def __check_selection(self):
if self.__selected_in is not None and self.__selected_out is not None:
output = self.output_widget.indexOfTopLevelItem(self.__selected_out)
self.connectButton.clicked.disconnect()
self.connectButton.setEnabled(True)
#.........这里部分代码省略.........
示例9: MiscTab
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [as 别名]
class MiscTab(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.name = self.tr("Misc")
self.markColorLabel = QLabel(self.tr("Default flag colors:"), self)
# TODO: enforce duplicate names avoidance
self.markColorWidget = QTreeWidget(self)
self.markColorWidget.setHeaderLabels(
(self.tr("Color"), self.tr("Name")))
self.markColorWidget.setRootIsDecorated(False)
self.markColorWidget.setSelectionBehavior(
QAbstractItemView.SelectRows)
# TODO: make this work correctly, top-level items only
# self.markColorWidget.setDragDropMode(QAbstractItemView.InternalMove)
self.addItemButton = QPushButton("+", self)
self.addItemButton.clicked.connect(self.addItem)
self.removeItemButton = QPushButton("−", self)
self.removeItemButton.clicked.connect(self.removeItem)
self.loadRecentFileBox = QCheckBox(
self.tr("Load most recent file on start"), self)
layout = QGridLayout(self)
l = 0
layout.addWidget(self.markColorLabel, l, 0, 1, 3)
l += 1
layout.addWidget(self.markColorWidget, l, 0, 1, 3)
l += 1
layout.addWidget(self.addItemButton, l, 0)
layout.addWidget(self.removeItemButton, l, 1)
l += 1
layout.addWidget(self.loadRecentFileBox, l, 0, 1, 3)
self.setLayout(layout)
self.readSettings()
def addItem(self):
def mangleNewName():
name = self.tr("New")
index = 0
while self.markColorWidget.findItems(name, Qt.MatchExactly, 1):
index += 1
name = "{0} ({1})".format(name, index)
return name
# TODO: not DRY with ctor
item = QTreeWidgetItem(self.markColorWidget)
item.setFlags(item.flags() | Qt.ItemIsEditable)
widget = ColorVignette(self)
widget.setColor(QColor(Qt.white))
widget.setMargins(2, 2, 2, 2)
widget.setMayClearColor(False)
self.markColorWidget.setItemWidget(item, 0, widget)
item.setText(1, mangleNewName())
self.markColorWidget.setCurrentItem(item)
self.markColorWidget.editItem(item, 1)
self.removeItemButton.setEnabled(True)
def removeItem(self):
i = self.markColorWidget.selectionModel().currentIndex().row()
self.markColorWidget.takeTopLevelItem(i)
if not self.markColorWidget.topLevelItemCount():
self.removeItemButton.setEnabled(False)
def readSettings(self):
entries = settings.readMarkColors()
for name, color in entries.items():
item = QTreeWidgetItem(self.markColorWidget)
item.setFlags(item.flags() | Qt.ItemIsEditable)
widget = ColorVignette(self)
widget.setColor(color)
widget.setMargins(2, 2, 2, 2)
widget.setMayClearColor(False)
self.markColorWidget.setItemWidget(item, 0, widget)
item.setText(1, name)
if not len(entries):
self.removeItemButton.setEnabled(False)
loadRecentFile = settings.loadRecentFile()
self.loadRecentFileBox.setChecked(loadRecentFile)
def writeSettings(self):
markColors = OrderedDict()
for i in range(self.markColorWidget.topLevelItemCount()):
item = self.markColorWidget.topLevelItem(i)
name = item.text(1)
color = self.markColorWidget.itemWidget(item, 0).color()
markColors[name] = color
settings.writeMarkColors(markColors)
loadRecentFile = self.loadRecentFileBox.isChecked()
settings.setLoadRecentFile(loadRecentFile)
示例10: CueListDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [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
示例11: _init_layout
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [as 别名]
def _init_layout(self):
"""
Create the GUI widgets (but leave them empty).
"""
hostname_combobox = QComboBox(parent=self)
self._hostname_combobox = hostname_combobox
hostname_combobox.setEditable(True)
hostname_combobox.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Maximum )
for hostname in self._suggested_hostnames:
hostname_combobox.addItem( hostname )
# EventFilter is installed after everything else is initialized. (See below.)
#hostname_combobox.installEventFilter(self)
self._connect_button = QPushButton("Connect", parent=self, clicked=self._handle_new_hostname)
hostname_layout = QHBoxLayout()
hostname_layout.addWidget( hostname_combobox )
hostname_layout.addWidget( self._connect_button )
hostinfo_table = QTableWidget()
hostinfo_table.setColumnCount(len(SERVER_INFO_FIELDS))
hostinfo_table.setHorizontalHeaderLabels(SERVER_INFO_FIELDS)
hostinfo_table.horizontalHeader().setVisible(True)
hostinfo_table.verticalHeader().setVisible(False)
hostinfo_table.setRowCount(1)
hostinfo_table.setItem(0,0, QTableWidgetItem("Placeholder"))
hostinfo_table.setVisible(False)
hostinfo_table.resizeRowsToContents()
hostinfo_table.horizontalHeader().setStretchLastSection(True)
table_height = hostinfo_table.verticalHeader().sectionSize(0) + hostinfo_table.rowHeight(0)
hostinfo_table.resize( QSize( hostinfo_table.width(), table_height ) )
hostinfo_table.setMaximumSize( QSize( 1000, table_height ) )
hostinfo_table.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
host_layout = QVBoxLayout()
host_layout.addLayout(hostname_layout)
host_layout.addWidget(hostinfo_table)
host_groupbox = QGroupBox("DVID Host", parent=self)
host_groupbox.setLayout( host_layout )
host_groupbox.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Preferred )
repo_treewidget = QTreeWidget(parent=self)
repo_treewidget.setHeaderLabels( TREEVIEW_COLUMNS ) # TODO: Add type, shape, axes, etc.
repo_treewidget.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Preferred )
repo_treewidget.itemSelectionChanged.connect( self._handle_data_selection )
data_layout = QVBoxLayout()
data_layout.addWidget( repo_treewidget )
data_groupbox = QGroupBox("Data Volumes", parent=self)
data_groupbox.setLayout( data_layout )
node_listwidget = QListWidget(parent=self)
node_listwidget.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Preferred )
node_listwidget.itemSelectionChanged.connect( self._update_status )
node_layout = QVBoxLayout()
node_layout.addWidget( node_listwidget )
node_groupbox = QGroupBox("Nodes", parent=self)
node_groupbox.setLayout( node_layout )
new_data_edit = QLineEdit(parent=self)
new_data_edit.textEdited.connect( self._update_status )
full_url_label = QLabel(parent=self)
full_url_label.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Maximum )
text_flags = full_url_label.textInteractionFlags()
full_url_label.setTextInteractionFlags( text_flags | Qt.TextSelectableByMouse )
new_data_layout = QVBoxLayout()
new_data_layout.addWidget( new_data_edit )
new_data_groupbox = QGroupBox("New Data Volume", parent=self)
new_data_groupbox.setLayout( new_data_layout )
new_data_groupbox.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Maximum )
buttonbox = QDialogButtonBox( Qt.Horizontal, parent=self )
buttonbox.setStandardButtons( QDialogButtonBox.Ok | QDialogButtonBox.Cancel )
buttonbox.accepted.connect( self.accept )
buttonbox.rejected.connect( self.reject )
buttonbox.button(QDialogButtonBox.Ok).setEnabled(False)
layout = QVBoxLayout()
layout.addWidget( host_groupbox )
layout.addWidget( data_groupbox )
layout.addWidget( node_groupbox )
if self._mode == "specify_new":
layout.addWidget( new_data_groupbox )
else:
new_data_groupbox.hide()
layout.addWidget( full_url_label )
layout.addWidget( buttonbox )
# Stretch factors
layout.setStretchFactor(data_groupbox, 3)
layout.setStretchFactor(node_groupbox, 1)
self.setLayout(layout)
self.setWindowTitle( "Select DVID Volume" )
self.resize(1000, 1000)
#.........这里部分代码省略.........
示例12: __init__
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [as 别名]
def __init__(self, *args, **kwargs):
super(ShortcutManagerDlg, self).__init__(*args, **kwargs)
self.setWindowTitle("Shortcut Preferences")
self.setMinimumWidth(500)
self.setMinimumHeight(500)
mgr = ShortcutManager() # Singleton
scrollWidget = QWidget(parent=self)
tempLayout = QVBoxLayout(scrollWidget)
scrollWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
treeWidget = QTreeWidget(parent=scrollWidget)
treeWidget.setHeaderLabels(["Action", "Shortcut"])
treeWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
treeWidget.setColumnWidth(0, 300)
treeWidget.setColumnWidth(1, 50)
action_descriptions = mgr.get_all_action_descriptions()
target_keyseqs = mgr.get_keyseq_reversemap()
# Create a LineEdit for each shortcut,
# and keep track of them in a dict
shortcutEdits = collections.OrderedDict()
for group, targets in list(action_descriptions.items()):
groupItem = QTreeWidgetItem(treeWidget, [group])
for (name, description) in targets:
edit = QLineEdit(target_keyseqs[(group, name)])
shortcutEdits[(group, name)] = edit
item = QTreeWidgetItem(groupItem, [description])
item.setText(0, description)
treeWidget.setItemWidget(item, 1, edit)
tempLayout.addWidget(treeWidget)
# Add ok and cancel buttons
buttonLayout = QHBoxLayout()
cancelButton = QPushButton("Cancel")
cancelButton.clicked.connect(self.reject)
okButton = QPushButton("OK")
okButton.clicked.connect(self.accept)
okButton.setDefault(True)
buttonLayout.addSpacerItem(QSpacerItem(10, 0, QSizePolicy.Expanding))
buttonLayout.addWidget(cancelButton)
buttonLayout.addWidget(okButton)
tempLayout.addLayout(buttonLayout)
scroll = QScrollArea(parent=self)
scroll.setWidget(scrollWidget)
scroll.setWidgetResizable(True)
scroll.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
dlgLayout = QVBoxLayout()
dlgLayout.addWidget(scroll)
self.setLayout(dlgLayout)
# Show the window
result = self.exec_()
# Did the user hit 'cancel'?
if result != QDialog.Accepted:
return
for (group, name), edit in list(shortcutEdits.items()):
oldKey = target_keyseqs[(group, name)]
newKey = str(edit.text())
if oldKey.lower() != newKey.lower() and newKey != "":
mgr.change_keyseq(group, name, oldKey, newKey)
mgr.store_to_preferences()
示例13: Shortcuts
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [as 别名]
class Shortcuts(preferences.Page):
def __init__(self, dialog):
super(Shortcuts, self).__init__(dialog)
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(layout)
self.scheme = SchemeSelector(self)
layout.addWidget(self.scheme)
self.searchEntry = LineEdit()
self.searchEntry.setPlaceholderText(_("Search..."))
layout.addWidget(self.searchEntry)
self.tree = QTreeWidget(self)
self.tree.setHeaderLabels([_("Command"), _("Shortcut")])
self.tree.setRootIsDecorated(False)
self.tree.setColumnCount(2)
self.tree.setAllColumnsShowFocus(True)
self.tree.setAnimated(True)
layout.addWidget(self.tree)
self.edit = QPushButton(icons.get("preferences-desktop-keyboard-shortcuts"), '')
layout.addWidget(self.edit)
# signals
self.searchEntry.textChanged.connect(self.updateFilter)
self.scheme.currentChanged.connect(self.slotSchemeChanged)
self.scheme.changed.connect(self.changed)
self.tree.currentItemChanged.connect(self.slotCurrentItemChanged)
self.tree.itemDoubleClicked.connect(self.editCurrentItem)
self.edit.clicked.connect(self.editCurrentItem)
# make a dict of all actions with the actions as key and the names as
# value, with the collection prepended (for loading/saving)
win = dialog.parent()
allactions = {}
for collection in actioncollectionmanager.manager(win).actionCollections():
for name, action in collection.actions().items():
allactions[action] = (collection, name)
# keep a list of actions not in the menu structure
left = list(allactions.keys())
def add_actions(menuitem, actions):
"""Add actions to a QTreeWidgetItem."""
for a in actions:
if a.menu():
item = build_menu_item(a)
if item.childCount():
menuitem.addChild(item)
elif a in left:
left.remove(a)
menuitem.addChild(ShortcutItem(a, *allactions[a]))
menuitem.setFlags(Qt.ItemIsEnabled) # disable selection
def build_menu_item(action):
"""Return a QTreeWidgetItem with children for all the actions in the submenu."""
menuitem = QTreeWidgetItem()
text = qutil.removeAccelerator(action.text())
menuitem.setText(0, _("Menu {name}").format(name=text))
add_actions(menuitem, action.menu().actions())
return menuitem
# present the actions nicely ordered as in the menus
for a in win.menuBar().actions():
menuitem = build_menu_item(a)
if menuitem.childCount():
self.tree.addTopLevelItem(menuitem)
# sort leftover actions
left.sort(key=lambda i: i.text())
# show actions that are left, grouped by collection
titlegroups = {}
for a in left[:]: # copy
collection, name = allactions[a]
if collection.title():
titlegroups.setdefault(collection.title(), []).append(a)
left.remove(a)
for title in sorted(titlegroups):
item = QTreeWidgetItem(["{0}:".format(title)])
for a in titlegroups[title]:
item.addChild(ShortcutItem(a, *allactions[a]))
self.tree.addTopLevelItem(item)
item.setFlags(Qt.ItemIsEnabled) # disable selection
# show other actions that were not in the menus
item = QTreeWidgetItem([_("Other commands:")])
for a in left:
if a.text() and not a.menu():
item.addChild(ShortcutItem(a, *allactions[a]))
if item.childCount():
self.tree.addTopLevelItem(item)
item.setFlags(Qt.ItemIsEnabled) # disable selection
self.tree.expandAll()
item = self.tree.topLevelItem(0).child(0)
if _lastaction:
# find the previously selected item
#.........这里部分代码省略.........
示例14: DebugViewer
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [as 别名]
#.........这里部分代码省略.........
index, self.breakpointViewer.windowTitle())
self.breakpointViewer.sourceFile.connect(self.sourceFile)
from .WatchPointViewer import WatchPointViewer
# add the watch expression viewer
self.watchpointViewer = WatchPointViewer()
self.watchpointViewer.setModel(self.debugServer.getWatchPointModel())
index = self.__tabWidget.addTab(
self.watchpointViewer,
UI.PixmapCache.getIcon("watchpoints.png"), '')
self.__tabWidget.setTabToolTip(
index, self.watchpointViewer.windowTitle())
from .ExceptionLogger import ExceptionLogger
# add the exception logger
self.exceptionLogger = ExceptionLogger()
index = self.__tabWidget.addTab(
self.exceptionLogger,
UI.PixmapCache.getIcon("exceptions.png"), '')
self.__tabWidget.setTabToolTip(
index, self.exceptionLogger.windowTitle())
if self.embeddedShell:
self.__tabWidget.setCurrentWidget(self.shellAssembly)
else:
if self.embeddedBrowser:
self.__tabWidget.setCurrentWidget(self.browser)
else:
self.__tabWidget.setCurrentWidget(self.glvWidget)
# add the threads viewer
self.__mainLayout.addWidget(QLabel(self.tr("Threads:")))
self.__threadList = QTreeWidget()
self.__threadList.setHeaderLabels(
[self.tr("ID"), self.tr("Name"),
self.tr("State"), ""])
self.__threadList.setSortingEnabled(True)
self.__mainLayout.addWidget(self.__threadList)
self.__doThreadListUpdate = True
self.__threadList.currentItemChanged.connect(self.__threadSelected)
self.__mainLayout.setStretchFactor(self.__tabWidget, 5)
self.__mainLayout.setStretchFactor(self.__threadList, 1)
self.currPage = None
self.currentStack = None
self.framenr = 0
self.debugServer.clientStack.connect(self.handleClientStack)
self.__autoViewSource = Preferences.getDebugger("AutoViewSourceCode")
self.sourceButton.setVisible(not self.__autoViewSource)
def preferencesChanged(self):
"""
Public slot to handle the preferencesChanged signal.
"""
self.__autoViewSource = Preferences.getDebugger("AutoViewSourceCode")
self.sourceButton.setVisible(not self.__autoViewSource)
def setDebugger(self, debugUI):
"""
Public method to set a reference to the Debug UI.
示例15: SqlConnectionWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabels [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
#.........这里部分代码省略.........