Ejemplo n.º 1
0
    def __get_labels(self):
        """
        Read the label file of the documents and extract all the labels

        Returns:
            An array of labels.Label objects
        """
        if 'labels' not in self.__cache:
            labels = set()
            storage = self._storage
            try:
                with codecs.open(os.path.join(self.path, self.LABEL_FILE),
                                 'r',
                                 encoding='utf-8') as file_desc:
                    for line in file_desc.readlines():
                        label_name, label_color = line.strip().split(',', 1)
                        if '::' in label_name:
                            label_name, base = label_name.split('::')
                            base = int(base)
                        else:
                            base = None
                        label = Label(name=label_name, color=label_color)
                        if label not in labels:
                            labels.add(label)
                        if base:
                            self._storage = (label, base)
            except IOError:
                pass
            self.__cache['labels'] = labels
            if storage is not None:
                self._storage = storage
        return self.__cache['labels']
Ejemplo n.º 2
0
    def __get_labels(self):
        """
        Read the label file of the documents and extract all the labels

        Returns:
            An array of labels.Label objects
        """
        labels = []
        try:
            with codecs.open(os.path.join(self.path, self.LABEL_FILE),
                             'r',
                             encoding='utf-8') as file_desc:
                for line in file_desc.readlines():
                    line = line.strip()
                    (label_name, label_color) = line.split(",")
                    labels.append(Label(name=label_name, color=label_color))
        except IOError:
            pass
        return labels
Ejemplo n.º 3
0
    def do(self):
        SimpleAction.do(self)

        # Open the russian dolls to retrieve the selected label.
        label_list = self.__doc_properties.lists['labels']['gui']
        selected_row = label_list.get_selected_row()
        if selected_row is None:
            logger.warning("No label selected")
            return True
        label_box = selected_row.get_children()[0]
        label_name = label_box.get_children()[1].get_text()
        label_color = label_box.get_children()[2].get_rgba().to_string()
        label = Label(label_name, label_color)

        new_label = copy(label)
        editor = LabelEditor(new_label)
        if not editor.edit(self.__main_win.window):
            logger.warning("Label edition cancelled")
            return
        logger.info("Label edited. Applying changes")
        job = self.__doc_properties.job_factories['label_updater'].make(
            self.__main_win.docsearch, label, new_label)
        self.__main_win.schedulers['main'].schedule(job)
Ejemplo n.º 4
0
    def __init__(self, label_to_edit=None):
        if label_to_edit == None:
            label_to_edit = Label()
        self.label = label_to_edit

        self.__ok_button = None