Example #1
0
    def initUI(self):
        ## window configuration settings,
        ## sich as padding, width, height, and
        ## min/max plot axes
        self.setStyleSheet("QFrame {"
                           "  background-color: rgb(0, 0, 0);"
                           "  border-width: 1px;"
                           "  border-style: solid;"
                           "  border-color: #3399CC;}")
        self.textpad = 5
        self.font_ratio = 0.0512
        fsize1 = round(self.size().height() * self.font_ratio) + 2
        fsize2 = round(self.size().height() * self.font_ratio)
        self.plot_font = QtGui.QFont('Helvetica', fsize1)
        self.box_font = QtGui.QFont('Helvetica', fsize2)
        self.plot_metrics = QtGui.QFontMetrics(self.plot_font)
        self.box_metrics = QtGui.QFontMetrics(self.box_font)
        if platform.system() == "Windows":
            fsize1 -= self.plot_metrics.descent()
            fsize2 -= self.box_metrics.descent()

            self.plot_font = QtGui.QFont('Helvetica', fsize1)
            self.box_font = QtGui.QFont('Helvetica', fsize2)
            self.plot_metrics = QtGui.QFontMetrics(self.plot_font)
            self.box_metrics = QtGui.QFontMetrics(self.box_font)
        self.plot_height = self.plot_metrics.xHeight()  # + self.textpad
        self.box_height = self.box_metrics.xHeight() + self.textpad
        self.tpad = self.plot_height + 15
        self.bpad = self.plot_height + 2
        self.lpad = 0.
        self.rpad = 0.
        self.wid = self.size().width() - self.rpad
        self.hgt = self.size().height() - self.bpad
        self.tlx = self.rpad
        self.tly = self.tpad
        self.brx = self.wid
        self.bry = self.hgt - self.bpad  #+ round(self.font_ratio * self.hgt)
        self.shipmax = 5.
        self.shipmin = 0.
        self.plotBitMap = QtGui.QPixmap(self.width() - 2, self.height() - 2)
        self.plotBitMap.fill(self.bg_color)
        self.plotBackground()
Example #2
0
 def __init__(self, parent=None):
     QtWidgets.QLabel.__init__(self, parent)
     self.setTextInteractionFlags(
         Qt.TextSelectableByMouse | Qt.LinksAccessibleByMouse
     )
     self._display = ''
     self._template = ''
     self._text = ''
     self._elide = False
     self._metrics = QtGui.QFontMetrics(self.font())
     self.setOpenExternalLinks(True)
Example #3
0
    def initUI(self):
        ## initialize fram variables such as size,
        ## padding, etc.
        self.setStyleSheet("QFrame {"
                           "  background-color: rgb(0, 0, 0);"
                           "  border-width: 1px;"
                           "  border-style: solid;"
                           "  border-color: #3399CC;}")
        self.lpad = 5
        self.rpad = 5
        self.tpad = 3
        self.bpad = 3
        self.os_mod = 0
        self.barby = 0
        self.wid = self.size().width()
        self.hgt = self.size().height()
        self.tlx = self.rpad
        self.tly = self.tpad
        self.brx = self.wid
        self.bry = self.hgt

        if self.physicalDpiX() > 75:
            fsize = 8
        else:
            fsize = 10
        font_ratio = fsize / self.hgt
        font_ratio = 0.0512
        self.label_font = QtGui.QFont('Helvetica',
                                      round(font_ratio * self.hgt))
        self.fosberg_font = QtGui.QFont('Helvetica',
                                        round(font_ratio * self.hgt) + 2)
        self.label_metrics = QtGui.QFontMetrics(self.label_font)
        self.fosberg_metrics = QtGui.QFontMetrics(self.fosberg_font)
        self.label_height = self.label_metrics.xHeight() + self.tpad
        self.ylast = self.label_height
        if platform.system() == "Windows":
            self.os_mod = self.label_metrics.descent()

        self.plotBitMap = QtGui.QPixmap(self.width() - 2, self.height() - 2)
        self.plotBitMap.fill(self.bg_color)
        self.plotBackground()
Example #4
0
    def initUI(self):
        ## window configuration settings,
        ## sich as padding, width, height, and
        ## min/max plot axes
        self.lpad = 5
        self.rpad = 0
        self.tpad = 0
        self.bpad = 20
        self.fpad = 5
        self.wid = self.size().width() - self.rpad
        self.hgt = self.size().height() - self.bpad
        self.tlx = self.rpad
        self.tly = self.tpad
        self.brx = self.wid
        self.bry = self.hgt
        ## center the frame on the slinky
        self.center_frame()
        if self.physicalDpiX() > 75:
            fsize = 7
        else:
            fsize = 9
        self.font_ratio = 0.0512
        self.title_font = QtGui.QFont(
            'Helvetica',
            round(self.size().height() * self.font_ratio) + 2)
        self.plot_font = QtGui.QFont(
            'Helvetica', round(self.size().height() * self.font_ratio))
        self.title_metrics = QtGui.QFontMetrics(self.title_font)
        self.plot_metrics = QtGui.QFontMetrics(self.plot_font)
        self.os_mod = 0
        if platform.system() == "Windows":
            self.os_mod = self.plot_metrics.descent()

        ## get the pixel height of the font
        self.title_height = self.title_metrics.xHeight() + self.fpad
        self.plot_height = self.plot_metrics.xHeight() + self.fpad
        ## initialize the QPixmap that the frame and data will be drawn on
        self.plotBitMap = QtGui.QPixmap(self.width(), self.height())
        self.plotBitMap.fill(self.bg_color)
        ## plot the background
        self.plotBackground()
Example #5
0
    def updateText(self):
        texts = []
        for i in range(self.model().rowCount()):
            if self.model().item(i).checkState() == QtCore.Qt.Checked:
                texts.append(self.model().item(i).text())
        text = ", ".join(texts)

        # Compute elided text (with "...")
        metrics = QtGui.QFontMetrics(self.lineEdit().font())
        elidedText = metrics.elidedText(text, QtCore.Qt.ElideRight,
                                        self.lineEdit().width())
        self.lineEdit().setText(elidedText)
