Ejemplo n.º 1
0
 def resizeEvent(self, event: QResizeEvent):
     metric = QFontMetrics(self.file_view.font())
     width = self.file_view.width() - 45
     for i, text in enumerate(self.file_list):
         clipped_text = metric.elidedText(text, Qt.ElideLeft, width)
         item: QTreeWidgetItem = self.file_view.topLevelItem(i)
         item.setText(0, clipped_text)
Ejemplo n.º 2
0
 def get_short_name(self):
     """Get a short name for the notebook."""
     sname = osp.splitext(osp.basename(self.filename))[0]
     if len(sname) > 20:
         fm = QFontMetrics(QFont())
         sname = fm.elidedText(sname, Qt.ElideRight, 110)
     return sname
Ejemplo n.º 3
0
class ElidingLabel(QLabel):
    """A single-line eliding QLabel."""
    def __init__(self, text='', parent=None):
        super().__init__(parent)
        self._text = text
        self.fm = QFontMetrics(self.font())

    def setText(self, txt):
        self._text = txt
        short = self.fm.elidedText(self._text, Qt.ElideRight, self.width())
        super().setText(short)

    def resizeEvent(self, rEvent):
        width = rEvent.size().width()
        short = self.fm.elidedText(self._text, Qt.ElideRight, width)
        super().setText(short)
        rEvent.accept()
Ejemplo n.º 4
0
    def updateText(self):
        self.checkItems = []
        for i in range(self.model().rowCount()):
            if self.model().item(i).checkState() == Qt.Checked:
                self.checkItems.append(self.model().item(i).text())
        text = ", ".join(self.checkItems)

        # Compute elided text (with "...")
        metrics = QFontMetrics(self.lineEdit().font())
        elidedText = metrics.elidedText(text, Qt.ElideRight, self.lineEdit().width())
        self.lineEdit().setText(elidedText)
Ejemplo n.º 5
0
    def save_state_action(self, state: ProjectInfoBase, custom_name):
        # TODO left elipsis
        # state: ProjectInfoBase = self.get_state()
        if not isinstance(state,
                          ProjectInfoBase):  # workaround for PointsInfo load
            return
        normed_file_path = os.path.normpath(state.file_path)
        sub_dict = self.state_dict[normed_file_path]
        name = f"state {self.state_dict_count[normed_file_path]+1}"
        if custom_name:
            name, ok = QInputDialog.getText(self,
                                            "Save name",
                                            "Save name:",
                                            text=name)
            if not ok:
                return
            while name in sub_dict or name in ["raw image", "image with mask"]:
                name, ok = QInputDialog.getText(self,
                                                "Save name",
                                                "Save name (previous in use):",
                                                text=name)
                if not ok:
                    return
        try:
            index = self.file_list.index(os.path.normpath(normed_file_path))
            item = self.file_view.topLevelItem(index)
        except ValueError:
            metric = QFontMetrics(self.file_view.font())
            width = self.file_view.width() - 45
            clipped_text = metric.elidedText(normed_file_path, Qt.ElideLeft,
                                             width)
            item = QTreeWidgetItem(self.file_view, [clipped_text])
            item.setToolTip(0, normed_file_path)
            self.file_list.append(normed_file_path)
            QTreeWidgetItem(item, ["raw image"])
            sub_dict["raw image"] = state.get_raw_copy()
            if state.is_masked():
                QTreeWidgetItem(item, ["image with mask"])
                sub_dict["image with mask"] = state.get_raw_mask_copy()

        item.setExpanded(True)
        if state.is_raw():
            return
        it = QTreeWidgetItem(item, [name])
        self.file_view.setCurrentItem(it)
        sub_dict[name] = state
        self.state_dict_count[state.file_path] += 1
Ejemplo n.º 6
0
 def setText(self, text: str) -> None:
     metrics = QFontMetrics(self.font())
     elidedText: str = metrics.elidedText(text, Qt.ElideMiddle,
                                          self.width())
     super().setText(elidedText)
Ejemplo n.º 7
0
 def setText(self, text):
     self._text = text
     metrics = QFontMetrics(self.font())
     elided = metrics.elidedText(self._text, Qt.ElideRight, self.width())
     super(ElidedLabel, self).setText(elided)