def message_warning(self, title, message, *args, **kwargs): """ Shortcut to display a warning popup dialog. """ log.warning(message) return QtWidgets.QMessageBox.warning(self.window, "{0} - {1}".format( self.app_name, title), message, *args, **kwargs)
def message_warning(self, title, message, *args, **kwargs): """ Shortcut to display a warning popup dialog. """ log.warning(message) return QtWidgets.QMessageBox.warning(self.window, "{0} - {1}".format( self.app_name, title), message, *args, **kwargs)
def save_area(self): """ Save the dock area for the workspace. """ log.debug("Saving dock area") area = self.content.find('dock_area') try: with open('inkcut.workspace.db', 'w') as f: f.write(pickle.dumps(area)) except Exception as e: log.warning("Error saving dock area: {}".format(e)) return e
def order(self, job, path): """ Sort subpaths by minimizing the distances between all start and end points. """ subpaths = split_painter_path(path) log.debug("Subpath count: {}".format(len(subpaths))) # Cache all start and end points now = time() # This is in the UI thread time_limit = now + self.plugin.optimizer_timeout zero = QVector2D(0, 0) for sp in subpaths: # Average start and end into one "vertex" start = sp.elementAt(0) end = sp.elementAt(sp.elementCount() - 1) sp.start_point = QVector2D(start.x, start.y) sp.end_point = QVector2D(end.x, end.y) distance = QVector2D.distanceToPoint original = subpaths[:] result = [] p = zero while subpaths: best = sys.maxsize shortest = None for sp in subpaths: d = distance(p, sp.start_point) if d < best: best = d shortest = sp p = shortest.end_point result.append(shortest) subpaths.remove(shortest) # time.time() is slow so limit the calls if time() > time_limit: result.extend(subpaths) # At least part of it is optimized log.warning( "Shortest path search aborted (time limit reached)") break duration = time() - now d = self.subpath_move_distance(zero, original) d = d - self.subpath_move_distance(zero, result) log.debug("Shortest path search: Saved {} in of movement in {}".format( to_unit(d, 'in'), duration)) return join_painter_paths(result)
def set_language(self, language): try: language = getattr(QtCore.QLocale, language, 'system') if isinstance(language, int): locale = QtCore.QLocale(language).name() elif callable(language): locale = language().name() else: locale = QtCore.QLocale.system().name() root_dir = os.path.dirname(os.path.dirname(__file__)) path = os.path.join(root_dir, "res", "translations", locale) if self.translator.load(path): log.warning("Setting locale: %s" % locale) self.application._qapp.installTranslator(self.translator) else: log.warning("Translations not found at %s" % path) except Exception as e: log.exception(e)