Example #6
0
 def drawPrecipTypeTemp(self, qp):
     small = QtGui.QFont('Helvetica',
                         round(self.hgt * self.font_ratio) - 1,
                         bold=False)
     small_metrics = QtGui.QFontMetrics(small)
     height = small_metrics.xHeight() + self.tpad
     pen = QtGui.QPen(self.fg_color, 2, QtCore.Qt.SolidLine)
     qp.setPen(pen)
     qp.setFont(small)
     rect1 = QtCore.QRect(0, self.ptype_tmpf_y1, self.wid, height)
     qp.drawText(rect1, QtCore.Qt.TextDontClip | QtCore.Qt.AlignCenter,
                 self.ptype_tmpf_string)
Example #7
0
 def drawPrecipType(self, qp):
     big = QtGui.QFont('Helvetica',
                       round(self.hgt * self.font_ratio) + 5,
                       bold=True)
     big_metrics = QtGui.QFontMetrics(big)
     height = big_metrics.xHeight() + self.tpad
     pen = QtGui.QPen(self.fg_color, 2, QtCore.Qt.SolidLine)
     qp.setPen(pen)
     qp.setFont(big)
     rect1 = QtCore.QRect(0, self.precip_type_y1, self.wid, height)
     qp.drawText(rect1, QtCore.Qt.TextDontClip | QtCore.Qt.AlignCenter,
                 self.precip_type)
Example #8
0
def prompt_n(msg, inputs):
    """Presents the user with N input widgets and returns the results"""
    dialog = QtWidgets.QDialog(active_window())
    dialog.setWindowModality(Qt.WindowModal)
    dialog.setWindowTitle(msg)

    long_value = msg
    for k, v in inputs:
        if len(k + v) > len(long_value):
            long_value = k + v

    metrics = QtGui.QFontMetrics(dialog.font())
    min_width = metrics.width(long_value) + 100
    if min_width > 720:
        min_width = 720
    dialog.setMinimumWidth(min_width)

    ok_b = ok_button(msg, enabled=False)
    close_b = close_button()

    form_widgets = []

    def get_values():
        return [pair[1].text().strip() for pair in form_widgets]

    for name, value in inputs:
        lineedit = QtWidgets.QLineEdit()
        # Enable the OK button only when all fields have been populated
        # pylint: disable=no-member
        lineedit.textChanged.connect(
            lambda x: ok_b.setEnabled(all(get_values())))
        if value:
            lineedit.setText(value)
        form_widgets.append((name, lineedit))

    # layouts
    form_layout = form(defs.no_margin, defs.button_spacing, *form_widgets)
    button_layout = hbox(defs.no_margin, defs.button_spacing, STRETCH, close_b,
                         ok_b)
    main_layout = vbox(defs.margin, defs.button_spacing, form_layout,
                       button_layout)
    dialog.setLayout(main_layout)

    # connections
    connect_button(ok_b, dialog.accept)
    connect_button(close_b, dialog.reject)

    accepted = dialog.exec_() == QtWidgets.QDialog.Accepted
    text = get_values()
    ok = accepted and all(text)
    return (ok, text)
Example #9
0
 def initUI(self):
     ## window configuration settings,
     ## sich as padding, width, height, and
     ## min/max plot axes
     self.setStyleSheet("QFrame {"
                        "  background-color: rgb(0, 0, 0);"
                        "  border-width: 1px;"
                        "  border-style: solid;"
                        "  border-color: #3399CC;}")
     if self.physicalDpiX() > 75:
         fsize = 10
     else:
         fsize = 11
     fsize = np.floor(.055 * self.size().height())
     self.fsize = fsize
     self.plot_font = QtGui.QFont('Helvetica', fsize + 1)
     self.box_font = QtGui.QFont('Helvetica', fsize)
     self.plot_metrics = QtGui.QFontMetrics(self.plot_font)
     self.box_metrics = QtGui.QFontMetrics(self.box_font)
     self.plot_height = self.plot_metrics.xHeight() + 5
     self.box_height = self.box_metrics.xHeight() + 5
     self.lpad = 40
     self.rpad = 40.
     self.tpad = fsize * 2 + 5
     self.bpad = fsize
     self.wid = self.size().width() - self.rpad
     self.hgt = self.size().height() - self.bpad
     self.tlx = self.rpad
     self.tly = self.tpad
     self.brx = self.wid
     self.bry = self.hgt
     self.ymax = 3000.
     self.ymin = 0.
     self.xmax = 3000.
     self.xmin = 0.
     self.plotBitMap = QtGui.QPixmap(self.width() - 2, self.height() - 2)
     self.plotBitMap.fill(self.bg_color)
     self.plotBackground()
Example #10
0
    def addFont(self, font_size):
        with self._vao:
            font = TextRenderer.Font()
            font.size = font_size

            db = QtGui.QFontDatabase()
            qfont = db.systemFont(db.FixedFont)
            if font_size > 0:
                qfont.setPointSize(font_size)
            else:
                self.fonts[0] = font

            self.fonts[qfont.pointSize()] = font

            metrics = QtGui.QFontMetrics(qfont)

            font.width = metrics.width("W")
            font.height = metrics.height()

            font.tex_width = (1 + 128 - 32) * font.width
            font.tex_width = (font.tex_width +
                              3) // 4 * 4  # should be multiple of 4
            font.tex_height = metrics.height()
            for i in range(32, 128):
                c = bytes([i]).decode()

            image = QtGui.QImage(font.tex_width, font.tex_height,
                                 QtGui.QImage.Format_Grayscale8)
            image.fill(QtCore.Qt.black)

            painter = QtGui.QPainter()
            painter.begin(image)
            painter.setFont(qfont)
            painter.setPen(QtCore.Qt.white)
            for i in range(32, 128):
                w = font.width
                text = bytes([i]).decode()
                painter.drawText(
                    (i - 32) * w, 0, (i + 1 - 32) * w, font.height,
                    QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft, text)
            painter.end()
            ptr = image.constBits()
            if qtpy.API == "pyqt5":
                ptr.setsize(image.byteCount())
            Z = numpy.array(ptr).reshape(font.tex_height, font.tex_width)

            font.tex = Texture(GL_TEXTURE_2D, GL_RED)
            font.tex.store(Z, GL_UNSIGNED_BYTE, Z.shape[1], Z.shape[0])
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
Example #11
0
    def _checkStations(self, e):
