本文整理汇总了Python中PyQt4.Qt.QInputDialog类的典型用法代码示例。如果您正苦于以下问题:Python QInputDialog类的具体用法?Python QInputDialog怎么用?Python QInputDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QInputDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match_all_above_thresh
def match_all_above_thresh(fac, threshold=None):
'do matching and assign all above thresh'
if threshold == None:
# User ask
dlg = QInputDialog()
threshres = dlg.getText(None, 'Threshold Selector',
'Enter a matching threshold.\n'+
'The system will query each chip and assign all matches above this thresh')
if not threshres[1]:
logmsg('Cancelled all match')
return
try:
threshold = float(str(threshres[0]))
except ValueError:
logerr('The threshold must be a number')
qm = fac.hs.qm
cm = fac.hs.cm
nm = fac.hs.nm
vm = fac.hs.vm
# Get model ready
vm.sample_train_set()
fac.hs.ensure_model()
# Do all queries
for qcx in iter(cm.get_valid_cxs()):
qcid = cm.cx2_cid[qcx]
logmsg('Querying CID='+str(qcid))
query_name = cm.cx2_name(qcx)
logdbg(str(qcx))
logdbg(str(type(qcx)))
cm.load_features(qcx)
res = fac.hs.query(qcid)
# Match only those above a thresh
res.num_top_min = 0
res.num_extra_return = 0
res.top_thresh = threshold
top_cx = res.top_cx()
if len(top_cx) == 0:
print('No matched for cid='+str(qcid))
continue
top_names = cm.cx2_name(top_cx)
all_names = np.append(top_names,[query_name])
if all([nm.UNIDEN_NAME() == name for name in all_names]):
# If all names haven't been identified, make a new one
new_name = nm.get_new_name()
else:
# Rename to the most frequent non ____ name seen
from collections import Counter
name_freq = Counter(np.append(top_names,[query_name])).most_common()
new_name = name_freq[0][0]
if new_name == nm.UNIDEN_NAME():
new_name = name_freq[1][0]
# Do renaming
cm.rename_chip(qcx, new_name)
for cx in top_cx:
cm.rename_chip(cx, new_name)
fac.hs.uim.populate_tables()
示例2: add_new_prop
def add_new_prop(fac, propname=None):
'add a new property to keep track of'
if propname is None:
# User ask
dlg = QInputDialog()
textres = dlg.getText(None, 'New Metadata Property','What is the new property name? ')
if not textres[1]:
logmsg('Cancelled new property')
return
propname = str(textres[0])
logmsg('Adding property '+propname)
fac.hs.cm.add_user_prop(propname)
fac.hs.uim.populate_tables()
示例3: go_to_line_number
def go_to_line_number(self):
ed = self.gui.central.current_editor
if ed is None or not ed.has_line_numbers:
return
num, ok = QInputDialog.getInt(self.gui, _('Enter line number'), ('Line number:'), ed.current_line, 1, max(100000, ed.number_of_lines))
if ok:
ed.current_line = num
示例4: ask_user
def ask_user(self):
# Ask the user for a factor by which to multiply all font sizes
factor, ok = QInputDialog.getDouble(
self.gui, 'Enter a magnification factor', 'Allow font sizes in the book will be multiplied by the specified factor',
value=2, min=0.1, max=4
)
if ok:
# Ensure any in progress editing the user is doing is present in the container
self.boss.commit_all_editors_to_container()
try:
self.magnify_fonts(factor)
except Exception:
# Something bad happened report the error to the user
import traceback
error_dialog(self.gui, _('Failed to magnify fonts'), _(
'Failed to magnify fonts, click "Show details" for more info'),
det_msg=traceback.format_exc(), show=True)
# Revert to the saved restore point
self.boss.revert_requested(self.boss.global_undo.previous_container)
else:
# Show the user what changes we have made, allowing her to
# revert them if necessary
self.boss.show_current_diff()
# Update the editor UI to take into account all the changes we
# have made
self.boss.apply_container_update_to_gui()
示例5: debug_timing_test_pycode_from_a_dialog
def debug_timing_test_pycode_from_a_dialog( ): #bruce 051117
# TODO: rewrite this to call grab_text_using_dialog (should be easy)
title = "debug: time python code"
label = "one line of python to compile and exec REPEATEDLY in debug.py's globals()\n(or use @@@ to fake \\n for more lines)"
from PyQt4.Qt import QInputDialog
parent = None
text, ok = QInputDialog.getText(parent, title, label) # parent argument needed only in Qt4 [bruce 070329, more info above]
if not ok:
print "time python code code: cancelled"
return
# fyi: type(text) == <class '__main__.qt.QString'>
command = str(text)
command = command.replace("@@@",'\n')
print "trying to time the exec or eval of command:",command
from code import compile_command
try:
try:
mycode = compile( command + '\n', '<string>', 'exec') #k might need '\n\n' or '' or to be adaptive in length?
# 'single' means print value if it's an expression and value is not None; for timing we don't want that so use 'eval'
# or 'exec' -- but we don't know which one is correct! So try exec, if that fails try eval.
print "exec" # this happens even for an expr like 2+2 -- why?
except SyntaxError:
print "try eval" # i didn't yet see this happen
mycode = compile_command( command + '\n', '<string>', 'eval')
except:
print_compact_traceback("exception in compile_command: ")
return
if mycode is None:
print "incomplete command:",command
return
# mycode is now a code object
print_exec_timing_explored(mycode)
示例6: __init__
def __init__(self, pa, parent):
QDialog.__init__(self, parent)
TE_Dialog.__init__(self)
self.setupUi(self)
opts = smtp_prefs().parse()
self.test_func = parent.test_email_settings
self.test_button.clicked.connect(self.test)
self.from_.setText(unicode(self.from_.text())%opts.from_)
if pa:
self.to.setText(pa)
if opts.relay_host:
tmp_password=''
if opts.relay_prompt:
header=opts.relay_username+'@'+opts.relay_host
tmp_password, ok = QInputDialog.getText(self,
header,
_('Password:'),
mode=parent.relay_password.Password,
text=tmp_password)
if not ok:
tmp_password=''
else:
conf = smtp_prefs()
conf.set('relay_password', hexlify(str(tmp_password).encode('utf-8')))
tmp_password='password prompted'
else:
tmp_password=unhexlify(opts.relay_password).decode('utf-8')
self.label.setText(_('Using: %(un)s:%(pw)[email protected]%(host)s:%(port)s and %(enc)s encryption')%
dict(un=opts.relay_username, pw=tmp_password,
host=opts.relay_host, port=opts.relay_port, enc=opts.encryption))
示例7: edit_bookmark
def edit_bookmark(self):
indexes = self.bookmarks_table.selectionModel().selectedIndexes()
if indexes != []:
title, ok = QInputDialog.getText(self, _('Edit bookmark'), _('New title for bookmark:'), QLineEdit.Normal, self._model.data(indexes[0], Qt.DisplayRole).toString())
title = QVariant(unicode(title).strip())
if ok and title:
self._model.setData(indexes[0], title, Qt.EditRole)
示例8: auth_dialog
def auth_dialog(self):
response = QInputDialog.getText(None, "Ledger Wallet Authentication", self.message, QLineEdit.Password)
if not response[1]:
self.response = None
else:
self.response = str(response[0])
self.done.set()
示例9: rename_requested
def rename_requested(self, name, location):
loc = location.replace('/', os.sep)
base = os.path.dirname(loc)
newname, ok = QInputDialog.getText(self.gui, _('Rename') + ' ' + name,
'<p>'+_('Choose a new name for the library <b>%s</b>. ')%name +
'<p>'+_('Note that the actual library folder will be renamed.'),
text=name)
newname = sanitize_file_name_unicode(unicode(newname))
if not ok or not newname or newname == name:
return
newloc = os.path.join(base, newname)
if os.path.exists(newloc):
return error_dialog(self.gui, _('Already exists'),
_('The folder %s already exists. Delete it first.') %
newloc, show=True)
if (iswindows and len(newloc) >
LibraryDatabase2.WINDOWS_LIBRARY_PATH_LIMIT):
return error_dialog(self.gui, _('Too long'),
_('Path to library too long. Must be less than'
' %d characters.')%LibraryDatabase2.WINDOWS_LIBRARY_PATH_LIMIT,
show=True)
try:
os.rename(loc, newloc)
except:
import traceback
error_dialog(self.gui, _('Rename failed'),
_('Failed to rename the library at %s. '
'The most common cause for this is if one of the files'
' in the library is open in another program.') % loc,
det_msg=traceback.format_exc(), show=True)
return
self.stats.rename(location, newloc)
self.build_menus()
self.gui.iactions['Copy To Library'].build_menus()
示例10: word_dialog
def word_dialog(self, msg):
response = QInputDialog.getText(self.top_level_window(), "Ledger Wallet Authentication", msg, QLineEdit.Password)
if not response[1]:
self.word = None
else:
self.word = str(response[0])
self.done.set()
示例11: insert_link
def insert_link(self, *args):
link, ok = QInputDialog.getText(self, _('Create link'),
_('Enter URL'))
if not ok:
return
url = self.parse_link(unicode(link))
if url.isValid():
url = unicode(url.toString())
self.exec_command('createLink', url)
示例12: create_folder
def create_folder(self, item):
text, ok = QInputDialog.getText(self, _('Folder name'), _('Enter a name for the new folder'))
if ok and unicode(text):
c = QTreeWidgetItem(item, (unicode(text),))
c.setIcon(0, QIcon(I('mimetypes/dir.png')))
for item in self.folders.selectedItems():
item.setSelected(False)
c.setSelected(True)
self.folders.setCurrentItem(c)
示例13: expand_rois
def expand_rois(fac, percent_increase=None):
'expand rois by a percentage of the diagonal'
if percent_increase == None:
# User ask
dlg = QInputDialog()
percentres = dlg.getText(None, 'ROI Expansion Factor',
'Enter the percentage to expand the ROIs.\n'+
'The percentage is in terms of diagonal length')
if not percentres[1]:
logmsg('Cancelled all match')
return
try:
percent_increase = float(str(percentres[0]))
except ValueError:
logerr('The percentage must be a number')
cm = fac.hs.cm
gm = fac.hs.gm
logmsg('Resizing all chips')
for cx in iter(cm.get_valid_cxs()):
logmsg('Resizing cx='+str(cx))
# Get ROI size and Image size
[rx, ry, rw, rh] = cm.cx2_roi[cx]
[gw, gh] = gm.gx2_img_size(cm.cx2_gx[cx])
# Find Diagonal Increase
diag = np.sqrt(rw**2 + rh**2)
scale_factor = percent_increase/100.0
diag_increase = scale_factor * diag
target_diag = diag + diag_increase
# Find Width/Height Increase
ar = float(rw)/float(rh)
w_increase = np.sqrt(ar**2 * diag_increase**2 / (ar**2 + 1))
h_increase = w_increase / ar
# Find New xywh within image constriants
new_x = int(max(0, round(rx - w_increase / 2.0)))
new_y = int(max(0, round(ry - h_increase / 2.0)))
new_w = int(min(gw - new_x, round(rw + w_increase)))
new_h = int(min(gh - new_y, round(rh + h_increase)))
new_roi = [new_x, new_y, new_w, new_h]
logmsg('Old Roi: '+repr([rx, ry, rw, rh]))
cm.change_roi(cx, new_roi)
logmsg('\n')
logmsg('Done resizing all chips')
示例14: s_r_save_query
def s_r_save_query(self, *args):
names = ['']
names.extend(self.query_field_values)
try:
dex = names.index(self.saved_search_name)
except:
dex = 0
name = ''
while not name:
name, ok = QInputDialog.getItem(self, _('Save search/replace'),
_('Search/replace name:'), names, dex, True)
if not ok:
return
if not name:
error_dialog(self, _("Save search/replace"),
_("You must provide a name."), show=True)
new = True
name = unicode(name)
if name in self.queries.keys():
if not question_dialog(self, _("Save search/replace"),
_("That saved search/replace already exists and will be overwritten. "
"Are you sure?")):
return
new = False
query = {}
query['name'] = name
query['search_field'] = unicode(self.search_field.currentText())
query['search_mode'] = unicode(self.search_mode.currentText())
query['s_r_template'] = unicode(self.s_r_template.text())
query['s_r_src_ident'] = unicode(self.s_r_src_ident.currentText())
query['search_for'] = unicode(self.search_for.text())
query['case_sensitive'] = self.case_sensitive.isChecked()
query['replace_with'] = unicode(self.replace_with.text())
query['replace_func'] = unicode(self.replace_func.currentText())
query['destination_field'] = unicode(self.destination_field.currentText())
query['s_r_dst_ident'] = unicode(self.s_r_dst_ident.text())
query['replace_mode'] = unicode(self.replace_mode.currentText())
query['comma_separated'] = self.comma_separated.isChecked()
query['results_count'] = self.results_count.value()
query['starting_from'] = self.starting_from.value()
query['multiple_separator'] = unicode(self.multiple_separator.text())
self.queries[name] = query
self.queries.commit()
if new:
self.query_field.blockSignals(True)
self.query_field.clear()
self.query_field.addItem('')
self.query_field_values = sorted([q for q in self.queries], key=sort_key)
self.query_field.addItems(self.query_field_values)
self.query_field.blockSignals(False)
self.query_field.setCurrentIndex(self.query_field.findText(name))
示例15: blur_image
def blur_image(self):
val, ok = QInputDialog.getInt(
self,
_("Blur image"),
_("The standard deviation for the Gaussian blur operation (higher means more blurring)"),
value=3,
min=1,
max=20,
)
if ok:
self.canvas.blur_image(sigma=val)