本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.text方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.text方法的具體用法?Python QLineEdit.text怎麽用?Python QLineEdit.text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.text方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: MainWindow
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.statusBar().showMessage('ready')
self.filename = QLabel(self)
self.filename.setText('filename')
self.filename.move(20, 20)
self.filename_edit = QLineEdit(self)
self.filename_edit.move(80, 20)
self.keywords = QLabel(self)
self.keywords.setText('keyword')
self.keywords.move(20, 60)
self.keywords_edit = QLineEdit(self)
self.keywords_edit.move(80, 60)
self.button = QPushButton('search', self)
self.button.move(20, 100)
self.button.clicked.connect(self.search_keywords)
self.setWindowModality(QtCore.Qt.ApplicationModal)
self.setMaximumSize(300, 200)
self.setMinimumSize(300, 200)
self.setGeometry(300, 300, 300, 220)
self.setWindowTitle('kws kaldi')
self.error_message = QLabel(self)
self.result = QLabel(self)
def search_keywords(self):
filename_text = self.filename_edit.text()
keywords_text = self.keywords_edit.text()
if filename_text == '':
self.statusBar().showMessage('filename is empty!')
return
if not os.path.isfile(filename_text):
self.statusBar().showMessage('incorrect filename!')
return
if keywords_text == '':
self.statusBar().showMessage('keyword is empty!')
return
self.statusBar().showMessage('processing')
process = subprocess.Popen('GST_PLUGIN_PATH=. ./transcribe-audio_TED.sh ' + str(filename_text),
stdout=subprocess.PIPE, shell=True)
out, err = process.communicate()
print(out.decode("utf-8"))
if keywords_text in out.decode("utf-8"):
self.result.setText('"' + keywords_text + '"' + ' is in speech')
self.result.adjustSize()
else:
self.result.setText('"' + keywords_text + '"' + ' is not in speech')
self.result.adjustSize()
self.result.move(20, 140)
print(self.filename_edit.text())
self.statusBar().showMessage('ready')
示例2: WinNewEntry
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class WinNewEntry(QWidget):
def __init__(self, controller):
super().__init__()
self.initUI()
self.controller = controller
def initUI(self):
self.setGeometry(200,200,500,200)
self.setWindowTitle('Tag Indexer: Add an entry')
lblURL = QLabel('URL:', self)
lblTags = QLabel('Tags:', self)
lblTags.setToolTip('À séparer par des virgules')
self.champURL = QLineEdit(self)
self.champURL.returnPressed.connect(self.save)
self.champTags = QLineEdit(self)
self.champTags.returnPressed.connect(self.save)
btnEnr = QPushButton('Enregistrer',self)
btnEnr.clicked.connect(self.save)
btnAnnul = QPushButton('Annuler',self)
btnAnnul.clicked.connect(self.hide)
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(lblURL, 0,0)
grid.addWidget(self.champURL, 0, 3, 1, 6)
grid.addWidget(lblTags, 4, 0)
grid.addWidget(self.champTags, 4, 3, 1, 6)
grid.addWidget(btnAnnul, 9, 7)
grid.addWidget(btnEnr, 9, 8)
self.setLayout(grid)
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.hide()
def closeEvent(self, e):
self.hide()
e.ignore()
def save(self):
tags = self.champTags.text().split(",")
tags = [i for i in map(lambda s: s.rstrip(" \t").lstrip(" \t"), tags)]
e = NewDataEvent(self.champURL.text(), tags)
self.champURL.setText('')
self.champTags.setText('')
self.hide()
self.controller.notify(e)
def cancel(self):
self.champURL.setText('')
self.champTags.setText('')
self.hide()
示例3: InputDialog
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class InputDialog(QDialog):
def __init__(self,parent=None):
super(InputDialog,self).__init__(parent)
self.setWindowTitle("輸入服務器地址和用戶名")
self.resize(300,150)
self.setWindowIcon(QIcon('images/icon.jpg'))
self.createGrid()
def createGrid(self):
names = ('呆尐兔兔','康師傅','哇哈哈','礦泉水','農夫山泉','蛤蛤','操作係統','計算機','網絡','數據通信')
nick_name = names[int(time.time() * 1000) % 10]
layout = QGridLayout(self)
self.setLayout(layout)
#添加三個輸入框
self.ipEdit = QLineEdit('127.0.0.1')
self.portEdit = QLineEdit('9999')
self.nicknameEdit = QLineEdit(nick_name)
layout.addWidget(QLabel("IP地址"),0,0,1,2)
layout.addWidget(self.ipEdit,0,2,1,10)
layout.addWidget(QLabel("端口號"),1,0,1,2)
layout.addWidget(self.portEdit,1,2,1,10)
layout.addWidget(QLabel("昵稱"),2,0,1,2)
layout.addWidget(self.nicknameEdit,2,2,1,10)
#添加提交按鈕
submit_btn = QPushButton('確認',self)
submit_btn.clicked.connect(self.submit)
layout.addWidget(submit_btn,3,7,1,5)
def submit(self):
ip,port,nickname = self.ipEdit.text(),self.portEdit.text(),self.nicknameEdit.text()
def is_valid_ip(ip_address):
if ip_address == "localhost":
return True
if not ip:
return False
ip_address = str(ip_address).split('.')
if len(ip_address) != 4:
return False
for each in ip_address :
if not each.isdigit():
return False
if int(each) > 255 or int(each) < 0:
return False
return True
def is_valid_port(port):
return port and str(port).isdigit() and ( 0 < int(port) < 65536)
def is_valid_nickname(nickname):
return nickname and ( 0 < len(nickname) < 21)
if not is_valid_ip(ip):
QMessageBox.information(self,"警告","請輸入正確的IP地址")
elif not is_valid_port(port):
QMessageBox.information(self,"警告","請輸入正確的端口號")
elif not is_valid_nickname(nickname):
QMessageBox.information(self,"警告","請輸入正確的昵稱,1-20字符")
else:
self.hide()
startGame(ip,port,nickname)
示例4: GalleryListEdit
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class GalleryListEdit(misc.BasePopup):
def __init__(self, gallery_list, item, parent):
super().__init__(parent, blur=False)
self.gallery_list = gallery_list
self.item = item
main_layout = QFormLayout(self.main_widget)
self.name_edit = QLineEdit(gallery_list.name, self)
main_layout.addRow("Name:", self.name_edit)
self.filter_edit = QLineEdit(self)
if gallery_list.filter:
self.filter_edit.setText(gallery_list.filter)
what_is_filter = misc.ClickedLabel("What is filter? (Hover)")
what_is_filter.setToolTip(app_constants.WHAT_IS_FILTER)
what_is_filter.setToolTipDuration(9999999999)
main_layout.addRow(what_is_filter)
main_layout.addRow("Filter", self.filter_edit)
main_layout.addRow(self.buttons_layout)
self.add_buttons("Close")[0].clicked.connect(self.close)
self.add_buttons("Apply")[0].clicked.connect(self.accept)
self.adjustSize()
def accept(self):
name = self.name_edit.text()
self.item.setText(name)
self.gallery_list.name = name
self.gallery_list.filter = self.filter_edit.text()
gallerydb.add_method_queue(gallerydb.ListDB.modify_list, True, self.gallery_list, True, True)
gallerydb.add_method_queue(self.gallery_list.scan, True)
self.close()
示例5: ManualInstallWidget
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class ManualInstallWidget(QWidget):
"""Manually Installed plugins widget"""
def __init__(self, parent):
super(ManualInstallWidget, self).__init__()
self._parent = parent
vbox = QVBoxLayout(self)
form = QFormLayout()
self._txtName = QLineEdit()
self._txtName.setPlaceholderText('my_plugin')
self._txtVersion = QLineEdit()
self._txtVersion.setPlaceholderText('0.1')
form.addRow(translations.TR_PROJECT_NAME, self._txtName)
form.addRow(translations.TR_VERSION, self._txtVersion)
vbox.addLayout(form)
hPath = QHBoxLayout()
self._txtFilePath = QLineEdit()
self._txtFilePath.setPlaceholderText(os.path.join(
os.path.expanduser('~'), 'full', 'path', 'to', 'plugin.zip'))
self._btnFilePath = QPushButton(QIcon(":img/open"), '')
self.completer, self.dirs = QCompleter(self), QDirModel(self)
self.dirs.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot)
self.completer.setModel(self.dirs)
self._txtFilePath.setCompleter(self.completer)
hPath.addWidget(QLabel(translations.TR_FILENAME))
hPath.addWidget(self._txtFilePath)
hPath.addWidget(self._btnFilePath)
vbox.addLayout(hPath)
vbox.addSpacerItem(QSpacerItem(0, 1, QSizePolicy.Expanding,
QSizePolicy.Expanding))
hbox = QHBoxLayout()
hbox.addSpacerItem(QSpacerItem(1, 0, QSizePolicy.Expanding))
self._btnInstall = QPushButton(translations.TR_INSTALL)
hbox.addWidget(self._btnInstall)
vbox.addLayout(hbox)
#Signals
self._btnFilePath.clicked['bool'].connect(self._load_plugin_path)
self._btnInstall.clicked['bool'].connect(self.install_plugin)
def _load_plugin_path(self):
"""Ask the user a plugin filename"""
path = QFileDialog.getOpenFileName(self,
translations.TR_SELECT_PLUGIN_PATH)
if path:
self._txtFilePath.setText(path)
def install_plugin(self):
"""Install a plugin manually"""
if self._txtFilePath.text() and self._txtName.text():
plug = []
plug.append(self._txtName.text())
plug.append(self._txtVersion.text())
plug.append('')
plug.append('')
plug.append('')
plug.append(self._txtFilePath.text())
self._parent.install_plugins_manually([plug])
示例6: DyStockDataHistTicksVerifyDlg
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class DyStockDataHistTicksVerifyDlg(QDialog):
def __init__(self, data, parent=None):
super().__init__(parent)
self._data = data
self._initUi()
def _initUi(self):
self.setWindowTitle('曆史分筆數據校驗')
# 控件
startDateLable = QLabel('開始日期')
self._startDateLineEdit = QLineEdit(datetime.now().strftime("%Y-%m-%d"))
endDateLable = QLabel('結束日期')
self._endDateLineEdit = QLineEdit(datetime.now().strftime("%Y-%m-%d"))
self._addCheckBox = QCheckBox('校驗缺失曆史分筆數據')
self._addCheckBox.setChecked(True)
self._deleteCheckBox = QCheckBox('校驗無效曆史分筆數據')
#self._deleteCheckBox.setChecked(True)
cancelPushButton = QPushButton('Cancel')
okPushButton = QPushButton('OK')
cancelPushButton.clicked.connect(self._cancel)
okPushButton.clicked.connect(self._ok)
# 布局
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(startDateLable, 0, 0)
grid.addWidget(self._startDateLineEdit, 1, 0)
grid.addWidget(endDateLable, 0, 1)
grid.addWidget(self._endDateLineEdit, 1, 1)
grid.addWidget(self._addCheckBox, 2, 0)
grid.addWidget(self._deleteCheckBox, 2, 1)
grid.addWidget(okPushButton, 3, 1)
grid.addWidget(cancelPushButton, 3, 0)
self.setLayout(grid)
def _ok(self):
self._data['startDate'] = self._startDateLineEdit.text()
self._data['endDate'] = self._endDateLineEdit.text()
self._data['verifyMissing'] = self._addCheckBox.isChecked()
self._data['verifyInvalid'] = self._deleteCheckBox.isChecked()
self.accept()
def _cancel(self):
self.reject()
示例7: ASCreation
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class ASCreation(QWidget):
@update_paths
def __init__(self, nodes, links, controller):
super().__init__()
self.controller = controller
self.nodes = nodes
self.links = links
self.setWindowTitle('Create AS')
# AS type
AS_type = QLabel('Type')
self.AS_type_list = QObjectComboBox()
self.AS_type_list.addItems(AS_subtypes)
# AS name
AS_name = QLabel('Name')
self.name_edit = QLineEdit()
self.name_edit.setMaximumWidth(120)
# AS ID
AS_id = QLabel('ID')
self.id_edit = QLineEdit()
self.id_edit.setMaximumWidth(120)
# confirmation button
button_create_AS = QPushButton()
button_create_AS.setText('Create AS')
button_create_AS.clicked.connect(self.create_AS)
# cancel button
cancel_button = QPushButton()
cancel_button.setText('Cancel')
# position in the grid
layout = QGridLayout()
layout.addWidget(AS_type, 0, 0, 1, 1)
layout.addWidget(self.AS_type_list, 0, 1, 1, 1)
layout.addWidget(AS_name, 1, 0, 1, 1)
layout.addWidget(self.name_edit, 1, 1, 1, 1)
layout.addWidget(AS_id, 2, 0, 1, 1)
layout.addWidget(self.id_edit, 2, 1, 1, 1)
layout.addWidget(button_create_AS, 3, 0, 1, 1)
layout.addWidget(cancel_button, 3, 1, 1, 1)
self.setLayout(layout)
def create_AS(self):
# automatic initialization of the AS id in case it is empty
id = self.id_edit.text()
id = int(id) if id else len(self.network.pnAS) + 1
new_AS = self.network.AS_factory(
self.AS_type_list.text,
self.name_edit.text(),
id,
self.links,
self.nodes
)
self.close()
示例8: FindInFilesActions
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class FindInFilesActions(QWidget):
searchRequested = pyqtSignal('QString', bool, bool, bool)
def __init__(self, parent=None):
super().__init__(parent)
self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Ignored)
self._scope = QComboBox()
self._scope.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.ninjaide = IDE.get_service('ide')
self.ninjaide.filesAndProjectsLoaded.connect(
self._update_combo_projects)
main_layout = QVBoxLayout(self)
hbox = QHBoxLayout()
hbox.addWidget(QLabel(translations.TR_SEARCH_SCOPE))
hbox.addWidget(self._scope)
main_layout.addLayout(hbox)
widgets_layout = QGridLayout()
widgets_layout.setContentsMargins(0, 0, 0, 0)
self._line_search = QLineEdit()
self._line_search.setPlaceholderText(translations.TR_SEARCH_FOR)
main_layout.addWidget(self._line_search)
# TODO: replace
self._check_cs = QCheckBox(translations.TR_SEARCH_CASE_SENSITIVE)
self._check_cs.setChecked(True)
widgets_layout.addWidget(self._check_cs, 2, 0)
self._check_wo = QCheckBox(translations.TR_SEARCH_WHOLE_WORDS)
widgets_layout.addWidget(self._check_wo, 2, 1)
self._check_re = QCheckBox(translations.TR_SEARCH_REGEX)
widgets_layout.addWidget(self._check_re, 3, 0)
self._check_recursive = QCheckBox('Recursive')
widgets_layout.addWidget(self._check_recursive, 3, 1)
main_layout.addLayout(widgets_layout)
main_layout.addStretch(1)
# Connections
self._line_search.returnPressed.connect(self.search_requested)
def _update_combo_projects(self):
projects = self.ninjaide.get_projects()
for nproject in projects.values():
self._scope.addItem(nproject.name, nproject.path)
@property
def current_project_path(self):
"""Returns NProject.path of current project"""
return self._scope.itemData(self._scope.currentIndex())
def search_requested(self):
text = self._line_search.text()
if not text.strip():
return
has_search = self._line_search.text()
cs = self._check_cs.isChecked()
regex = self._check_re.isChecked()
wo = self._check_wo.isChecked()
self.searchRequested.emit(has_search, cs, regex, wo)
示例9: DisjointSPWindow
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class DisjointSPWindow(QWidget):
algorithms = (
'Constrained A*',
'Bhandari algorithm',
'Suurbale algorithm',
'Linear programming'
)
def __init__(self, controller):
super().__init__()
self.controller = controller
self.setWindowTitle('Disjoint shortest paths algorithms')
algorithm = QLabel('Algorithm')
self.dsp_list = QComboBox()
self.dsp_list.addItems(self.algorithms)
source = QLabel('Source')
self.source_edit = QLineEdit()
destination = QLabel('Destination')
self.destination_edit = QLineEdit()
number_of_paths = QLabel('Number of paths')
self.number_of_paths_edit = QLineEdit()
# confirmation button
button_compute = QPushButton()
button_compute.setText('Compute')
button_compute.clicked.connect(self.compute_dsp)
# position in the grid
layout = QGridLayout()
layout.addWidget(algorithm, 0, 0, 1, 1)
layout.addWidget(self.dsp_list, 0, 1, 1, 1)
layout.addWidget(source, 1, 0, 1, 1)
layout.addWidget(self.source_edit, 1, 1, 1, 1)
layout.addWidget(destination, 2, 0, 1, 1)
layout.addWidget(self.destination_edit, 2, 1, 1, 1)
layout.addWidget(number_of_paths, 3, 0, 1, 1)
layout.addWidget(self.number_of_paths_edit, 3, 1, 1, 1)
layout.addWidget(button_compute, 4, 0, 1, 2)
self.setLayout(layout)
@update_paths
def compute_dsp(self, _):
source = self.network.nf(name=self.source_edit.text())
destination = self.network.nf(name=self.destination_edit.text())
algorithm = {
'Constrained A*': self.network.A_star_shortest_pair,
'Bhandari algorithm': self.network.bhandari,
'Suurbale algorithm': self.network.suurbale,
'Linear programming': lambda: 'to repair'
}[self.dsp_list.currentText()]
nodes, physical_links = algorithm(source, destination)
self.view.select(*(nodes + physical_links))
示例10: LeapWidget
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class LeapWidget(QWidget):
sig_leap = pyqtSignal(str, bool, bool)
def __init__(self, parent: QWidget) -> None:
super().__init__(parent,
Qt.Window |
Qt.WindowStaysOnTopHint |
# Qt.X11BypassWindowManagerHint |
Qt.FramelessWindowHint)
self._build_gui()
def _build_gui(self):
self._line_edit = QLineEdit(self)
vbox = QVBoxLayout()
vbox.addWidget(self._line_edit)
vbox.setContentsMargins(0, 0, 0, 0)
self.setLayout(vbox)
self.resize(200, 40)
self._line_edit.editingFinished.connect(self.hide)
self._line_edit.textChanged.connect(self.on_text_changed)
def showEvent(self, ev):
super().showEvent(ev)
self.place_widget()
def place_widget(self):
parent = self.parentWidget()
pos = parent.mapToGlobal(self.parentWidget().viewport().geometry().bottomRight())
self.move(pos.x() - self.width(),
pos.y() - self.height())
def focusOutEvent(self, ev) -> None:
print("focus out")
super().focusOutEvent(ev)
self.hide()
def hideEvent(self, ev):
super().hideEvent(ev)
def keyPressEvent(self, ev) -> None:
if ev.key() in (Qt.Key_Return, Qt.Key_Enter):
self.parentWidget().keyPressEvent(ev)
else:
super().keyPressEvent(ev)
if ev.key() == Qt.Key_Escape:
self.hide()
elif ev.key() == Qt.Key_Up:
self.sig_leap.emit(self._line_edit.text(), False, True)
elif ev.key() == Qt.Key_Down:
self.sig_leap.emit(self._line_edit.text(), True, True)
def on_text_changed(self, text: str) -> None:
self.sig_leap.emit(text, True, False)
示例11: DatePlot
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class DatePlot(QWidget):
def __init__(self, plotWindow):
QWidget.__init__(self)
self.plotWindow = plotWindow
self.dateStr = QLineEdit()
self.dateStr.textChanged.connect(self.loadConf)
self.cal = Calendar(self)
self.cal.showDate()
self.choseDate = QPushButton(self)
self.choseDate.setIcon(self.mainwindow.icon_calendar)
self.choseDate.clicked.connect(partial(self.cal.setVisible, True))
self.refresh = QPushButton(self)
self.refresh.setIcon(self.mainwindow.icon_refresh)
self.refresh.clicked.connect(self.tryDraw)
self.layout = QGridLayout()
self.layout.addWidget(self.refresh, 0, 0)
self.layout.addWidget(self.choseDate, 0, 1)
self.layout.addWidget(self.dateStr, 0, 2, 1, 5)
self.setLayout(self.layout)
@property
def mainwindow(self):
return self.plotWindow.mainwindow
@property
def realtime(self):
return self.cal.checkboxRealTime.isChecked()
@property
def dateEnd(self):
return self.datetime + dt.timedelta(days=self.cal.spinboxDays.value())
def updateDate(self, datetime):
self.dateStr.setText(datetime.isoformat()[:-3])
def loadConf(self):
datestr = self.dateStr.text()
if len(datestr) in [10, 16]:
self.datetime = str2date(datestr)
if not self.cal.confAuto.isChecked():
self.config = loadConf(self.dateStr.text())
else:
self.config = self.mainwindow.db.pollDbConf(self.dateStr.text())
self.plotWindow.constructGroupbox(self.config)
else:
pass
def tryDraw(self):
try:
self.plotWindow.graph.draw_idle()
except AttributeError:
pass
示例12: FindReplaceDialog
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class FindReplaceDialog(QDialog):
"""
Display a dialog for getting:
* A term to find,
* An optional value to replace the search term,
* A flag to indicate if the user wishes to replace all.
"""
def __init__(self, parent=None):
super().__init__(parent)
def setup(self, find=None, replace=None, replace_flag=False):
self.setMinimumSize(600, 200)
self.setWindowTitle(_('Find / Replace'))
widget_layout = QVBoxLayout()
self.setLayout(widget_layout)
# Find.
find_label = QLabel(_('Find:'))
self.find_term = QLineEdit()
self.find_term.setText(find)
widget_layout.addWidget(find_label)
widget_layout.addWidget(self.find_term)
# Replace
replace_label = QLabel(_('Replace (optional):'))
self.replace_term = QLineEdit()
self.replace_term.setText(replace)
widget_layout.addWidget(replace_label)
widget_layout.addWidget(self.replace_term)
# Global replace.
self.replace_all_flag = QCheckBox(_('Replace all?'))
self.replace_all_flag.setChecked(replace_flag)
widget_layout.addWidget(self.replace_all_flag)
button_box = QDialogButtonBox(QDialogButtonBox.Ok |
QDialogButtonBox.Cancel)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
widget_layout.addWidget(button_box)
def find(self):
"""
Return the value the user entered to find.
"""
return self.find_term.text()
def replace(self):
"""
Return the value the user entered for replace.
"""
return self.replace_term.text()
def replace_flag(self):
"""
Return the value of the global replace flag.
"""
return self.replace_all_flag.isChecked()
示例13: Example
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class Example(QWidget):
def __init__(self):
super().__init__()
self.ip_edit = QLineEdit('http://195.208.117.228:8080')
self.uuid_edit = QLineEdit()
self.init_ui()
def init_ui(self):
self.setGeometry(300, 300, 300, 220)
self.setWindowTitle('Operator app')
self.center()
main_layout = QGridLayout(self)
ip_title = QLabel('IP:')
main_layout.addWidget(ip_title , 0, 0)
main_layout.addWidget(self.ip_edit , 0, 1, 1, 3)
uuid_title = QLabel('UUID:')
main_layout.addWidget(uuid_title , 1, 0)
main_layout.addWidget(self.uuid_edit, 1, 1, 1, 3)
forward_button = QPushButton('Forward', self)
left_button = QPushButton('Left', self)
backward_button = QPushButton('Backward', self)
right_button = QPushButton('Right', self)
main_layout.addWidget(forward_button, 3, 2)
main_layout.addWidget(left_button, 4, 1)
main_layout.addWidget(backward_button, 4, 2)
main_layout.addWidget(right_button, 4, 3)
forward_button.clicked.connect(self.button_clicked)
left_button.clicked.connect(self.button_clicked)
backward_button.clicked.connect(self.button_clicked)
right_button.clicked.connect(self.button_clicked)
self.show()
def send_command(self, command):
data = {'clientUID': self.uuid_edit.text(), 'command': command, 'args':[]}
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
requests.post(self.ip_edit.text() + '/command', data=json.dumps(data), headers=headers)
def button_clicked(self):
sender = self.sender()
self.send_command(sender.text())
def close_event(self, event):
reply = QMessageBox.question(self, 'Message',
"Are you sure to quit?", QMessageBox.Yes |
QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
示例14: LoginDialog
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class LoginDialog(QDialog):
"""蝦米音樂登錄對話框"""
login_success = pyqtSignal([object])
def __init__(self, parent=None):
super().__init__(parent)
self._label = QLabel(self)
self.username_input = QLineEdit(self)
self.pw_input = QLineEdit(self)
self.pw_input.setEchoMode(QLineEdit.Password)
self._btn_box = QDialogButtonBox(self)
self._ok_btn = QDialogButtonBox.Ok
self._setup_ui()
self.setWindowTitle('蝦米賬號密碼登錄')
self._btn_box.clicked.connect(self.do_verify)
def _setup_ui(self):
self._btn_box.addButton(self._ok_btn)
self._label.hide()
self._layout = QFormLayout(self)
self._layout.addRow('郵箱/手機號:', self.username_input)
self._layout.addRow('密碼:', self.pw_input)
self._layout.addRow(self._label)
self._layout.addRow(self._btn_box)
def show_msg(self, msg, error=False):
"""顯示提示信息"""
self._label.show()
self._label.setTextFormat(Qt.RichText)
if error:
color = 'red'
else:
color = 'green'
self._label.setText('<span style="color: {};">{}</span>'
.format(color, msg))
def do_verify(self):
"""校驗用戶名和密碼,成功則發送信號"""
username = self.username_input.text()
password = self.pw_input.text()
pw_md5digest = hashlib.md5(password.encode('utf-8')).hexdigest()
rv = api.login(username, pw_md5digest)
code, msg = rv['ret'][0].split('::')
is_success = code == 'SUCCESS'
self.show_msg(msg, error=(not is_success))
if is_success:
data = rv['data']['data']
schema = UserSchema(strict=True)
user, _ = schema.load(data)
self.login_success.emit(user)
self.close()
示例15: Score
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import text [as 別名]
class Score(_base.Group, scoreproperties.ScoreProperties):
@staticmethod
def title(_=_base.translate):
return _("Score")
def createWidgets(self, layout):
self.pieceLabel = QLabel()
self.piece = QLineEdit()
self.pieceLabel.setBuddy(self.piece)
self.opusLabel = QLabel()
self.opus = QLineEdit()
self.opusLabel.setBuddy(self.opus)
self.scoreProps = QGroupBox(checkable=True, checked=False)
scoreproperties.ScoreProperties.createWidgets(self)
grid = QGridLayout()
grid.addWidget(self.pieceLabel, 0 ,0)
grid.addWidget(self.piece, 0, 1)
grid.addWidget(self.opusLabel, 1, 0)
grid.addWidget(self.opus, 1, 1)
layout.addLayout(grid)
layout.addWidget(self.scoreProps)
layout = QVBoxLayout()
self.scoreProps.setLayout(layout)
scoreproperties.ScoreProperties.layoutWidgets(self, layout)
scorewiz = self.scoreProps.window()
self.setPitchLanguage(scorewiz.pitchLanguage())
scorewiz.pitchLanguageChanged.connect(self.setPitchLanguage)
def translateWidgets(self):
self.pieceLabel.setText(_("Piece:"))
self.opusLabel.setText(_("Opus:"))
self.scoreProps.setTitle(_("Properties"))
scoreproperties.ScoreProperties.translateWidgets(self)
def accepts(self):
return (StaffGroup, _base.Part)
def makeNode(self, node):
score = ly.dom.Score(node)
h = ly.dom.Header()
piece = self.piece.text().strip()
opus = self.opus.text().strip()
if piece:
h['piece'] = ly.dom.QuotedString(piece)
if opus:
h['opus'] = ly.dom.QuotedString(opus)
if len(h):
score.append(h)
return score
def globalSection(self, builder):
if self.scoreProps.isChecked():
return scoreproperties.ScoreProperties.globalSection(self, builder)