#       if len(self.stn_lats) == 0:
#           return

        lb_lat, ub_lat = self.mapper.getLatBounds()
        idxs = np.array([ idx for idx, slat in enumerate(self.stn_lats) if lb_lat <= slat <= ub_lat ])
        if len(idxs) == 0:
            return

        stn_xs, stn_ys = self.mapper(self.stn_lats[idxs], self.stn_lons[idxs] + self.map_rot)
        stn_xs, stn_ys = list(zip(*[ self.transform.map(sx, sy) for sx, sy in zip(stn_xs, stn_ys) ]))
        stn_xs = np.array(stn_xs)
        stn_ys = np.array(stn_ys)
        dists = np.hypot(stn_xs - e.x(), stn_ys - e.y())
        stn_idx = np.argmin(dists)
        if dists[stn_idx] <= 5:
            stn_x, stn_y = stn_xs[stn_idx], stn_ys[stn_idx]
            fm = QtGui.QFontMetrics(QtGui.QFont(self.font().rawName(), 16))

            label_offset = 5
            align = 0
            if stn_x > self.width() / 2:
                sgn_x = -1
                label_x = stn_x - fm.width(self.stn_names[idxs[stn_idx]])
                align |= QtCore.Qt.AlignRight
            else:
                sgn_x = 1
                label_x = stn_x
                align |= QtCore.Qt.AlignLeft

            if stn_y > self.height() / 2:
                sgn_y = -1
                label_y = stn_y - fm.height()
                align |= QtCore.Qt.AlignBottom
            else:
                sgn_y = 1
                label_y = stn_y
                align |= QtCore.Qt.AlignTop

            self.stn_readout.setText(self.stn_names[idxs[stn_idx]])
            self.stn_readout.move(label_x + sgn_x * label_offset, label_y + sgn_y * label_offset)
            self.stn_readout.setFixedWidth(fm.width(self.stn_names[idxs[stn_idx]]))
            self.stn_readout.setAlignment(align)
            self.setCursor(QtCore.Qt.PointingHandCursor)
        else:
            self.stn_readout.setText("")
            self.stn_readout.setFixedWidth(0)
            self.stn_readout.move(self.width(), self.height())
            self.stn_readout.setAlignment(QtCore.Qt.AlignLeft)
            self.unsetCursor()
Example #12
0
 def initUI(self):
     ## window configuration settings,
     ## sich as padding, width, height, and
     ## min/max plot axes
     self.setStyleSheet("QFrame {"
         "  background-color: rgb(0, 0, 0);"
         "  border-width: 1px;"
         "  border-style: solid;"
         "  border-color: #3399CC;}")
     if self.physicalDpiX() > 75:
         fsize = 10
     else:
         fsize = 11
             
     self.font_ratio = 0.0512
     self.plot_font = QtGui.QFont('Helvetica', round(self.size().height() * self.font_ratio + 1))
     self.label_font = QtGui.QFont('Helvetica', round(self.size().height() * self.font_ratio ))
     self.plot_metrics = QtGui.QFontMetrics( self.plot_font )
     self.label_metrics = QtGui.QFontMetrics(self.label_font)
     self.plot_height = self.plot_metrics.xHeight() + 5
     self.label_height = self.label_metrics.xHeight() + 5
     self.vrot_inset_data = inset_data.vrotData()
     self.lpad = 5.; self.rpad = 0.
     self.tpad = 5 + self.plot_height + self.label_height ;
     self.bpad = self.label_height + 5
     self.wid = self.size().width() - self.rpad
     self.hgt = self.size().height() - self.bpad
     self.tlx = self.rpad; self.tly = self.tpad
     self.brx = self.wid; self.bry = self.hgt
     self.probmax = 70.; self.probmin = 0.
     self.vrotmax = 110.; self.vrotmin = 0
     self.EF01_color = "#006600"
     self.EF23_color = "#FFCC33"
     self.EF45_color = "#FF00FF"
     self.plotBitMap = QtGui.QPixmap(self.width()-2, self.height()-2)
     self.plotBitMap.fill(self.bg_color)
     self.plotBackground()
Example #13
0
    def __init__(self, parent=None):
        super().__init__(parent)
        hboxlayout = QtWidgets.QHBoxLayout()
        hboxlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(hboxlayout)
        self.setMinimumWidth(100)

        fontmetric = QtGui.QFontMetrics(self.font())
        fontheight = fontmetric.height()
        self.setFixedHeight(fontheight + 2)

        pal = self.palette()
        pal.setColor(QtGui.QPalette.Background, QtGui.QColor(192, 192, 192))
        self.setPalette(pal)
        self.setAutoFillBackground(True)
Example #14
0
    def show_header(self, fname, fit=True):

        try:

            text = str(dicom.read_file(fname))
            self.setText(text)
            self.setWindowTitle(fname)
            if fit:
                font = self.document().defaultFont()
                font_metrics = QtGui.QFontMetrics(font)
                text_size = font_metrics.size(0, text)
                self.resize(text_size.width() + 30, text_size.height() + 30)

        except Exception as e:

            print("Error loading DICOM data")
