本文整理汇总了Python中PyQt4.QtGui.QStringListModel.data方法的典型用法代码示例。如果您正苦于以下问题:Python QStringListModel.data方法的具体用法?Python QStringListModel.data怎么用?Python QStringListModel.data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QStringListModel
的用法示例。
在下文中一共展示了QStringListModel.data方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PosiviewProperties
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import data [as 别名]
#.........这里部分代码省略.........
def addMobile(self):
self.mobileListModel.insertRow(self.mobileListModel.rowCount())
index = self.mobileListModel.index(self.mobileListModel.rowCount() - 1)
self.lineEditMobileName.setText('NewMobile')
self.mobileListModel.setData(index, 'NewMobile', Qt.DisplayRole)
self.mMobileListView.setCurrentIndex(index)
self.applyMobile()
@pyqtSlot(name='on_pushButtonApplyMobile_clicked')
def applyMobile(self):
index = self.mMobileListView.currentIndex()
if index.isValid() and not self.lineEditMobileName.text() == '':
mobile = dict()
mobile['Name'] = self.lineEditMobileName.text()
mobile['type'] = self.comboBoxMobileType.currentText()
try:
t = eval(self.lineEditMobileShape.text())
if t.__class__ is tuple or t.__class__ is dict:
mobile['shape'] = t
except SyntaxError:
mobile['shape'] = ((0.0, -0.5), (0.3, 0.5), (0.0, 0.2), (-0.5, 0.5))
mobile['length'] = self.doubleSpinBoxMobileLength.value()
mobile['width'] = self.doubleSpinBoxMobileWidth.value()
mobile['zValue'] = self.spinBoxZValue.value()
mobile['color'] = self.mColorButtonMobileColor.color().rgba()
mobile['fillColor'] = self.mColorButtonMobileFillColor.color().rgba()
mobile['timeout'] = self.spinBoxMobileTimeout.value() * 1000
mobile['nofixNotify'] = self.spinBoxMobileNotification.value()
mobile['trackLength'] = self.spinBoxTrackLength.value()
mobile['trackColor'] = self.mColorButtonMobileTrackColor.color().rgba()
provs = dict()
for r in range(self.mobileProviderModel.rowCount()):
try:
fil = int(self.mobileProviderModel.item(r, 1).data(Qt.DisplayRole))
except:
fil = self.mobileProviderModel.item(r, 1).data(Qt.DisplayRole)
if not fil:
fil = None
provs[self.mobileProviderModel.item(r, 0).data(Qt.DisplayRole)] = fil
mobile['provider'] = provs
currName = self.mobileListModel.data(index, Qt.DisplayRole)
if not currName == mobile['Name']:
del self.projectProperties['Mobiles'][currName]
self.mobileListModel.setData(index, mobile['Name'], Qt.DisplayRole)
self.projectProperties['Mobiles'][mobile['Name']] = mobile
def populateMobileWidgets(self, index):
mobile = self.projectProperties['Mobiles'][self.mobileListModel.data(index, Qt.DisplayRole)]
self.lineEditMobileName.setText(mobile.get('Name'))
self.comboBoxMobileType.setCurrentIndex(self.comboBoxMobileType.findText(mobile.setdefault('type', 'BOX').upper()))
if mobile['type'] == 'SHAPE':
self.lineEditMobileShape.setText(str(mobile['shape']))
self.lineEditMobileShape.setEnabled(True)
else:
self.lineEditMobileShape.setEnabled(False)
self.lineEditMobileShape.clear()
self.doubleSpinBoxMobileLength.setValue(mobile.get('length', 20.0))
self.doubleSpinBoxMobileWidth.setValue(mobile.get('width', 5.0))
self.spinBoxZValue.setValue(mobile.get('zValue', 100))
self.mColorButtonMobileColor.setColor(self.getColor(mobile.get('color', 'black')))
self.mColorButtonMobileFillColor.setColor(self.getColor(mobile.get('fillColor', 'green')))
self.spinBoxMobileTimeout.setValue(mobile.get('timeout', 3000) / 1000)
self.spinBoxMobileNotification.setValue(mobile.get('nofixNotify', 0))
self.spinBoxTrackLength.setValue(mobile.get('trackLength', 100))
self.mColorButtonMobileTrackColor.setColor(self.getColor(mobile.get('trackColor', 'green')))
示例2: PylouWidget
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import data [as 别名]
#.........这里部分代码省略.........
"TextFont", QVariant(QFont())))
self.treeview.nativeWidget().setFont(QFont(user_font_family))
# custom user choosed styles
user_style_sheet = "color:{};alternate-background-color:{}".format(
self.applet.configurations.readEntry("TextColor"),
self.applet.configurations.readEntry("AlternateBColor"))
self.treeview.nativeWidget().setStyleSheet(user_style_sheet)
# Qt connecting people
Applet.connect(
self.lineEdit, SIGNAL("keyUPPressed"), self.prevHistoryItem)
Applet.connect(
self.lineEdit, SIGNAL("keyDownPressed"), self.nextHistoryItem)
Applet.connect(self.treeview, SIGNAL("DblClick"), self.openFile)
Applet.connect(self.treeview, SIGNAL("Click"), self.openDirectory)
self.applet.appletDestroyed.connect(self.saveHistory)
# History file
self.histfile = HISTORY_FILE_PATH
with open(self.histfile, 'r') as history_file:
self.history = history_file.readlines()
self.historyCurrentItem = 0
self.treeview.nativeWidget().hide()
self.resize(self.minimumSize())
def saveHistory(self):
"""Write History to History file."""
with open(self.histfile, 'w') as history_file:
history_file.writelines(self.history)
def prevHistoryItem(self):
"""Navigate the History 1 Item Backwards."""
if self.historyCurrentItem < len(self.history):
self.historyCurrentItem = self.historyCurrentItem + 1
try:
self.lineEdit.setText(str(self.history[-self.historyCurrentItem]))
except IndexError as error:
print(error)
self.label.setText("ERROR: History Empty.")
def nextHistoryItem(self):
"""Navigate the History 1 Item Forwards."""
if self.historyCurrentItem > 1:
self.historyCurrentItem = self.historyCurrentItem - 1
try:
self.lineEdit.setText(str(self.history[-self.historyCurrentItem]))
except IndexError as error:
print(error)
self.label.setText("ERROR: History Empty.")
def addItem(self):
"""Add Items from Locate command."""
start_time = datetime.now().second
self.stringlist.clear()
lineText = self.lineEdit.text()
if len(lineText) and str(lineText).strip() not in self.history:
self.history.append(lineText + "\n")
self.historyCurrentItem = 1
self.saveHistory()
self.historyCurrentItem = self.historyCurrentItem - 1
command = "ionice --ignore --class 3 chrt --idle 0 " # Nice CPU / IO
command += "locate --ignore-case --existing --quiet --limit 9999 {}"
condition = str(self.applet.configurations.readEntry("Home")) == "true"
if len(str(lineText).strip()) and condition:
command_to_run = command.format( # Only Search inside Home folders
path.join(path.expanduser("~"), "*{}*".format(lineText)))
else:
command_to_run = command.format(lineText)
locate_output = Popen(command_to_run, shell=True, stdout=PIPE).stdout
results = tuple(locate_output.readlines())
banned = self.applet.configurations.readEntry("Banned")
banned_regex_pattern = str(banned).strip().lower().replace(" ", "|")
for item in results:
if not search(banned_regex_pattern, str(item)): # banned words
self.stringlist.append(item[:-1])
purge() # Purge RegEX Cache
self.model.setStringList(self.stringlist)
self.treeview.nativeWidget().resizeColumnToContents(0)
number_of_results = len(results)
if number_of_results: # if tems found Focus on item list
self.lineEdit.nativeWidget().clear()
self.label.setText("Found {} results on {} seconds !".format(
number_of_results, abs(datetime.now().second - start_time)))
self.resize(500, 12 * number_of_results)
self.treeview.nativeWidget().show()
self.treeview.nativeWidget().setFocus()
else: # if no items found Focus on LineEdit
self.label.setText("Search")
self.resize(self.minimumSize())
self.treeview.nativeWidget().hide()
self.lineEdit.nativeWidget().selectAll()
self.lineEdit.nativeWidget().setFocus()
def openDirectory(self, index):
"""Take a model index and find the folder name then open the folder."""
item_to_open = path.dirname(str(self.model.data(index, 0).toString()))
Popen("xdg-open '{}'".format(item_to_open), shell=True)
def openFile(self, index):
"""Take a model index and find the filename then open the file."""
item_to_open = self.model.data(index, 0).toString()
Popen("xdg-open '{}'".format(item_to_open), shell=True)
示例3: data
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import data [as 别名]
def data( self, index, role ):
" Changes the rows font "
if role == Qt.FontRole:
return self.__font
return QStringListModel.data( self, index, role )