本文整理汇总了Python中PyQt4.QtGui.QStringListModel.setStringList方法的典型用法代码示例。如果您正苦于以下问题:Python QStringListModel.setStringList方法的具体用法?Python QStringListModel.setStringList怎么用?Python QStringListModel.setStringList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QStringListModel
的用法示例。
在下文中一共展示了QStringListModel.setStringList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AppletNoticeWindow
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
class AppletNoticeWindow(QWidget):
def __init__(self, controller):
QWidget.__init__(self)
self.__controller = controller
self.__pkglist = []
# setup widgets
self.__vbox_up = QVBoxLayout()
self.__critical_label = QLabel()
self.__critical_label.setWordWrap(True)
self.__list_model = QStringListModel()
self.__list_view = QListView()
self.__list_view.setModel(self.__list_model)
self.__vbox_up.addWidget(self.__critical_label)
self.__vbox_up.addWidget(self.__list_view)
# bottom buttons
self.__vbox = QVBoxLayout()
self.__vbox.addLayout(self.__vbox_up)
self.__button_hbox = QHBoxLayout()
self.__close_button = QPushButton(_("Close"))
self.__launch_pm_button = QPushButton(_("Launch Application Browser"))
self.__button_hbox.addWidget(self.__launch_pm_button)
self.__button_hbox.addWidget(self.__close_button)
self.__vbox.addLayout(self.__button_hbox)
self.setLayout(self.__vbox)
# set window settings
self.resize(400, 200)
self.setWindowTitle(_("Application updates"))
self.connect(self.__close_button, SIGNAL("clicked()"), self.on_close)
self.connect(self.__launch_pm_button, SIGNAL("clicked()"), self.on_pm)
def closeEvent(self, event):
"""
We don't want to kill the window, since the whole app will close
otherwise.
"""
event.ignore()
self.on_close()
def on_pm(self):
self.__controller.launch_package_manager()
def on_close(self):
self.__controller.trigger_notice_window()
def populate(self, pkg_data, critical_txt):
self.__list_model.setStringList(pkg_data)
self.__critical_label.setText(critical_txt)
self.__list_view.update()
示例2: __init__
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
def __init__(self,parent=None):
super(QtGui.QLineEdit, self).__init__(parent)
model = QStringListModel()
completer = QCompleter()
completer.setModel(model)
model.setStringList(cmd.cmdset)
self.setCompleter(completer)
示例3: __init__
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
def __init__(self,expdat):
super(DBAnnotateSave, self).__init__()
print("DBAnnotateSave")
uic.loadUi(os.path.join(hs.heatsequerdir,'ui/manualdata.py'), self)
self.bplus.clicked.connect(self.plus)
self.bminus.clicked.connect(self.minus)
self.bontoinput.returnPressed.connect(self.plus)
self.bstudyinfo.clicked.connect(self.studyinfo)
self.bisa.toggled.connect(self.radiotoggle)
self.bdiffpres.toggled.connect(self.radiotoggle)
self.bisatype.currentIndexChanged.connect(self.isatypechanged)
self.bhistory.clicked.connect(self.history)
self.cexp=expdat
self.lnumbact.setText(str(len(expdat.selectedseqs)))
completer = QCompleter()
self.bontoinput.setCompleter(completer)
scdb=hs.scdb
self.scdb=scdb
self.dataid=hs.supercooldb.finddataid(scdb,datamd5=self.cexp.datamd5,mapmd5=self.cexp.mapmd5)
model = QStringListModel()
completer.setModel(model)
# completer.setCompletionMode(QCompleter.InlineCompletion)
completer.maxVisibleItems=10
completer.setCaseSensitivity(Qt.CaseInsensitive)
# make the completer selection also erase the text edit
completer.activated.connect(self.cleartext,type=Qt.QueuedConnection)
# in qt5 should work with middle complete as well...
# completer.setFilterMode(Qt.MatchContains)
if not hs.scdb.ontologyfromid:
hs.scdb=hs.supercooldb.loaddbonto(hs.scdb)
self.ontology=hs.scdb.ontology
self.ontologyfromid=hs.scdb.ontologyfromid
nlist=list(self.ontology.keys())
# nlist=sorted(nlist)
nlist=sorted(nlist, key=lambda s: s.lower())
print("sorted ontology")
model.setStringList(nlist)
self.setWindowTitle(self.cexp.studyname)
try:
tt=hs.lastdatamd5
except:
hs.lastdatamd5=''
if self.cexp.datamd5==hs.lastdatamd5:
self.fillfromcuration(hs.lastcurations[-1],onlyall=True)
self.prefillinfo()
self.bontoinput.setFocus()
示例4: IntroPage
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
class IntroPage(WizardPage):
UI_CLASS = Ui_Intro
TITLE = "Starting a bisection"
SUBTITLE = "Please choose an application and a type of bisection."
FIELDS = {'application': 'app_combo', 'bisect_type': 'bisect_combo',
'find_fix': 'find_fix'}
ID = 0
def __init__(self):
WizardPage.__init__(self)
self.fetch_config = None
self.app_model = QStringListModel(REGISTRY.names())
self.ui.app_combo.setModel(self.app_model)
self.bisect_model = QStringListModel()
self.ui.bisect_combo.setModel(self.bisect_model)
self.ui.app_combo.currentIndexChanged.connect(self._set_fetch_config)
self._set_fetch_config(0)
def _set_fetch_config(self, index):
# limit bisection type given the application
old_bisect_index = self.ui.bisect_combo.currentIndex()
self.fetch_config = create_config(
str(self.ui.app_combo.itemText(index)), mozinfo.os, mozinfo.bits)
bisect_types = ['nightlies']
if self.fetch_config.is_inbound():
bisect_types.append('inbound')
self.bisect_model.setStringList(bisect_types)
bisect_index = 0
if old_bisect_index == 1 and len(bisect_types) == 2:
bisect_index = 1
self.ui.bisect_combo.setCurrentIndex(bisect_index)
def validatePage(self):
app_name = self.fetch_config.app_name
launcher_class = LAUNCHER_REGISTRY.get(app_name)
try:
launcher_class.check_is_runnable()
return True
except LauncherNotRunnable, exc:
QMessageBox.critical(
self,
"%s is not runnable" % app_name,
str(exc)
)
return False
示例5: ed_add_element
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
def ed_add_element(self):
''' Button 33. Add element '''
# Create the dialog and signals
self.dlg = Add_element()
utils_giswater.setDialog(self.dlg)
self.dlg.btn_accept.pressed.connect(self.ed_add_element_accept)
self.dlg.btn_cancel.pressed.connect(self.close_dialog)
# Manage i18n of the form
self.controller.translate_form(self.dlg, 'element')
# Check if we have at least one feature selected
if not self.ed_check():
return
# Fill combo boxes
self.populate_combo("elementcat_id", "cat_element")
self.populate_combo("state", "value_state")
self.populate_combo("location_type", "man_type_location")
self.populate_combo("workcat_id", "cat_work")
self.populate_combo("buildercat_id", "cat_builder")
self.populate_combo("elementcat_id", "cat_element")
self.populate_combo("ownercat_id", "cat_owner")
self.populate_combo("verified", "value_verified")
# Adding auto-completion to a QLineEdit
self.edit = self.dlg.findChild(QLineEdit, "element_id")
self.completer = QCompleter()
self.edit.setCompleter(self.completer)
model = QStringListModel()
sql = "SELECT DISTINCT(element_id) FROM "+self.schema_name+".element "
row = self.dao.get_rows(sql)
for i in range(0,len(row)):
aux = row[i]
row[i] = str(aux[0])
model.setStringList(row)
self.completer.setModel(model)
# Set signal to reach selected value from QCompleter
self.completer.activated.connect(self.ed_add_el_autocomplete)
# Open the dialog
self.dlg.exec_()
示例6: create_QNewStrategy
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
def create_QNewStrategy(self):
self.__q_new_strategy = QNewStrategy()
completer = QCompleter()
if self.get_got_list_instrument_info():
model = QStringListModel()
model.setStringList(self.get_list_instrument_id())
completer.setModel(model)
else:
print(">>> CTPManager.create_QNewStrategy() 查询合约信息失败")
self.__q_new_strategy.lineEdit_a_instrument.setCompleter(completer)
self.__q_new_strategy.lineEdit_b_instrument.setCompleter(completer)
self.__q_new_strategy.set_ClientMain(self.__client_main) # CTPManager设置为新建策略窗口属性
self.__q_new_strategy.set_CTPManager(self) # CTPManager设置为新建策略窗口属性
self.__q_new_strategy.set_SocketManager(self.__socket_manager) # SocketManager设置为新建策略窗口属性
self.__q_new_strategy.set_trader_id(self.__trader_id) # 设置trade_id属性
self.set_QNewStrategy(self.__q_new_strategy) # 新建策略窗口设置为CTPManager属性
self.__client_main.set_QNewStrategy(self.__q_new_strategy) # 新建策略窗口设置为ClientMain属性
self.signal_hide_QNewStrategy.connect(self.get_QNewStrategy().hide) # 绑定信号槽,新创建策略成功后隐藏“新建策略弹窗”
# 绑定信号槽:新建策略窗新建策略指令 -> SocketManager.slot_send_msg
self.__q_new_strategy.signal_send_msg.connect(self.__socket_manager.slot_send_msg)
示例7: __init__
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
def __init__(self, items):
QSpinBox.__init__(self)
self.setMinimumWidth(75)
self.__string_converter = str
self.__items = items
list = []
for item in self.__items:
assert isinstance(item, CTime)
date = item.date()
list.append(self.convertToString(date))
model = QStringListModel()
model.setStringList(list)
self.setRange(0, len(items) - 1)
self.setValue(len(items) - 1)
line_edit = QLineEdit()
self.setLineEdit(line_edit)
示例8: ed_add_file
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
def ed_add_file(self):
''' Button 34. Add file '''
# Create the dialog and signals
self.dlg = Add_file()
utils_giswater.setDialog(self.dlg)
self.dlg.btn_accept.pressed.connect(self.ed_add_file_accept)
self.dlg.btn_cancel.pressed.connect(self.close_dialog)
# Manage i18n of the form
self.controller.translate_form(self.dlg, 'file')
# Check if we have at least one feature selected
if not self.ed_check():
return
# Fill combo boxes
self.populate_combo("doc_type", "doc_type")
self.populate_combo("tagcat_id", "cat_tag")
# Adding auto-completion to a QLineEdit
self.edit = self.dlg.findChild(QLineEdit, "doc_id")
self.completer = QCompleter()
self.edit.setCompleter(self.completer)
model = QStringListModel()
sql = "SELECT DISTINCT(id) FROM "+self.schema_name+".doc "
row = self.dao.get_rows(sql)
for i in range(0,len(row)):
aux = row[i]
row[i] = str(aux[0])
model.setStringList(row)
self.completer.setModel(model)
# Set signal to reach selected value from QCompleter
self.completer.activated.connect(self.ed_add_file_autocomplete)
# Open the dialog
self.dlg.exec_()
示例9: ExplainView
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
class ExplainView(QListView):
"""show a list explaining all score computations"""
def __init__(self, game, parent=None):
QListView.__init__(self, parent)
self.game = None
self.setWindowTitle(m18n('Explain Scores').replace('&', '') + ' - Kajongg')
self.setGeometry(0, 0, 300, 400)
self.model = QStringListModel()
self.setModel(self.model)
StateSaver(self)
self.refresh(game)
def refresh(self, game):
"""refresh for new values"""
self.game = game
lines = []
if self.game is None:
lines.append(m18n('There is no active game'))
else:
i18nName = m18n(self.game.ruleset.name)
lines.append(m18n('Ruleset: %1', i18nName))
lines.append('')
for player in self.game.players:
pLines = []
if player.hand and player.hand.tileNames:
total = player.hand.total()
if total:
pLines = ['%s: %s' % (player.localName, total)]
for line in player.hand.explain():
pLines.append('- ' + line)
elif player.handTotal:
pLines.append(m18n('Manual score for %1: %2 points', player.localName, player.handTotal))
if pLines:
pLines.append('')
lines.extend(pLines)
if 'xxx'.join(lines) != 'xxx'.join(unicode(x) for x in self.model.stringList()):
# QStringListModel does not optimize identical lists away, so we do
self.model.setStringList(lines)
示例10: LineEdit
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
class LineEdit(QLineEdit):
"""Cursom QLineEdit with tab completion"""
def __init__(self, parent=None):
QLineEdit.__init__(self, parent)
self.completer = QCompleter()
self.setCompleter(self.completer)
self.model = QStringListModel()
self.completer.setModel(self.model)
#get_data(model)
self.completions = None
self.parent = parent
def keyPressEvent(self, event):
"""Handle keypress event"""
text = self.text()
if event.key() == Qt.Key_Tab:
current_text = self.text()
if current_text != '':
for item in self.completions:
if item.startswith(current_text):
self.setText(item)
break
event.accept()
elif event.key() == Qt.Key_Return:
if text != '':
self.window().process_command(text)
self.setText('')
event.accept()
else:
QLineEdit.keyPressEvent(self, event)
def set_completions(self, completions):
"""Set completions"""
self.completions = completions
self.model.setStringList(completions)
示例11: IntroPage
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
class IntroPage(WizardPage):
UI_CLASS = Ui_Intro
TITLE = "Bisection start"
SUBTITLE = ("Please choose an application, a type of bisection"
" and the number of bits for the application.")
FIELDS = {'application': 'app_combo', 'bisect_type': 'bisect_combo',
'find_fix': 'find_fix', 'bits': 'bits_combo'}
ID = 0
def __init__(self):
WizardPage.__init__(self)
self.fetch_config = None
self.app_model = QStringListModel(REGISTRY.names())
self.ui.app_combo.setModel(self.app_model)
self.bisect_model = QStringListModel()
self.ui.bisect_combo.setModel(self.bisect_model)
if mozinfo.bits == 64:
self.bits_model = QStringListModel(['32', '64'])
bits_index = 1
elif mozinfo.bits == 32:
self.bits_model = QStringListModel(['32'])
bits_index = 0
self.ui.bits_combo.setModel(self.bits_model)
self.ui.bits_combo.setCurrentIndex(bits_index)
self.ui.app_combo.currentIndexChanged.connect(self._set_fetch_config)
self.ui.bits_combo.currentIndexChanged.connect(self._set_fetch_config)
self.ui.app_combo.setCurrentIndex(
self.ui.app_combo.findText("firefox"))
def _set_fetch_config(self, index):
# limit bisection type given the application
bits = int(self.ui.bits_combo.currentText())
old_bisect_index = self.ui.bisect_combo.currentIndex()
self.fetch_config = create_config(
str(self.ui.app_combo.itemText(index)), mozinfo.os, bits)
bisect_types = ['nightlies']
if self.fetch_config.is_inbound():
bisect_types.append('inbound')
self.bisect_model.setStringList(bisect_types)
bisect_index = 0
if old_bisect_index == 1 and len(bisect_types) == 2:
bisect_index = 1
self.ui.bisect_combo.setCurrentIndex(bisect_index)
available_bits = self.fetch_config.available_bits()
if not available_bits:
self.ui.bits_combo.hide()
self.ui.label_4.hide()
else:
self.ui.bits_combo.show()
self.ui.label_4.show()
def validatePage(self):
app_name = self.fetch_config.app_name
launcher_class = LAUNCHER_REGISTRY.get(app_name)
try:
launcher_class.check_is_runnable()
return True
except LauncherNotRunnable, exc:
QMessageBox.critical(
self,
"%s is not runnable" % app_name,
str(exc)
)
return False
示例12: PylouWidget
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
class PylouWidget(QGraphicsWidget):
"""Main Widget for Pylou."""
def __init__(self, parent):
"""Init class."""
QGraphicsWidget.__init__(self)
self.applet = parent
def init(self):
"""Start Pylou Widget."""
self.layou = QGraphicsLinearLayout(self)
self.stringlist = QStringList()
self.model = QStringListModel(self.applet)
self.model.setStringList(self.stringlist)
self.treeview = MyTreeView(self)
self.treeview.setModel(self.model)
self.lineEdit, self.label = MyLineEdit(self), Plasma.Label(self)
self.label.setText("Search")
self.layou.setOrientation(0x2) # Qt.Vertical
self.layou.addItem(self.treeview)
self.layou.addItem(self.label)
self.layou.addItem(self.lineEdit)
self.setLayout(self.layou)
self.lineEdit.returnPressed.connect(self.addItem)
self.setMinimumSize(200, 99)
self.setMaximumSize(666, 666)
# custom user choosed fonts
user_font_family = QVariant(self.applet.configurations.readEntry(
"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:
#.........这里部分代码省略.........
示例13: Person
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
#.........这里部分代码省略.........
self.ui.netLineEdit.setText(self.display_money(self.net))
@pyqtProperty(list)
def exp_types(self):
return self.experience.keys()
@pyqtProperty(str)
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
self.name_changed_sig.emit()
@pyqtProperty(float)
def net_worth(self):
return self._net_worth
@net_worth.setter
def net_worth(self, value):
self._net_worth = value
self.ui.netWorthLineEdit.setText(self.display_money(self._net_worth))
@pyqtProperty(float)
def income_tax(self):
if self.shelter:
pass
else:
return self.salary * 0.05
@pyqtProperty(float)
def salary(self):
try:
return self._employer.emp_to_salary[self]
except (AttributeError, KeyError):
return 0.0
@pyqtProperty(float)
def net(self):
return self.total_income - self.total_expenses
@pyqtProperty(float)
def total_expenses(self):
return self.income_tax
@pyqtProperty(float)
def total_income(self):
return self.salary
def employer_production_switched(self):
self.ui.salaryLineEdit.setText(self.display_money(self.salary))
self.ui.totalIncomeLineEdit.setText(self.display_money(self.total_income))
self.ui.taxesLineEdit.setText(self.display_money(self.income_tax))
self.ui.netLineEdit.setText(self.display_money(self.net))
def name_changed(self, new_name):
self.name = str(new_name)
def on_turn_end(self):
self.net_worth += self.net
self.ui.salaryLineEdit.setText(self.display_money(self.salary))
self.ui.totalIncomeLineEdit.setText(self.display_money(self.total_income))
self.ui.taxesLineEdit.setText(self.display_money(self.income_tax))
self.ui.netLineEdit.setText(self.display_money(self.net))
def gain_experience(self, exp_type, amount):
try:
self.experience[exp_type] += amount
except KeyError:
self.experience[exp_type] = amount
self.exp_type_model.setStringList(self.exp_types)
finally:
self.update_experience_widget_after_turn(exp_type)
def upgrade(self):
person_type = self.ui.upgradeComboBox.currentText()
if not(person_type):
return
person_type_clean = person_type.replace(' ', '')
upgrade_check, error = eval("manitae.people.{0}.{0}.upgrade_to(self)".format(person_type_clean))
if not(upgrade_check):
self.send_warning.emit("Could not upgrade person {0}: {1}".format(str(self), error))
else:
self.name_changed_sig.emit()
self.upgraded.emit()
self.employer.employee_upgraded(self)
def update_experience_widget(self, exp_type):
exp_amount = self.experience[str(exp_type)]
self.ui.expLineEdit.setText(str(exp_amount))
def update_experience_widget_after_turn(self, exp_changed):
exp_type = self.ui.expComboBox.currentText()
if str(exp_type) == str(exp_changed):
exp_amount = self.experience[str(exp_type)]
self.ui.expLineEdit.setText(str(exp_amount))
def display_money(self, amount):
return "{:.2f}".format(amount)
示例14: OWDatabasesUpdate
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
#.........这里部分代码省略.........
for item, tree_item, options_widget in self.updateItems:
self.filesView.setItemWidget(tree_item, 0, options_widget)
# Add an update button if the file is updateable
if item.state == OUTDATED:
button = QToolButton(
None, text="Update",
maximumWidth=120,
maximumHeight=30
)
if sys.platform == "darwin":
button.setAttribute(Qt.WA_MacSmallSize)
button.clicked.connect(
partial(self.SubmitDownloadTask, item.domain,
item.filename)
)
self.filesView.setItemWidget(tree_item, 2, button)
self.progress.advance()
self.filesView.setColumnWidth(0, self.filesView.sizeHintForColumn(0))
for column in range(1, 4):
contents_hint = self.filesView.sizeHintForColumn(column)
header_hint = self.filesView.header().sectionSizeHint(column)
width = max(min(contents_hint, 400), header_hint)
self.filesView.setColumnWidth(column, width)
hints = [hint for hint in sorted(all_tags) if not hint.startswith("#")]
self.completertokens = hints
self.completermodel.setStringList(hints)
self.SearchUpdate()
self.UpdateInfoLabel()
self.toggleButtons()
self.cancelButton.setEnabled(False)
self.progress.setRange(0, 0)
def buttonCheck(self, selected_items, state, button):
for item in selected_items:
if item.state != state:
button.setEnabled(False)
else:
button.setEnabled(True)
break
def toggleButtons(self):
selected_items = [item for item, tree_item, _ in self.updateItems if not tree_item.isHidden()]
self.buttonCheck(selected_items, OUTDATED, self.updateButton)
self.buttonCheck(selected_items, AVAILABLE, self.downloadButton)
def HandleError(self, exception):
if isinstance(exception, IOError):
self.error(0,
"Could not connect to server! Press the Retry "
"button to try again.")
self.SetFilesList({})
else:
sys.excepthook(type(exception), exception.args, None)
self.progress.setRange(0, 0)
self.setEnabled(True)
示例15: RatingWidget
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setStringList [as 别名]
#.........这里部分代码省略.........
# cost display
self.cost = QGroupBox("National ideas")
costLayout = QFormLayout()
self.costRating = QLineEdit()
self.costRating.setReadOnly(True)
costLayout.addRow(QLabel("Rating:"), self.costRating)
self.costDisplay = QLineEdit()
self.costDisplay.setReadOnly(True)
costLayout.addRow(QLabel("Cost:"), self.costDisplay)
possibleRatings = QGroupBox("Possible ratings")
possibleRatingsLayout = QFormLayout()
for cost, rating in ideaRatings:
if cost is not None:
possibleRatingsLayout.addRow(QLabel("Up to %0.1f:" % (cost),), QLabel(rating))
else:
possibleRatingsLayout.addRow(QLabel("Above:"), QLabel(rating))
possibleRatings.setLayout(possibleRatingsLayout)
costLayout.addRow(possibleRatings)
breakdown = QGroupBox("Breakdown")
breakdownLayout = QFormLayout()
self.breakdownLabels = []
self.breakdownCosts = []
for i in range(9):
breakdownLabel = QLabel()
self.breakdownLabels.append(breakdownLabel)
breakdownCost = QLineEdit()
breakdownCost.setReadOnly(True)
self.breakdownCosts.append(breakdownCost)
breakdownLayout.addRow(breakdownLabel, breakdownCost)
breakdown.setLayout(breakdownLayout)
costLayout.addRow(breakdown)
self.cost.setLayout(costLayout)
self.cost.setToolTip(costToolTipText)
# penalty display
self.penalties = QGroupBox("Penalties")
penaltiesLayout = QFormLayout()
# self.penaltiesRating = QLineEdit()
# self.penaltiesRating.setReadOnly(True)
# penaltiesLayout.addRow(QLabel("Rating:"), self.penaltiesRating)
self.yellowCardCount = QLineEdit()
self.yellowCardCount.setReadOnly(True)
penaltiesLayout.addRow(QLabel("Yellow cards:"), self.yellowCardCount)
self.yellowCardDisplay = QListView()
self.yellowCardDisplay.setSelectionMode(QAbstractItemView.NoSelection)
self.yellowCards = QStringListModel()
self.yellowCardDisplay.setModel(self.yellowCards)
penaltiesLayout.addRow(self.yellowCardDisplay)
self.redCardCount = QLineEdit()
self.redCardCount.setReadOnly(True)
penaltiesLayout.addRow(QLabel("Red cards:"), self.redCardCount)
self.redCardDisplay = QListView()
self.redCardDisplay.setSelectionMode(QAbstractItemView.NoSelection)
self.redCards = QStringListModel()
self.redCardDisplay.setModel(self.redCards)
penaltiesLayout.addRow(self.redCardDisplay)
self.penalties.setLayout(penaltiesLayout)
self.penalties.setToolTip(penaltiesToolTipText)
layout = QHBoxLayout()
layout.addWidget(self.cost)
layout.addWidget(self.penalties)
self.setLayout(layout)
def handleCostChanged(self, costs):
totalCost = sum(costs)
self.costDisplay.setText("%0.2f" % (totalCost,))
self.costRating.setText(getIdeaRating(totalCost))
for i, cost in enumerate(costs):
self.breakdownCosts[i].setText("%0.2f" % cost)
def handleIdeaNamesChanged(self, names):
for i, name in enumerate(names):
self.breakdownLabels[i].setText(name)
def handlePenaltiesChanged(self, yellow, red):
self.yellowCardCount.setText("%d" % (len(yellow),))
self.yellowCards.setStringList(yellow)
self.redCardCount.setText("%d" % (len(red),))
self.redCards.setStringList(red)