Example #15
0
    def resize_font(self, initial_font_size=8.25):
        font_size = initial_font_size
        some_font = self._parent.font()

        while True:
            some_font.setPointSizeF(font_size)
            metric = QtGui.QFontMetrics(some_font)
            self._parent.setFont(some_font)

            if metric.width(self._parent.text()) < self._parent.width():
                break
            else:
                font_size -= 0.1

            if font_size < 5:
                break
Example #16
0
    def __init__(
        self, parent=None, value=None, mini=1, maxi=99999, step=0, prefix='', suffix=''
    ):
        QtWidgets.QSpinBox.__init__(self, parent)
        self.setPrefix(prefix)
        self.setSuffix(suffix)
        self.setWrapping(True)
        self.setMinimum(mini)
        self.setMaximum(maxi)
        if step:
            self.setSingleStep(step)
        if value is not None:
            self.setValue(value)

        font = self.font()
        metrics = QtGui.QFontMetrics(font)
        width = max(self.minimumWidth(), metrics.width('XXXXXX'))
        self.setMinimumWidth(width)
Example #17
0
    def __init__(self, parent, command, number, name="", enabled=True):
        super(Command, self).__init__(parent)
        self.command = command
        self.widget = QtWidgets.QTextBrowser()
        self.widget.setReadOnly(True)
        self.widget.setText(command)
        self.widget.setDisabled(not enabled)
        font_height = QtGui.QFontMetrics(
            self.widget.document().defaultFont()).height()
        lines = math.ceil(len(command) / 200)
        self.setMinimumHeight(
            int(font_height + ((lines + 2) * (font_height * 1.25))))

        grid = QtWidgets.QGridLayout()
        grid.addWidget(
            QtWidgets.QLabel(f"Command {number}" if not name else name), 0, 0,
            1, 2)
        grid.addWidget(self.widget, 1, 0, 1, 2)
        self.setLayout(grid)
Example #18
0
    def resizeEvent(self, event):
        super(DynamicSizeLabel, self).resizeEvent(event)

        if not self.text():
            return

        # --- fetch current parameters ----

        f = self.font()
        cr = self.contentsRect()

        # --- iterate to find the font size that fits the contentsRect ---

        dw = event.size().width() - event.oldSize().width()  # width change
        dh = event.size().height() - event.oldSize().height()  # height change

        fs = max(f.pixelSize(), 1)
        while True:

            f.setPixelSize(fs)
            br = QtGui.QFontMetrics(f).boundingRect(self.text())

            if dw >= 0 and dh >= 0:  # label is expanding

                if br.height() <= cr.height() and br.width() <= cr.width():
                    fs += 1
                else:
                    f.setPixelSize(max(fs - 1, 1))  # backtrack
                    break

            else:  # label is shrinking

                if br.height() > cr.height() or br.width() > cr.width():
                    fs -= 1
                else:
                    break

            if fs < 1:
                break

        # --- update font size ---
        self.setFont(f)
Example #19
0
 def initUI(self):
     '''
     Initializes frame variables such as padding,
     width, height, etc, as well as the QPixmap
     that contains the frame drawing.
     '''
     ## set the frame stylesheet
     self.setStyleSheet("QFrame {"
                        "  background-color: rgb(0, 0, 0);"
                        "  border-width: 1px;"
                        "  border-style: solid;"
                        "  border-color: #3399CC;}")
     ## set the frame padding
     ## set the height/width variables
     self.lpad = 0
     self.rpad = 0
     self.tpad = 5
     self.bpad = 0
     self.wid = self.size().width()
     self.hgt = self.size().height()
     self.tlx = self.rpad
     self.tly = self.tpad
     self.brx = self.wid
     self.bry = self.hgt
     ## do a DPI check to make sure
     ## the text is sized properly!
     fsize = np.floor(.06 * self.hgt)
     self.tpad = np.floor(.03 * self.hgt)
     ## set the font, get the metrics and height of the font
     self.label_font = QtGui.QFont('Helvetica')
     self.label_font.setPixelSize(fsize)
     self.label_metrics = QtGui.QFontMetrics(self.label_font)
     self.label_height = self.label_metrics.xHeight() + self.tpad
     ## the self.ylast variable is used as a running sum for
     ## text placement.
     self.ylast = self.label_height
     ## initialize the QPixmap that will be drawn on.
     self.plotBitMap = QtGui.QPixmap(self.width() - 2, self.height() - 2)
     self.plotBitMap.fill(self.bg_color)
     ## plot the background frame
     self.plotBackground()
Example #20
0
    def __init__(self, codeEditor):
        QtWidgets.QPlainTextEdit.__init__(self)

        self._globals = {}
        self._mg = None
        self.codeEditor = codeEditor
        # FONT: set monospace
        font = QtGui.QFont()
        font.setFamily("Courier")
        font.setStyleHint(QtGui.QFont.Monospace)
        font.setFixedPitch(True)
        font.setPointSize(10)
        self.setFont(font)
        # TAB to spaces
        tabStop = 4  # 4 characters
        metrics = QtGui.QFontMetrics(font)
        self.setTabStopWidth(tabStop * metrics.width(' '))
        # SCROLL BAR - horizontal:
        self.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap)
        # SYNTAX highlighter:
        self.highlighter = Highlighter(self.document(), "python")
