def rename(): title = _("Set Device Label") msg = _("Enter new label:") response = QInputDialog().getText(dialog, title, msg) if not response[1]: return client().change_label(str(response[0])) refresh()
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()
def modify_label(): response = QInputDialog().getText(None, "Set New Trezor Label", "New Trezor Label: (upon submission confirm on Trezor)") if not response[1]: return new_label = str(response[0]) twd.start("Please confirm label change on Trezor") status = self.wallet.get_client().apply_settings(label=new_label) twd.stop() update_label()
def modify_label(): response = QInputDialog().getText(None, "Set New KeepKey Label", "New KeepKey Label: (upon submission confirm on KeepKey)") if not response[1]: return new_label = str(response[0]) self.handler.show_message("Please confirm label change on KeepKey") status = self.get_client().apply_settings(label=new_label) self.handler.stop() update_label()
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()
def makeNewList(self): listName, okay = QInputDialog.getText(QInputDialog(), self.objectName().capitalize() + " List Name", "New " + self.objectName().capitalize() + " List Name:", QLineEdit.Normal, "New " + self.objectName().capitalize() + " List") if okay and len(listName) > 0: if any([listName in lst for lst in self._rddtDataExtractor.subredditLists]): QMessageBox.information(QMessageBox(), "Data Extractor for reddit", "Duplicate subreddit list names not allowed.") return self._lstChooser.addItem(listName) self._lstChooser.setCurrentIndex(self._lstChooser.count() - 1) self._chooserDict[listName] = ListModel([], self._classToUse) self.chooseNewList(self._lstChooser.count() - 1) if self._rddtDataExtractor.defaultSubredditListName is None: # becomes None if user deletes all subreddit lists self._rddtDataExtractor.defaultSubredditListName = listName self._gui.setUnsavedChanges(True)
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')