本文整理汇总了Python中PyQt5.QtWidgets.QListView.selectionModel方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.selectionModel方法的具体用法?Python QListView.selectionModel怎么用?Python QListView.selectionModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QListView
的用法示例。
在下文中一共展示了QListView.selectionModel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConfigurationView
# 需要导入模块: from PyQt5.QtWidgets import QListView [as 别名]
# 或者: from PyQt5.QtWidgets.QListView import selectionModel [as 别名]
class ConfigurationView(QWidget):
"""
Displays the configuration view.
"""
def __init__(self, parent=None):
super(ConfigurationView, self).__init__(parent)
self._layout = QBoxLayout(QBoxLayout.TopToBottom)
self.setLayout(self._layout)
self._editView = EditView(parent)
# initialize list view
self._listView = QListView()
self._configuration_model = self._get_config_model()
self._listView.setModel(self._configuration_model)
# initialize detail view
self._detailView = QWidget()
self._detailLayout = QBoxLayout(QBoxLayout.TopToBottom)
self._detailView.setLayout(self._detailLayout)
self._detailPanels = {}
self._currentDetailPanel = None
self._currentConfiguration = None # type: Configuration
self._config_wide_print_amounts = {}
self._recalculateEffectivePrintAmounts = False
# add widgets to layout
self._layout.addWidget(QLabel("List of Configurations"))
self._layout.addWidget(self._listView)
self._layout.addWidget(self._detailView)
self._create_detail_view()
# hide detail view on start
self._detailView.hide()
# selected configs map
self._selected_configs = {}
self._selected_counter = 0
# add event listener for selection change
self._listView.clicked.connect(self._on_selection_change)
self._listView.selectionModel().currentChanged.connect(self._on_selection_change)
def add_configuration(self, configuration):
"""
Adds the given configuration to the list view and opens the edit view.
:param configuration:
:type configuration: Configuration
"""
item = create_new_list_item(configuration.get_name())
self._configuration_model.appendRow(item)
self._editView.show_for_configuration(configuration)
def select_first_item(self):
rect = QRect(0,0,1,1)
self._listView.setSelection(rect, QItemSelectionModel.Select)
def update_model(self):
self._configuration_model = self._get_config_model()
self._listView.setModel(self._configuration_model)
@staticmethod
def _get_config_model():
data = DataStorage()
configurations_order = data.get_configurations_order()
model = QStandardItemModel()
for name in configurations_order:
item = create_new_list_item(name)
model.appendRow(item)
return model
def _on_selection_change(self, model_index):
"""
Called on selecting a new item in the listView.
:param model_index: index of selected item
:type model_index: QModelIndex
"""
data = DataStorage()
configurations = data.get_configurations()
selected_item = self._configuration_model.itemFromIndex(model_index) # type: QStandardItem
current_config_name = selected_item.text()
current_config = configurations[current_config_name] # type: Configuration
self._show_detail_view(current_config)
config_wide_print_amount = self._config_wide_print_amounts[current_config_name]
material_print_amounts = current_config.get_effective_material_print_amounts(
config_wide_print_amount,
self._recalculateEffectivePrintAmounts
)
self._recalculateEffectivePrintAmounts = False
if self._selected_counter == 0:
MaterialView.reset_check_state_and_print_amount()
for material in current_config.get_materials():
item = get_item(MaterialView.get_model().invisibleRootItem(), material.get_name())
if item is not None:
print_amount = material_print_amounts[material.get_name()]
if is_checked(selected_item):
check_item(item)
#.........这里部分代码省略.........
示例2: MDIHistory
# 需要导入模块: from PyQt5.QtWidgets import QListView [as 别名]
# 或者: from PyQt5.QtWidgets.QListView import selectionModel [as 别名]
class MDIHistory(QWidget, _HalWidgetBase):
def __init__(self, parent=None):
super(MDIHistory, self).__init__(parent)
self.setMinimumSize(QSize(200, 150))
self.setWindowTitle("PyQt5 editor test example")
lay = QVBoxLayout()
lay.setContentsMargins(0,0,0,0)
self.setLayout(lay)
self.list = QListView()
self.list.setEditTriggers(QListView.NoEditTriggers)
self.list.activated.connect(self.activated)
self.list.setAlternatingRowColors(True)
self.list.selectionChanged = self.selectionChanged
self.model = QStandardItemModel(self.list)
self.MDILine = MDILine()
self.MDILine.soft_keyboard = False
self.MDILine.line_up = self.line_up
self.MDILine.line_down = self.line_down
STATUS.connect('reload-mdi-history', self.reload)
# add widgets
lay.addWidget(self.list)
lay.addWidget(self.MDILine)
self.fp = os.path.expanduser(INFO.MDI_HISTORY_PATH)
try:
open(self.fp, 'r')
except:
open(self.fp, 'a+')
LOG.debug('MDI History file created: {}'.format(self.fp))
self.reload()
self.select_row('last')
def _hal_init(self):
STATUS.connect('state-off', lambda w: self.setEnabled(False))
STATUS.connect('state-estop', lambda w: self.setEnabled(False))
STATUS.connect('interp-idle', lambda w: self.setEnabled(STATUS.machine_is_on()
and (STATUS.is_all_homed()
or INFO.NO_HOME_REQUIRED)))
STATUS.connect('interp-run', lambda w: self.setEnabled(not STATUS.is_auto_mode()))
STATUS.connect('all-homed', lambda w: self.setEnabled(STATUS.machine_is_on()))
def reload(self, w=None ):
self.model.clear()
try:
with open(self.fp,'r') as inputfile:
for line in inputfile:
line = line.rstrip('\n')
item = QStandardItem(line)
self.model.appendRow(item)
self.list.setModel(self.model)
self.list.scrollToBottom()
if self.MDILine.hasFocus():
self.select_row('last')
except:
LOG.debug('File path is not valid: {}'.format(fp))
def selectionChanged(self,old, new):
cmd = self.getSelected()
self.MDILine.setText(cmd)
selectionModel = self.list.selectionModel()
if selectionModel.hasSelection():
self.row = selectionModel.currentIndex().row()
def getSelected(self):
selected_indexes = self.list.selectedIndexes()
selected_rows = [item.row() for item in selected_indexes]
# iterates each selected row in descending order
for selected_row in sorted(selected_rows, reverse=True):
text = self.model.item(selected_row).text()
return text
def activated(self):
cmd = self.getSelected()
self.MDILine.setText(cmd)
self.MDILine.submit()
self.select_row('down')
def select_row(self, style):
selectionModel = self.list.selectionModel()
parent = QModelIndex()
self.rows = self.model.rowCount(parent) - 1
if style == 'last':
self.row = self.rows
elif style == 'up':
if self.row > 0:
self.row -= 1
else:
self.row = self.rows
elif style == 'down':
if self.row < self.rows:
self.row += 1
else:
self.row = 0
else:
return
#.........这里部分代码省略.........
示例3: PatchPanel
# 需要导入模块: from PyQt5.QtWidgets import QListView [as 别名]
# 或者: from PyQt5.QtWidgets.QListView import selectionModel [as 别名]
class PatchPanel(QGroupBox):
"""Group of widget to patch an universe"""
def __init__(self, parent):
super(PatchPanel, self).__init__()
self.ola = parent.ola
self.parent = parent
self.device_selected = None
self.universe = None
grid = QGridLayout()
self.inputs_model = PortList(self, 'input_mode')
self.outputs_model = PortList(self, 'output_mode')
self.devices = QListView()
self.devices_model = DeviceList(self)
self.devices.setModel(self.devices_model)
self.inputs = QListView()
self.inputs.setModel(self.inputs_model)
self.inputs.setMinimumHeight(400)
self.inputs.setMinimumHeight(120)
self.outputs = QListView()
self.outputs.setModel(self.outputs_model)
self.outputs.setMinimumHeight(400)
self.outputs.setMinimumHeight(120)
# Universe Selected Change
self.devices.selectionModel().selectionChanged.connect(self.device_selection_changed)
devices_label = QLabel('Devices')
grid.addWidget(devices_label, 0, 0, 1, 1)
grid.addWidget(self.devices, 1, 0, 21, 1)
inputs_label = QLabel('Inputs')
grid.addWidget(inputs_label, 0, 1, 1, 1)
grid.addWidget(self.inputs, 1, 1, 10, 1)
outputs_label = QLabel('Outputs')
grid.addWidget(outputs_label, 11, 1, 1, 1)
grid.addWidget(self.outputs, 12, 1, 10, 1)
grid.setSpacing(5)
self.setLayout(grid)
def display_ports(self, universe=None):
"""
Request a list of Devices
if universe == None, a list of None-Already-Patched ports is send
"""
if universe is None:
result = self.ola.client.GetCandidatePorts(self.GetCandidatePortsCallback, None)
return result
result = self.ola.client.FetchDevices(self.GetDevicesCallback, 0)
return result
def GetCandidatePortsCallback(self, status, devices):
"""
Called for a new universe
"""
if status.Succeeded():
# clear the list of devices
self.devices_model.devices = []
if debug:
print('found', len(devices), 'candidate devices')
for device in devices:
self.devices_model.devices.append(device)
self.parent.ola.devicesList.emit()
self.refresh_ports()
def GetDevicesCallback(self, status, devices):
"""
Fill-in universe menus with candidate devices/ports
We need to make menus checkable to be able to patch ports
"""
if status.Succeeded():
# clear the list of devices
self.devices_model.devices = []
for device in devices:
if device.input_ports == []:
# there is no input ports
if device.output_ports == []:
# no in + no out = no device
pass
else:
self.devices_model.devices.append(device)
else:
self.devices_model.devices.append(device)
if debug:
print('found', len(self.devices_model.devices), 'devices')
self.parent.ola.devicesList.emit()
self.refresh_ports()
# if there was a selection before, restore it
#if self.device_selected:
#self.devices.setSelection(self.device_selected)
def refresh_ports(self):
device = self.device_selected
if device:
# reset the models of inputs and outputs
self.inputs_model.ports = []
#.........这里部分代码省略.........