本文整理汇总了Python中PyQt4.QtGui.QListView.setEditTriggers方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.setEditTriggers方法的具体用法?Python QListView.setEditTriggers怎么用?Python QListView.setEditTriggers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QListView
的用法示例。
在下文中一共展示了QListView.setEditTriggers方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: widget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setEditTriggers [as 别名]
def widget(self,parent):
td = ListPickerDialog(self, parent)
td.setWindowTitle("Select Server")
td.setAttribute(Qt.WA_DeleteOnClose)
layout = QHBoxLayout();
layout.setContentsMargins(16, 0, 16, 8)
view = self.view()
if not view:
listView = QListView()
listView.setEditTriggers( QAbstractItemView.NoEditTriggers)
listView.setModel(self.model())
listView.setModelColumn(self.modelColumn())
if listView.sizeHintForRow(0)>0:
listView.setMinimumHeight(listView.sizeHintForRow(0) * 5)
view = listView
else:
view.setModel(self.model())
layout.addWidget(view)
self.setView(view)
if self.model():
index = self.model().index(self.currentIndex(), self.modelColumn())
self.selectModelIndex(index)
btnbox = QDialogButtonBox(Qt.Vertical)
btnbox.addButton("Select", QDialogButtonBox.AcceptRole)
addBtn = btnbox.addButton("Add", QDialogButtonBox.ActionRole)
addBtn.clicked.connect(self.addServer)
editBtn = btnbox.addButton("Edit", QDialogButtonBox.ActionRole)
editBtn.clicked.connect(self.editServer)
remBtn = btnbox.addButton("Remove", QDialogButtonBox.ActionRole)
remBtn.clicked.connect(self.remServer)
btnbox.accepted.connect( td.accept)
btnbox.rejected.connect( td.reject)
layout.addWidget(btnbox)
td.setLayout(layout)
return td
示例2: DiscreteVariableEditor
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setEditTriggers [as 别名]
class DiscreteVariableEditor(VariableEditor):
"""An editor widget for editing a discrete variable.
Extends the :class:`VariableEditor` to enable editing of
variables values.
"""
def setup_gui(self):
layout = QVBoxLayout()
self.setLayout(layout)
self.main_form = QFormLayout()
self.main_form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
layout.addLayout(self.main_form)
self._setup_gui_name()
self._setup_gui_values()
self._setup_gui_labels()
def _setup_gui_values(self):
self.values_edit = QListView()
self.values_edit.setEditTriggers(QTreeView.CurrentChanged)
self.values_model = itemmodels.PyListModel(flags=Qt.ItemIsSelectable | \
Qt.ItemIsEnabled | Qt.ItemIsEditable)
self.values_edit.setModel(self.values_model)
self.values_model.dataChanged.connect(self.on_values_changed)
self.main_form.addRow("Values", self.values_edit)
def set_data(self, var):
"""Set the variable to edit
"""
VariableEditor.set_data(self, var)
self.values_model[:] = list(var.values) if var is not None else []
def get_data(self):
"""Retrieve the modified variable
"""
name = str(self.name_edit.text())
labels = self.labels_model.get_dict()
values = map(str, self.values_model)
if not self.is_same():
var = type(self.var)(name, values=values)
var.attributes.update(labels)
self.var = var
else:
var = self.var
return var
def is_same(self):
"""Is the current model state the same as the input.
"""
values = map(str, self.values_model)
return VariableEditor.is_same(self) and self.var.values == values
def clear(self):
"""Clear the model state.
"""
VariableEditor.clear(self)
self.values_model.wrap([])
@Slot()
def on_values_changed(self):
self.maybe_commit()
示例3: DesktopIconWidget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setEditTriggers [as 别名]
class DesktopIconWidget(QFrame):
def __init__(self, parent):
QFrame.__init__(self, parent)
self.setFrameStyle(QFrame.Box | QFrame.Sunken)
self.setStyleSheet("QListView{background:transparent;}")
self.listView = QListView(self)
self.setLayout(QHBoxLayout())
self.layout().setContentsMargins(0, 0, 0, 0)
self.layout().addWidget(self.listView)
self.listView.setContextMenuPolicy(Qt.CustomContextMenu)
self.listView.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.listView.setMovement(QListView.Snap)
self.listView.setFlow(QListView.LeftToRight)
self.listView.setResizeMode(QListView.Adjust)
self.listView.setGridSize(QSize(self.logicalDpiX() / 96 * 70,
self.logicalDpiY() / 96 * 70))
self.listView.setViewMode(QListView.IconMode)
self.quickDesktopModel = QuickDesktopModel(self.window().platform.databaseFile)
self.listView.setModel(self.quickDesktopModel)
self.createActions()
self.makeConnections()
def createActions(self):
self.actionCreateComputer = QAction(self.trUtf8("我的电脑(&C)"), self)
self.actionCreateDocuments = QAction(self.trUtf8("我的文档(&D)"), self)
self.actionCreateMusic = QAction(self.trUtf8("我的音乐(&M)"), self)
self.actionCreatePictures = QAction(self.trUtf8("我的图片(&P)"), self)
self.actionCreateShortcut = QAction(self.trUtf8("创建快捷方式(&C)"), self)
self.actionCreateShortcut.setIcon(QIcon(":/images/new.png"))
self.actionCreateBookmark = QAction(self.trUtf8("创建网络链接(&B)"), self)
self.actionCreateBookmark.setIcon(QIcon(":/images/insert-link.png"))
self.actionRemoveShortcut = QAction(self.trUtf8("删除快捷方式(&R)"), self)
self.actionRemoveShortcut.setIcon(QIcon(":/images/delete.png"))
self.actionRenameShortcut = QAction(self.trUtf8("重命名(&N)"), self)
self.actionRenameShortcut.setIcon(QIcon(":/images/edit-rename.png"))
self.actionEditShortcut = QAction(self.trUtf8("编辑快捷方式(&E)"), self)
self.actionEditShortcut.setIcon(QIcon(":/images/edit.png"))
def makeConnections(self):
self.listView.customContextMenuRequested.connect(self.onQuickDesktopContextMenuRequest)
self.listView.activated.connect(self.runQuickDesktopShortcut)
self.actionCreateComputer.triggered.connect(self.createComputerShortcut)
self.actionCreateDocuments.triggered.connect(self.createDocumentsShortcut)
self.actionCreateMusic.triggered.connect(self.createMusicShortcut)
self.actionCreatePictures.triggered.connect(self.createPicturesShortcut)
self.actionCreateShortcut.triggered.connect(self.createShortcut)
self.actionCreateBookmark.triggered.connect(self.createBookmark)
self.actionEditShortcut.triggered.connect(self.editShortcut)
self.actionRemoveShortcut.triggered.connect(self.removeShortcut)
self.actionRenameShortcut.triggered.connect(self.renameShortcut)
def onQuickDesktopContextMenuRequest(self, pos):
index = self.listView.indexAt(pos)
self.listView.setCurrentIndex(index)
menu = QMenu()
menu.addAction(self.actionCreateShortcut)
menu.addAction(self.actionCreateBookmark)
menu2 = menu.addMenu(self.trUtf8("创建特殊快捷方式(&S)"))
if os.name == "nt":
menu2.addAction(self.actionCreateComputer)
menu2.addAction(self.actionCreateDocuments)
menu2.addAction(self.actionCreatePictures)
menu2.addAction(self.actionCreateMusic)
if index.isValid():
menu.addAction(self.actionRemoveShortcut)
if not self.quickDesktopModel.isSpecialShortcut(index):
menu.addAction(self.actionEditShortcut)
menu.addAction(self.actionRenameShortcut)
try:
getattr(menu, "exec")(QCursor.pos())
except AttributeError:
getattr(menu, "exec_")(QCursor.pos())
def createShortcut(self):
d = ShortcutDialog(self)
if self.window().runDialog(d.create) == QDialog.Accepted:
shortcut = d.getResult()
shortcut["id"] = str(uuid.uuid4())
self.quickDesktopModel.addShortcut(shortcut)
d.deleteLater()
def createBookmark(self):
d = BookmarkDialog(self)
if self.window().runDialog(d.create) == QDialog.Accepted:
shortcut = {
"id": str(uuid.uuid4()),
"icon": "",
"openwith": "",
"dir": "",
}
shortcut.update(d.getResult())
self.quickDesktopModel.addShortcut(shortcut)
d.deleteLater()
def createComputerShortcut(self):
shortcut = {
#.........这里部分代码省略.........
示例4: Browser
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setEditTriggers [as 别名]
class Browser(QWidget):
entrytype = type("EntryType", (object,), dict((v,k) for k,v in enumerate(
["directory", "playlist", "mediafile", "url"]
)))
col = type("BrowserColumns", (object,), dict((v,k) for k,v in enumerate(
["name", "last_modified", "entrytype", "uri"]
)))
@staticmethod
def columns():
return len(dict((k,v) for k,v in Browser.col.__dict__.items()
if not k.startswith("__")))
def __init__(self,app):
super(Browser,self).__init__()
self.mpd = app.mpd
self.ih = app.imagehelper
self.model = QStandardItemModel(0,self.columns(),self)
self.initGUI()
self.initActions()
def initGUI(self):
self.setWindowTitle(QApplication.applicationName())
layout = QVBoxLayout()
headerlayout = QHBoxLayout()
homeBtn = QToolButton()
homeBtn.setIcon(self.ih.homeButton)
homeBtn.setFixedSize(64,64)
homeBtn.clicked.connect(self.home)
headerlayout.addWidget(homeBtn)
label = QLabel("<b>Location</b>")
label.setMargin(10)
label.setFixedSize(label.sizeHint())
headerlayout.addWidget(label)
self.currentLocation = ClickableLabel("")
self.currentLocation.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
self.currentLocation.setWordWrap(True)
self.currentLocation.setFixedSize(400,64)
self.currentLocation.clicked.connect(self.back)
headerlayout.addWidget(self.currentLocation)
headerlayout.addStretch()
layout.addLayout(headerlayout)
self.view = QListView()
self.view.setSelectionMode( QAbstractItemView.SingleSelection)
self.view.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.view.setContextMenuPolicy(Qt.CustomContextMenu)
self.view.customContextMenuRequested.connect(self.contextMenu)
self.view.setModel(self.model)
self.view.setModelColumn(0)
#self.view.doubleClicked.connect(self.doubleClicked)
self.view.activated.connect(self.activated)
layout.addWidget(self.view)
self.setLayout(layout)
def initActions(self):
self.actionAdd = QAction("Add", self)
self.actionAddPlay = QAction("Add and Play", self)
self.actionInsert = QAction("Insert", self)
self.actionReplace = QAction("Replace", self)
self.actionReplacePlay = QAction("Replace and Play", self)
self.actionUpdate = QAction("Update", self)
self.actionUpdateAll = QAction("Update all", self)
# playlist actions
self.actionPlsRename = QAction("Rename", self)
self.actionPlsDelete = QAction("Delete", self)
def contextMenu(self,pos):
if self.model.rowCount() == 0: return
mi = self.view.selectionModel().currentIndex()
if not mi.isValid(): return
uri = self.model.item(mi.row(),self.col.uri).text()
entrytype = int(self.model.item(mi.row(),self.col.entrytype).text())
addfunc = None
if entrytype != self.entrytype.playlist:
addfunc = self.mpd.add
else:
addfunc = self.mpd.load
popup = QMenu()
popup.addAction(self.actionAdd)
popup.addAction(self.actionAddPlay)
if entrytype == self.entrytype.mediafile or \
entrytype == self.entrytype.url:
popup.addAction(self.actionInsert)
popup.addAction(self.actionReplace)
popup.addAction(self.actionReplacePlay)
if entrytype == self.entrytype.playlist:
popup.addAction(self.actionPlsRename)
popup.addAction(self.actionPlsDelete)
else:
popup.addAction(self.actionUpdate)
popup.addAction(self.actionUpdateAll)
action = popup.exec_(self.mapToGlobal(pos))
status = self.mpd.status()
#.........这里部分代码省略.........
示例5: OWPythonScript
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setEditTriggers [as 别名]
class OWPythonScript(OWWidget):
settingsList = ["codeFile", "libraryListSource", "currentScriptIndex",
"splitterState", "auto_execute"]
def __init__(self, parent=None, signalManager=None):
OWWidget.__init__(self, parent, signalManager, 'Python Script')
self.inputs = [("in_data", Orange.data.Table, self.setExampleTable,
Default),
("in_distance", Orange.misc.SymMatrix,
self.setDistanceMatrix, Default),
("in_learner", Orange.core.Learner, self.setLearner,
Default),
("in_classifier", Orange.core.Classifier,
self.setClassifier, Default),
("in_object", object, self.setObject)]
self.outputs = [("out_data", Orange.data.Table),
("out_distance", Orange.misc.SymMatrix),
("out_learner", Orange.core.Learner),
("out_classifier", Orange.core.Classifier, Dynamic),
("out_object", object, Dynamic)]
self.in_data = None
self.in_distance = None
self.in_learner = None
self.in_classifier = None
self.in_object = None
self.auto_execute = False
self.codeFile = ''
self.libraryListSource = [Script("Hello world",
"print 'Hello world'\n")]
self.currentScriptIndex = 0
self.splitterState = None
self.loadSettings()
for s in self.libraryListSource:
s.flags = 0
self._cachedDocuments = {}
self.infoBox = OWGUI.widgetBox(self.controlArea, 'Info')
OWGUI.label(
self.infoBox, self,
"<p>Execute python script.</p><p>Input variables:<ul><li> " + \
"<li>".join(t[0] for t in self.inputs) + \
"</ul></p><p>Output variables:<ul><li>" + \
"<li>".join(t[0] for t in self.outputs) + \
"</ul></p>"
)
self.libraryList = PyListModel([], self, flags=Qt.ItemIsSelectable | \
Qt.ItemIsEnabled | Qt.ItemIsEditable)
self.libraryList.wrap(self.libraryListSource)
self.controlBox = OWGUI.widgetBox(self.controlArea, 'Library')
self.controlBox.layout().setSpacing(1)
self.libraryView = QListView()
self.libraryView.setEditTriggers(QListView.DoubleClicked | \
QListView.EditKeyPressed)
self.libraryView.setSizePolicy(QSizePolicy.Ignored,
QSizePolicy.Preferred)
self.libraryView.setItemDelegate(ScriptItemDelegate(self))
self.libraryView.setModel(self.libraryList)
self.connect(self.libraryView.selectionModel(),
SIGNAL("selectionChanged(QItemSelection, QItemSelection)"),
self.onSelectedScriptChanged)
self.controlBox.layout().addWidget(self.libraryView)
w = ModelActionsWidget()
self.addNewScriptAction = action = QAction("+", self)
action.setToolTip("Add a new script to the library")
self.connect(action, SIGNAL("triggered()"), self.onAddScript)
w.addAction(action)
self.removeAction = action = QAction("-", self)
action.setToolTip("Remove script from library")
self.connect(action, SIGNAL("triggered()"), self.onRemoveScript)
w.addAction(action)
action = QAction("Update", self)
action.setToolTip("Save changes in the editor to library")
action.setShortcut(QKeySequence(QKeySequence.Save))
self.connect(action, SIGNAL("triggered()"),
self.commitChangesToLibrary)
w.addAction(action)
action = QAction("More", self)
action.pyqtConfigure(toolTip="More actions")
new_from_file = QAction("Import a script from a file", self)
save_to_file = QAction("Save selected script to a file", self)
save_to_file.setShortcut(QKeySequence(QKeySequence.SaveAs))
#.........这里部分代码省略.........
示例6: MainWindow
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setEditTriggers [as 别名]
class MainWindow(QMainWindow):
"""
class MainWindow for the gui of dokueddy
"""
def __init__(self, config, parent=None):
"""
Constructor for class MainWindow
@param config: dokueddy configuration
"""
QMainWindow.__init__(self)
self.config = config
self.setGeometry(
self.config.settings['app_x'],
self.config.settings['app_y'],
self.config.settings['app_w'],
self.config.settings['app_h']
)
self.setWindowTitle(
self.config.settings['appname'] +
' - Version: ' +
self.config.settings['appversion']
)
globalFont = QFont(
self.config.settings['fontfamily'],
self.config.settings['pointsize']
)
self.statusbar = self.statusBar()
self.center()
self.exit = QAction('Quit Dokueddy', self)
self.menubar = QMenuBar(None)
self.file = self.menubar.addMenu('&File')
self.file.addAction(self.exit)
self.setMenuBar(self.menubar)
self.save = QAction(QIcon('../resources/icons/save_edit.gif'), 'Save current page', self)
self.save.setShortcut('Ctrl+S')
self.save.setDisabled(True)
self.fontBold = QAction(QIcon('../resources/icons/tag_bold.png'), 'Bold text', self)
self.fontItalic = QAction(QIcon('../resources/icons/tag_i.png'), 'Italic text', self)
self.fontH1 = QAction(QIcon('../resources/icons/tag_h1.png'), 'Heading 1', self)
self.fontH2 = QAction(QIcon('../resources/icons/tag_h2.png'), 'Heading 2', self)
self.fontH3 = QAction(QIcon('../resources/icons/tag_h3.png'), 'Heading 3', self)
self.fontH4 = QAction(QIcon('../resources/icons/tag_h4.png'), 'Heading 4', self)
self.fontH5 = QAction(QIcon('../resources/icons/tag_h5.png'), 'Heading 5', self)
self.search = QAction(QIcon('../resources/icons/magnify.png'), 'Search for', self)
self.toolbar = self.addToolBar('Toolbar')
self.toolbar.addAction(self.save)
self.toolbar.addSeparator()
self.toolbar.addAction(self.fontBold)
self.toolbar.addAction(self.fontItalic)
self.toolbar.addAction(self.fontH1)
self.toolbar.addAction(self.fontH2)
self.toolbar.addAction(self.fontH3)
self.toolbar.addAction(self.fontH4)
self.toolbar.addAction(self.fontH5)
self.toolbar.addAction(self.search)
self.toolbar.setMaximumHeight(24)
self.serverLabel = QLabel()
self.serverLabel.setText('Serveraddress:')
self.userLabel = QLabel()
self.userLabel.setText('Username:')
self.passwdLabel = QLabel()
self.passwdLabel.setText('Password:')
self.serverLineEdit = QLineEdit()
self.serverLineEdit.setMinimumWidth(160)
self.serverLineEdit.setMaximumSize(250, 35)
self.serverLineEdit.setText(self.config.settings['serverAddress'])
self.userLineEdit = QLineEdit()
self.userLineEdit.setMaximumSize(150, 35)
self.userLineEdit.setText(self.config.settings['user'])
self.passwdLineEdit = QLineEdit()
self.passwdLineEdit.setMaximumSize(150, 35)
self.passwdLineEdit.setEchoMode(QLineEdit.Password)
self.connectButton = QPushButton('Connect', self)
self.connectButton.setMaximumSize(100, 35)
self.quitButton = QPushButton('Quit', self)
self.quitButton.setMaximumSize(100, 35)
self.listView = QListView(self)
self.listView.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.listView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.listView.setMinimumWidth(200)
self.listView.setMaximumWidth(400)
self.listView.setFont(globalFont)
self.textEdit = QTextEdit(self)
self.textEdit.setMinimumWidth(400)
self.textEdit.setFont(globalFont)
self.textEdit.setLineWrapMode(QTextEdit.NoWrap)
self.editLayout = QGridLayout()
self.editLayout.addWidget(self.serverLabel, 0, 0, Qt.AlignLeft)
self.editLayout.addWidget(self.serverLineEdit, 0, 1)
self.editLayout.addWidget(self.userLabel, 0, 2, Qt.AlignLeft)
self.editLayout.addWidget(self.userLineEdit, 0, 3)
#.........这里部分代码省略.........