本文整理匯總了Python中qtpy.QtWidgets.QInputDialog.getText方法的典型用法代碼示例。如果您正苦於以下問題:Python QInputDialog.getText方法的具體用法?Python QInputDialog.getText怎麽用?Python QInputDialog.getText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qtpy.QtWidgets.QInputDialog
的用法示例。
在下文中一共展示了QInputDialog.getText方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rename_file
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def rename_file(self, fname):
"""Rename file"""
path, valid = QInputDialog.getText(self, _('Rename'),
_('New name:'), QLineEdit.Normal,
osp.basename(fname))
if valid:
path = osp.join(osp.dirname(fname), to_text_string(path))
if path == fname:
return
if osp.exists(path):
if QMessageBox.warning(self, _("Rename"),
_("Do you really want to rename <b>%s</b> and "
"overwrite the existing file <b>%s</b>?"
) % (osp.basename(fname), osp.basename(path)),
QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
return
try:
misc.rename_file(fname, path)
self.parent_widget.renamed.emit(fname, path)
return path
except EnvironmentError as error:
QMessageBox.critical(self, _("Rename"),
_("<b>Unable to rename file <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (osp.basename(fname), to_text_string(error)))
示例2: create_new_folder
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def create_new_folder(self, current_path, title, subtitle, is_package):
"""Create new folder"""
if current_path is None:
current_path = ''
if osp.isfile(current_path):
current_path = osp.dirname(current_path)
name, valid = QInputDialog.getText(self, title, subtitle,
QLineEdit.Normal, "")
if valid:
dirname = osp.join(current_path, to_text_string(name))
try:
os.mkdir(dirname)
except EnvironmentError as error:
QMessageBox.critical(self, title,
_("<b>Unable "
"to create folder <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (dirname, to_text_string(error)))
finally:
if is_package:
fname = osp.join(dirname, '__init__.py')
try:
with open(fname, 'wb') as f:
f.write(to_binary_string('#'))
return dirname
except EnvironmentError as error:
QMessageBox.critical(self, title,
_("<b>Unable "
"to create file <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (fname,
to_text_string(error)))
示例3: change_format
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def change_format(self):
"""
Ask user for display format for floats and use it.
This function also checks whether the format is valid and emits
`sig_option_changed`.
"""
format, valid = QInputDialog.getText(self, _('Format'),
_("Float formatting"),
QLineEdit.Normal,
self.dataModel.get_format())
if valid:
format = str(format)
try:
format % 1.1
except:
msg = _("Format ({}) is incorrect").format(format)
QMessageBox.critical(self, _("Error"), msg)
return
if not format.startswith('%'):
msg = _("Format ({}) should start with '%'").format(format)
QMessageBox.critical(self, _("Error"), msg)
return
self.dataModel.set_format(format)
self.sig_option_changed.emit('dataframe_format', format)
示例4: set_umr_namelist
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def set_umr_namelist(self):
"""Set UMR excluded modules name list"""
arguments, valid = QInputDialog.getText(self, _('UMR'),
_("Set the list of excluded modules as "
"this: <i>numpy, scipy</i>"),
QLineEdit.Normal,
", ".join(self.get_option('umr/namelist')))
if valid:
arguments = to_text_string(arguments)
if arguments:
namelist = arguments.replace(' ', '').split(',')
fixed_namelist = [module_name for module_name in namelist
if programs.is_module_installed(module_name)]
invalid = ", ".join(set(namelist)-set(fixed_namelist))
if invalid:
QMessageBox.warning(self, _('UMR'),
_("The following modules are not "
"installed on your machine:\n%s"
) % invalid, QMessageBox.Ok)
QMessageBox.information(self, _('UMR'),
_("Please note that these changes will "
"be applied only to new Python/IPython "
"consoles"), QMessageBox.Ok)
else:
fixed_namelist = []
self.set_option('umr/namelist', fixed_namelist)
示例5: get_arguments
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def get_arguments(self):
arguments, valid = QInputDialog.getText(self, _('Arguments'),
_('Command line arguments:'),
QLineEdit.Normal,
self.arguments)
if valid:
self.arguments = to_text_string(arguments)
return valid
示例6: change_exteditor
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def change_exteditor(self):
"""Change external editor path"""
path, valid = QInputDialog.getText(self, _('External editor'),
_('External editor executable path:'),
QLineEdit.Normal,
self.get_option('external_editor/path'))
if valid:
self.set_option('external_editor/path', to_text_string(path))
示例7: edit_filter
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def edit_filter(self):
"""Edit name filters"""
filters, valid = QInputDialog.getText(self, _('Edit filename filters'),
_('Name filters:'),
QLineEdit.Normal,
", ".join(self.name_filters))
if valid:
filters = [f.strip() for f in to_text_string(filters).split(',')]
self.parent_widget.sig_option_changed.emit('name_filters', filters)
self.set_name_filters(filters)
示例8: insert_node
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def insert_node(self):
index = self.currentIndex()
parentnode = index.internalPointer() or self.model().root
key, b = QInputDialog.getText(
self, "Insert Json node", "Insert key for new node:")
if not b:
return
node = JsonNode(key)
parentnode.add(node)
row = parentnode.index(node)
self.model().beginInsertRows(index, row, row)
self.model().endInsertRows()
示例9: change_format
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def change_format(self):
"""Change display format"""
format, valid = QInputDialog.getText(
self, _("Format"), _("Float formatting"), QLineEdit.Normal, self.model.get_format()
)
if valid:
format = str(format)
try:
format % 1.1
except:
QMessageBox.critical(self, _("Error"), _("Format (%s) is incorrect") % format)
return
self.model.set_format(format)
示例10: edit_key
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def edit_key(self):
index = self.currentIndex()
if index.isValid():
node = index.internalPointer()
key, b = QInputDialog.getText(
self, "Edit Json item", "Insert new key for item:",
text=node.key
)
if not b:
return
node.key = key
try: # PyQt5
self.model().dataChanged.emit(index, index, [Qt.DisplayRole])
except TypeError: # PyQt4, PySide
self.model().dataChanged.emit(index, index)
示例11: insert_item
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def insert_item(self):
index = self.currentIndex()
if index.isValid():
node = index.internalPointer()
else:
node = self.model().root
key, b = QInputDialog.getText(
self, "Insert Json item", "Insert key for new item:")
if not b:
return
item = JsonItem(key)
node.add(item)
row = node.index(item)
self.model().beginInsertRows(index, row, row)
self.model().endInsertRows()
示例12: set_umr_namelist
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def set_umr_namelist(self):
"""Set UMR excluded modules name list"""
arguments, valid = QInputDialog.getText(self, _('UMR'),
_("Set the list of excluded modules as "
"this: <i>numpy, scipy</i>"),
QLineEdit.Normal,
", ".join(self.get_option('umr/namelist')))
if valid:
arguments = to_text_string(arguments)
if arguments:
namelist = arguments.replace(' ', '').split(',')
fixed_namelist = []
non_ascii_namelist = []
for module_name in namelist:
if PY2:
if all(ord(c) < 128 for c in module_name):
if programs.is_module_installed(module_name):
fixed_namelist.append(module_name)
else:
QMessageBox.warning(self, _('Warning'),
_("You are working with Python 2, this means that "
"you can not import a module that contains non-"
"ascii characters."), QMessageBox.Ok)
non_ascii_namelist.append(module_name)
elif programs.is_module_installed(module_name):
fixed_namelist.append(module_name)
invalid = ", ".join(set(namelist)-set(fixed_namelist)-
set(non_ascii_namelist))
if invalid:
QMessageBox.warning(self, _('UMR'),
_("The following modules are not "
"installed on your machine:\n%s"
) % invalid, QMessageBox.Ok)
QMessageBox.information(self, _('UMR'),
_("Please note that these changes will "
"be applied only to new Python/IPython "
"consoles"), QMessageBox.Ok)
else:
fixed_namelist = []
self.set_option('umr/namelist', fixed_namelist)
示例13: toogle_breakpoint
# 需要導入模塊: from qtpy.QtWidgets import QInputDialog [as 別名]
# 或者: from qtpy.QtWidgets.QInputDialog import getText [as 別名]
def toogle_breakpoint(self, line_number=None, condition=None,
edit_condition=False):
"""Add/remove breakpoint."""
if not self.editor.is_python_like():
return
if line_number is None:
block = self.editor.textCursor().block()
else:
block = self.editor.document().findBlockByNumber(line_number-1)
data = block.userData()
if not data:
data = BlockUserData(self.editor)
data.breakpoint = True
elif not edit_condition:
data.breakpoint = not data.breakpoint
data.breakpoint_condition = None
if condition is not None:
data.breakpoint_condition = condition
if edit_condition:
condition = data.breakpoint_condition
condition, valid = QInputDialog.getText(self.editor,
_('Breakpoint'),
_("Condition:"),
QLineEdit.Normal,
condition)
if not valid:
return
data.breakpoint = True
data.breakpoint_condition = str(condition) if condition else None
if data.breakpoint:
text = to_text_string(block.text()).strip()
if len(text) == 0 or text.startswith(('#', '"', "'")):
data.breakpoint = False
block.setUserData(data)
self.editor.sig_flags_changed.emit()
self.editor.sig_breakpoints_changed.emit()