Example #21
0
    def __init__(self, parent=None):
        standard.Dialog.__init__(self, parent)
        self.setWindowTitle(N_('Edit Remotes'))
        if parent is not None:
            self.setWindowModality(Qt.WindowModal)

        self.current_name = ''
        self.current_url = ''

        self.default_hint = N_('Edit remotes by selecting them from the list')

        self.remote_list = []
        self.remotes = QtWidgets.QListWidget()
        self.remotes.setToolTip(N_(
            'Remote git repositories - double-click to rename'))

        self.editor = RemoteWidget(self)

        self.save_button = qtutils.create_button(
            text=N_('Save'), icon=icons.save(), default=True)

        self.reset_button = qtutils.create_button(
            text=N_('Reset'), icon=icons.discard())

        tooltip = N_(
            'Add and remove remote repositories using the \n'
            'Add(+) and Delete(-) buttons on the left-hand side.\n'
            '\n'
            'Remotes can be renamed by selecting one from the list\n'
            'and pressing "enter", or by double-clicking.')
        self.info = text.VimHintedPlainTextEdit(self.default_hint, parent=self)
        self.info.setToolTip(tooltip)

        font = self.info.font()
        metrics = QtGui.QFontMetrics(font)
        width = metrics.width('_' * 42)
        height = metrics.height() * 13
        self.info.setMinimumWidth(width)
        self.info.setMinimumHeight(height)
        self.info_thread = RemoteInfoThread(self)

        icon = icons.add()
        tooltip = N_('Add new remote git repository')
        self.add_button = qtutils.create_toolbutton(icon=icon, tooltip=tooltip)

        self.refresh_button = qtutils.create_toolbutton(
            icon=icons.sync(), tooltip=N_('Refresh'))
        self.delete_button = qtutils.create_toolbutton(
            icon=icons.remove(), tooltip=N_('Delete remote'))
        self.close_button = qtutils.close_button()

        self._edit_button_layout = qtutils.vbox(
            defs.no_margin, defs.spacing,
            self.save_button, self.reset_button)

        self._edit_layout = qtutils.hbox(
            defs.no_margin, defs.spacing,
            self.editor, self._edit_button_layout)

        self._display_layout = qtutils.vbox(
            defs.no_margin, defs.spacing,
            self._edit_layout, self.info)
        self._display_widget = QtWidgets.QWidget(self)
        self._display_widget.setLayout(self._display_layout)

        self._top_layout = qtutils.splitter(
            Qt.Horizontal, self.remotes, self._display_widget)
        width = self._top_layout.width()
        self._top_layout.setSizes([width//4, width*3//4])

        self._button_layout = qtutils.hbox(defs.margin, defs.spacing,
            self.add_button,
            self.delete_button,
            self.refresh_button,
            qtutils.STRETCH,
            self.close_button)

        self._layout = qtutils.vbox(defs.margin, defs.spacing,
                                    self._top_layout,
                                    self._button_layout)
        self.setLayout(self._layout)

        qtutils.connect_button(self.add_button, self.add)
        qtutils.connect_button(self.delete_button, self.delete)
        qtutils.connect_button(self.refresh_button, self.refresh)
        qtutils.connect_button(self.close_button, self.accept)
        qtutils.connect_button(self.save_button, self.save)
        qtutils.connect_button(self.reset_button, self.reset)
        qtutils.add_close_action(self)

        thread = self.info_thread
        thread.result.connect(self.set_info, type=Qt.QueuedConnection)

        self.editor.remote_name.returnPressed.connect(self.save)
        self.editor.remote_url.returnPressed.connect(self.save)
        self.editor.valid.connect(self.editor_valid)

        self.remotes.itemChanged.connect(self.remote_item_renamed)
        self.remotes.itemSelectionChanged.connect(self.selection_changed)

        self.disable_editor()
        self.init_state(None, self.resize_widget, parent)
        self.remotes.setFocus(Qt.OtherFocusReason)
        self.refresh()
Example #22
0
 def setFont(self, font):
     self._metrics = QtGui.QFontMetrics(font)
     QtWidgets.QLabel.setFont(self, font)
Example #23
0
 def set_tabwidth(self, width):
     self._tabwidth = width
     font = self.widget.font()
     fm = QtGui.QFontMetrics(font)
     pixels = fm.width('M' * width)
     self.widget.setTabStopWidth(pixels)
Example #24
0
    def __init__(self, context, parent):
        standard.TreeView.__init__(self, parent)

        self.context = context
        self.selection = context.selection
        self.saved_selection = []
        self.saved_current_path = None
        self.saved_open_folders = set()
        self.restoring_selection = False

        self.info_event_type = browse.GitRepoInfoEvent.TYPE

        self.setDragEnabled(True)
        self.setRootIsDecorated(False)
        self.setSortingEnabled(False)
        self.setSelectionMode(self.ExtendedSelection)

        # Observe model updates
        model = context.model
        model.add_observer(model.message_about_to_update,
                           self.emit_about_to_update)
        model.add_observer(model.message_updated, self.emit_update)

        self.about_to_update.connect(self.save_selection,
                                     type=Qt.QueuedConnection)
        self.updated.connect(self.update_actions, type=Qt.QueuedConnection)

        self.expanded.connect(self.index_expanded)

        self.collapsed.connect(lambda idx: self.size_columns())
        self.collapsed.connect(self.index_collapsed)

        # Sync selection before the key press event changes the model index
        queued = Qt.QueuedConnection
        self.index_about_to_change.connect(self.sync_selection, type=queued)

        self.action_history = qtutils.add_action_with_status_tip(
            self, N_('View History...'), N_('View history for selected paths'),
            self.view_history, hotkeys.HISTORY)

        self.action_stage = qtutils.add_action_with_status_tip(
            self, cmds.StageOrUnstage.name(),
            N_('Stage/unstage selected paths for commit'),
            cmds.run(cmds.StageOrUnstage, context), hotkeys.STAGE_SELECTION)

        self.action_untrack = qtutils.add_action_with_status_tip(
            self, N_('Untrack Selected'), N_('Stop tracking paths'),
            self.untrack_selected)

        self.action_rename = qtutils.add_action_with_status_tip(
            self, N_('Rename'), N_('Rename selected paths'),
            self.rename_selected)

        self.action_difftool = qtutils.add_action_with_status_tip(
            self, cmds.LaunchDifftool.name(),
            N_('Launch git-difftool on the current path'),
            cmds.run(cmds.LaunchDifftool, context), hotkeys.DIFF)

        self.action_difftool_predecessor = qtutils.add_action_with_status_tip(
            self, N_('Diff Against Predecessor...'),
            N_('Launch git-difftool against previous versions'),
            self.diff_predecessor, hotkeys.DIFF_SECONDARY)

        self.action_revert_unstaged = qtutils.add_action_with_status_tip(
            self, cmds.RevertUnstagedEdits.name(),
            N_('Revert unstaged changes to selected paths'),
            cmds.run(cmds.RevertUnstagedEdits, context), hotkeys.REVERT)

        self.action_revert_uncommitted = qtutils.add_action_with_status_tip(
            self, cmds.RevertUncommittedEdits.name(),
            N_('Revert uncommitted changes to selected paths'),
            cmds.run(cmds.RevertUncommittedEdits, context), hotkeys.UNDO)

        self.action_editor = qtutils.add_action_with_status_tip(
            self, cmds.LaunchEditor.name(), N_('Edit selected paths'),
            cmds.run(cmds.LaunchEditor, context), hotkeys.EDIT)

        self.action_refresh = common.refresh_action(context, self)

        if not utils.is_win32():
            self.action_default_app = common.default_app_action(
                context, self, self.selected_paths)

            self.action_parent_dir = common.parent_dir_action(
                context, self, self.selected_paths)

            self.action_terminal = common.terminal_action(
                context, self, self.selected_paths)

        self.x_width = QtGui.QFontMetrics(self.font()).width('x')
        self.size_columns()
    def __init__(self, ol=None, parent=None):
        # pylint: disable=unused-argument,super-on-old-class
        super(ClassicUBInputWidget, self).__init__()
        metrics = QtGui.QFontMetrics(self.font())
        #validators
        self.latticeLengthValidator = QtGui.QDoubleValidator(
            0.1, 1000., 5, self)
        self.latticeAngleValidator = QtGui.QDoubleValidator(5., 175., 5, self)
        self.doubleValidator = QtGui.QDoubleValidator(self)
        self.latt_a = 0.
        self.latt_b = 0.
        self.latt_c = 0.
        self.latt_alpha = 0.
        self.latt_beta = 0.
        self.latt_gamma = 0.
        self.latt_ux = 0.
        self.latt_uy = 0.
        self.latt_uz = 0.
        self.latt_vx = 0.
        self.latt_vy = 0.
        self.latt_vz = 0.
        #OrientedLattice
        if ValidateOL(ol):
            self.ol = ol
        else:
            self.ol = mantid.geometry.OrientedLattice()
        #labels
        self._labela = QtWidgets.QLabel('a')
        self._labelb = QtWidgets.QLabel('b')
        self._labelc = QtWidgets.QLabel('c')
        self._labelalpha = QtWidgets.QLabel('alpha')
        self._labelbeta = QtWidgets.QLabel(' beta')
        self._labelgamma = QtWidgets.QLabel('gamma')
        self._labelux = QtWidgets.QLabel('ux')
        self._labeluy = QtWidgets.QLabel('uy')
        self._labeluz = QtWidgets.QLabel('uz')
        self._labelvx = QtWidgets.QLabel('vx')
        self._labelvy = QtWidgets.QLabel('vy')
        self._labelvz = QtWidgets.QLabel('vz')
        self._labelclassic = QtWidgets.QLabel('Lattice parameters')
        #lineedits
        self._edita = QtWidgets.QLineEdit()
        self._edita.setValidator(self.latticeLengthValidator)
        self._editb = QtWidgets.QLineEdit()
        self._editb.setValidator(self.latticeLengthValidator)
        self._editc = QtWidgets.QLineEdit()
        self._editc.setValidator(self.latticeLengthValidator)
        self._editalpha = QtWidgets.QLineEdit()
        self._editalpha.setValidator(self.latticeAngleValidator)
        self._editbeta = QtWidgets.QLineEdit()
        self._editbeta.setValidator(self.latticeAngleValidator)
        self._editgamma = QtWidgets.QLineEdit()
        self._editgamma.setValidator(self.latticeAngleValidator)
        self._editux = QtWidgets.QLineEdit()
        self._editux.setValidator(self.doubleValidator)
        self._edituy = QtWidgets.QLineEdit()
        self._edituy.setValidator(self.doubleValidator)
        self._edituz = QtWidgets.QLineEdit()
        self._edituz.setValidator(self.doubleValidator)
        self._editvx = QtWidgets.QLineEdit()
        self._editvx.setValidator(self.doubleValidator)
        self._editvy = QtWidgets.QLineEdit()
        self._editvy.setValidator(self.doubleValidator)
        self._editvz = QtWidgets.QLineEdit()
        self._editvz.setValidator(self.doubleValidator)
        self._edita.setFixedWidth(metrics.width("8888.88888"))
        self._editb.setFixedWidth(metrics.width("8888.88888"))
        self._editc.setFixedWidth(metrics.width("8888.88888"))
        self._editalpha.setFixedWidth(metrics.width("8888.88888"))
        self._editbeta.setFixedWidth(metrics.width("8888.88888"))
        self._editgamma.setFixedWidth(metrics.width("8888.88888"))
        self._editux.setFixedWidth(metrics.width("8888.88888"))
        self._edituy.setFixedWidth(metrics.width("8888.88888"))
        self._edituz.setFixedWidth(metrics.width("8888.88888"))
        self._editvx.setFixedWidth(metrics.width("8888.88888"))
        self._editvy.setFixedWidth(metrics.width("8888.88888"))
        self._editvz.setFixedWidth(metrics.width("8888.88888"))
        #layout
        grid = QtWidgets.QGridLayout()
        self.setLayout(grid)
        grid.addWidget(self._labelclassic, 0, 0, 1, 3)
        grid.addWidget(self._labela, 1, 0, QtCore.Qt.AlignRight)
        grid.addWidget(self._edita, 1, 1)
        grid.addWidget(self._labelb, 1, 2, QtCore.Qt.AlignRight)
        grid.addWidget(self._editb, 1, 3)
        grid.addWidget(self._labelc, 1, 4, QtCore.Qt.AlignRight)
        grid.addWidget(self._editc, 1, 5)
        grid.addWidget(self._labelalpha, 2, 0, QtCore.Qt.AlignRight)
        grid.addWidget(self._editalpha, 2, 1)
        grid.addWidget(self._labelbeta, 2, 2, QtCore.Qt.AlignRight)
        grid.addWidget(self._editbeta, 2, 3)
        grid.addWidget(self._labelgamma, 2, 4, QtCore.Qt.AlignRight)
        grid.addWidget(self._editgamma, 2, 5)
        grid.addWidget(self._labelux, 3, 0, QtCore.Qt.AlignRight)
        grid.addWidget(self._editux, 3, 1)
        grid.addWidget(self._labeluy, 3, 2, QtCore.Qt.AlignRight)
        grid.addWidget(self._edituy, 3, 3)
        grid.addWidget(self._labeluz, 3, 4, QtCore.Qt.AlignRight)
        grid.addWidget(self._edituz, 3, 5)
        grid.addWidget(self._labelvx, 4, 0, QtCore.Qt.AlignRight)
        grid.addWidget(self._editvx, 4, 1)
        grid.addWidget(self._labelvy, 4, 2, QtCore.Qt.AlignRight)
        grid.addWidget(self._editvy, 4, 3)
        grid.addWidget(self._labelvz, 4, 4, QtCore.Qt.AlignRight)
        grid.addWidget(self._editvz, 4, 5)
        #update oriented lattice and gui
        self.updateOL(self.ol)

        #connections
        self._edita.textEdited.connect(self.check_state_latt)
        self._editb.textEdited.connect(self.check_state_latt)
        self._editc.textEdited.connect(self.check_state_latt)
        self._editalpha.textEdited.connect(self.check_state_latt)
        self._editbeta.textEdited.connect(self.check_state_latt)
        self._editgamma.textEdited.connect(self.check_state_latt)
        self._editux.textEdited.connect(self.check_state_orientation)
        self._edituy.textEdited.connect(self.check_state_orientation)
        self._edituz.textEdited.connect(self.check_state_orientation)
        self._editvx.textEdited.connect(self.check_state_orientation)
        self._editvy.textEdited.connect(self.check_state_orientation)
        self._editvz.textEdited.connect(self.check_state_orientation)
Example #26
0
 def __init__(self, parent=None):
     # pylint: disable=unused-argument,super-on-old-class
     super(InstrumentSetupWidget, self).__init__()
     metrics = QtGui.QFontMetrics(self.font())
     self.signaldict = dict()
     #instrument selector
     self.instrumentList = [
         'ARCS', 'CNCS', 'DNS', 'EXED', 'FOCUS', 'HET', 'HYSPEC', 'LET',
         'MAPS', 'MARI', 'MERLIN', 'SEQUOIA'
     ]
     self.combo = QtWidgets.QComboBox(self)
     for inst in self.instrumentList:
         self.combo.addItem(inst)
     defaultInstrument = mantid.config.getInstrument().name()
     if defaultInstrument in self.instrumentList:
         self.instrument = defaultInstrument
         self.combo.setCurrentIndex(
             self.instrumentList.index(defaultInstrument))
     else:
         self.instrument = self.instrumentList[0]
         self.combo.setCurrentIndex(0)
     self.signaldict['instrument'] = self.instrument
     self.labelInst = QtWidgets.QLabel('Instrument')
     #S2 and Ei edits
     self.S2 = 0.0
     self.Ei = 10.0
     self.signaldict['S2'] = self.S2
     self.signaldict['Ei'] = self.Ei
     self.validatorS2 = QtGui.QDoubleValidator(-90., 90., 5, self)
     self.validatorEi = QtGui.QDoubleValidator(1., 10000., 5, self)
     self.labelS2 = QtWidgets.QLabel('S2')
     self.labelEi = QtWidgets.QLabel('Incident Energy')
     self.editS2 = QtWidgets.QLineEdit()
     self.editS2.setValidator(self.validatorS2)
     self.editEi = QtWidgets.QLineEdit()
     self.editEi.setValidator(self.validatorEi)
     self.editS2.setText(QString(format(self.S2, '.2f')))
     self.editEi.setText(QString(format(self.Ei, '.1f')))
     self.editEi.setFixedWidth(metrics.width("8888.88"))
     self.editS2.setFixedWidth(metrics.width("888.88"))
     #fast checkbox
     self.fast = QtWidgets.QCheckBox("Fast", self)
     self.fast.toggle()
     self.updateFast()
     #masking
     self.labelMask = QtWidgets.QLabel('Mask file')
     self.editMask = QtWidgets.QLineEdit()
     self.buttonMask = QtWidgets.QPushButton("LoadMask")
     #goniometer settings
     self.labelGon = QtWidgets.QLabel('Goniometer')
     self.tableViewGon = QtWidgets.QTableView(self)
     self.tableViewGon.setMinimumWidth(metrics.width("Minimum ") * 8)
     self.tableViewGon.horizontalHeader().setSectionResizeMode(
         QtWidgets.QHeaderView.Stretch)
     self.tableViewGon.verticalHeader().setSectionResizeMode(
         QtWidgets.QHeaderView.Stretch)
     self.goniometerNames = ['psi', 'gl', 'gs']
     self.goniometerDirections = ['0,1,0', '0,0,1', '1,0,0']
     self.goniometerRotationSense = [1, 1, 1]
     self.goniometerMin = [0., 0., 0.]
     self.goniometerMax = [0., 0., 0.]
     self.goniometerStep = [1., 1., 1.]
     values = {
         'gonioLabels': self.goniometerNames,
         'gonioDirs': self.goniometerDirections,
         'gonioSenses': self.goniometerRotationSense,
         'gonioMinvals': self.goniometerMin,
         'gonioMaxvals': self.goniometerMax,
         'gonioSteps': self.goniometerStep
     }
     self.goniomodel = GonioTableModel(values, self)
     self.tableViewGon.setModel(self.goniomodel)
     self.tableViewGon.update()
     self.signaldict.update(values)
     #goniometer figure
     self.figure = Figure(figsize=(2, 3))
     self.figure.patch.set_facecolor('white')
     self.canvas = FigureCanvasQTAgg(self.figure)
     self.gonfig = None
     self.updateFigure()
     #layout
     self.gridI = QtWidgets.QGridLayout()
     self.gridI.addWidget(self.labelInst, 0, 0)
     self.gridI.addWidget(self.combo, 0, 1)
     self.gridI.addWidget(self.labelEi, 0, 2)
     self.gridI.addWidget(self.editEi, 0, 3)
     self.gridI.addWidget(self.labelS2, 0, 4)
     self.gridI.addWidget(self.editS2, 0, 5)
     self.gridI.addWidget(self.fast, 0, 6)
     self.setLayout(QtWidgets.QHBoxLayout())
     self.rightside = QtWidgets.QVBoxLayout()
     self.maskLayout = QtWidgets.QHBoxLayout()
     self.maskLayout.addWidget(self.labelMask)
     self.maskLayout.addWidget(self.editMask)
     self.maskLayout.addWidget(self.buttonMask)
     self.layout().addLayout(self.rightside)
     self.rightside.addLayout(self.gridI)
     self.rightside.addLayout(self.maskLayout)
     self.rightside.addWidget(self.labelGon)
     self.rightside.addWidget(self.tableViewGon)
     self.layout().addWidget(self.canvas)
     #connections
     self.editS2.textEdited.connect(self.checkValidInputs)
     self.editMask.textEdited.connect(self.setMaskFile)
     self.combo.activated[str].connect(self.instrumentSelected)
     self.fast.stateChanged.connect(self.updateFast)
     self.buttonMask.clicked.connect(self.loadMaskFromFile)
     self.editEi.textEdited.connect(self.checkValidInputs)
     #call instrumentSelected once
     self.instrumentSelected(self.instrument)
     #connect goniometer change with figure
     self.goniomodel.changed.connect(self.updateFigure)
     self.updateAll()
Example #27
0
 def lineedit(hint):
     widget = text.HintedLineEdit(hint)
     metrics = QtGui.QFontMetrics(widget.font())
     widget.setMinimumWidth(metrics.width('_' * 32))
     return widget
Example #28
0
    def set_min_size(self, minfs):
        f = self.font()
        f.setPixelSize(minfs)
        br = QtGui.QFontMetrics(f).boundingRect(self.text())

        self.setMinimumSize(br.width(), br.height())
Example #29
0
 def minimumSizeHint(self):
     height = super(ZoomWidget, self).minimumSizeHint().height()
     fm = QtGui.QFontMetrics(self.font())
     width = fm.width(str(self.maximum()))
     return QtCore.QSize(width, height)
Example #30
0
    def __init__(self,
                 parent=None,
                 off_state=None,
                 on_state=None,
                 thumb_track_ratio=1):
        assert off_state is None or isinstance(
            off_state, str), 'off_state must be str or None'
        assert on_state is None or isinstance(
            on_state, str), 'on_state must be str or None'
        super().__init__(parent=parent)

        # remember state names
        if off_state is None and on_state is None:
            self._state_names = None
        else:
            self._state_names = (off_state, on_state)

        # Get default track height from QLineEdit sizeHint if thumb_track_ratio <= 1
        # If thumb_track_ratio > 1 the QLineEdit height will serve as thumb diameter
        if thumb_track_ratio > 1:
            self._thumb_radius = int(
                round(QtWidgets.QLineEdit().sizeHint().height() / 2))
            self._track_radius = max(
                1, int(round(self._thumb_radius / thumb_track_ratio)))
            self._text_font = QtWidgets.QLabel().font()
        else:
            self._track_radius = int(
                round(QtWidgets.QLineEdit().sizeHint().height() / 2))
            self._thumb_radius = max(
                1, int(round(self._track_radius * thumb_track_ratio)))
        self._track_margin = max(0, self._thumb_radius - self._track_radius)
        self._thumb_origin = max(self._thumb_radius, self._track_radius)

        # Determine appearance from current palette depending on thumb style
        palette = self.palette()
        if thumb_track_ratio > 1:
            self._track_colors = (palette.dark(), palette.highlight())
            self._thumb_colors = (palette.light(), palette.highlight())
            self._text_colors = (palette.text().color(),
                                 palette.highlightedText().color())
            self._track_opacity = 0.5
        else:
            self._track_colors = (palette.dark(), palette.highlight())
            self._thumb_colors = (palette.light(), palette.highlightedText())
            self._text_colors = (palette.text().color(),
                                 palette.highlightedText().color())
            self._track_opacity = 1
        self._text_font = QtGui.QFont()
        # self._text_font.setBold(True)
        self._text_font.setPixelSize(1.5 * self._track_radius)

        # property value for current thumb position
        self._thumb_position = self._thumb_origin

        self.setCheckable(True)
        self.setSizePolicy(QtWidgets.QSizePolicy.Preferred,
                           QtWidgets.QSizePolicy.Fixed)
        if self._state_names is None or thumb_track_ratio > 1:
            self._text_width = 0
        else:
            metrics = QtGui.QFontMetrics(self._text_font)
            self._text_width = max(
                metrics.width(f' {text} ') for text in self._state_names
                if text)
        self._size_hint = QtCore.QSize(
            4 * self._track_radius + 2 * self._track_margin + self._text_width,
            2 * self._track_radius + 2 * self._track_margin)
        self.setMinimumSize(self._size_hint)