Ejemplo n.º 1
0
    def __init__(self, parent):
        super(KiteIntegrationInfo, self).__init__(parent)
        # Images
        images_layout = QHBoxLayout()
        if is_dark_interface():
            icon_filename = 'spyder_kite.svg'
        else:
            icon_filename = 'spyder_kite_dark.svg'
        image_path = get_image_path(icon_filename)
        image = QPixmap(image_path)
        image_label = QLabel()
        screen = QApplication.primaryScreen()
        device_image_ratio = screen.devicePixelRatio()
        if device_image_ratio > 1:
            image.setDevicePixelRatio(device_image_ratio)
        else:
            image_height = image.height() * 0.5
            image_width = image.width() * 0.5
            image = image.scaled(image_width, image_height, Qt.KeepAspectRatio,
                                 Qt.SmoothTransformation)
        image_label.setPixmap(image)

        images_layout.addStretch()
        images_layout.addWidget(image_label)
        images_layout.addStretch()

        # Label
        integration_label = QLabel(
            _("Now Spyder can use <a href=\"{kite_url}\">Kite</a> to "
              "provide better and more accurate code completions in its "
              "editor <br>for the most important packages in the Python "
              "scientific ecosystem, such as Numpy, <br>Matplotlib and "
              "Pandas.<br><br>Would you like to install it or learn more "
              "about it?<br><br><i>Note:</i> Kite is free to use "
              "but is not an open source program.").format(
                  kite_url=KITE_SPYDER_URL))
        integration_label.setOpenExternalLinks(True)

        # Buttons
        buttons_layout = QHBoxLayout()
        learn_more_button = QPushButton(_('Learn more'))
        learn_more_button.setAutoDefault(False)
        install_button = QPushButton(_('Install Kite'))
        install_button.setAutoDefault(False)
        dismiss_button = QPushButton(_('Dismiss'))
        dismiss_button.setAutoDefault(False)
        buttons_layout.addStretch()
        buttons_layout.addWidget(install_button)
        buttons_layout.addWidget(learn_more_button)
        buttons_layout.addWidget(dismiss_button)

        general_layout = QVBoxLayout()
        general_layout.addLayout(images_layout)
        general_layout.addWidget(integration_label)
        general_layout.addLayout(buttons_layout)
        self.setLayout(general_layout)

        learn_more_button.clicked.connect(self.sig_learn_more_button_clicked)
        install_button.clicked.connect(self.sig_install_button_clicked)
        dismiss_button.clicked.connect(self.sig_dismiss_button_clicked)
Ejemplo n.º 2
0
def get_screen_resolution():
    """Return screen resolution: tuple of floats (DPIx, DPIy)"""
    try:
        desktop = QApplication.desktop()
        return (desktop.logicalDpiX(), desktop.logicalDpiY())
    except AttributeError:
        screen = QApplication.primaryScreen()
        return (screen.logicalDotsPerInchX(), screen.logicalDotsPerInchY())
Ejemplo n.º 3
0
    def __init__(self, parent):
        super(KiteIntegrationInfo, self).__init__(parent)
        # Images
        images_layout = QHBoxLayout()
        icon_filename = 'kite_completions.png'
        image_path = get_image_path(icon_filename)
        image = QPixmap(image_path)
        image_label = QLabel()
        screen = QApplication.primaryScreen()
        image_label = QLabel()
        image_height = int(image.height() * self.ICON_SCALE_FACTOR)
        image_width = int(image.width() * self.ICON_SCALE_FACTOR)
        image = image.scaled(image_width, image_height, Qt.KeepAspectRatio,
                             Qt.SmoothTransformation)
        image_label.setPixmap(image)

        images_layout.addStretch()
        images_layout.addWidget(image_label)
        images_layout.addStretch()

        ilayout = QHBoxLayout()
        ilayout.addLayout(images_layout)

        # Label
        integration_label_title = QLabel(
            "Get better code completions in Spyder")
        integration_label_title.setStyleSheet(
            f"font-size: {self.TITLE_FONT_SIZE}")
        integration_label_title.setWordWrap(True)
        integration_label = QLabel(
            _("Now Spyder can use Kite to provide better code "
              "completions for key packages in the scientific Python "
              "Ecosystem. Install Kite for a better editor experience in "
              "Spyder. <br><br>Kite is free to use but is not open "
              "source. <a href=\"{kite_url}\">Learn more about Kite </a>").
            format(kite_url=KITE_SPYDER_URL))
        integration_label.setStyleSheet(f"font-size: {self.CONTENT_FONT_SIZE}")
        integration_label.setOpenExternalLinks(True)
        integration_label.setWordWrap(True)
        integration_label.setFixedWidth(360)
        label_layout = QVBoxLayout()
        label_layout.addWidget(integration_label_title)
        label_layout.addWidget(integration_label)

        # Buttons
        buttons_layout = QHBoxLayout()
        install_button = QPushButton(_('Install Kite'))
        install_button.setAutoDefault(False)
        install_button.setStyleSheet("background-color: #3775A9;"
                                     f"font-size: {self.BUTTONS_FONT_SIZE};"
                                     f"padding: {self.BUTTONS_PADDING}")
        dismiss_button = QPushButton(_('Dismiss'))
        dismiss_button.setAutoDefault(False)
        dismiss_button.setStyleSheet("background-color: #60798B;"
                                     f"font-size: {self.BUTTONS_FONT_SIZE};"
                                     f"padding: {self.BUTTONS_PADDING}")
        buttons_layout.addStretch()
        buttons_layout.addWidget(install_button)
        if not MAC:
            buttons_layout.addSpacing(10)
        buttons_layout.addWidget(dismiss_button)

        # Buttons with label
        vertical_layout = QVBoxLayout()
        if not MAC:
            vertical_layout.addStretch()
            vertical_layout.addLayout(label_layout)
            vertical_layout.addSpacing(20)
            vertical_layout.addLayout(buttons_layout)
            vertical_layout.addStretch()
        else:
            vertical_layout.addLayout(label_layout)
            vertical_layout.addLayout(buttons_layout)

        general_layout = QHBoxLayout()
        general_layout.addStretch()
        general_layout.addLayout(ilayout)
        general_layout.addSpacing(15)
        general_layout.addLayout(vertical_layout)
        general_layout.addStretch()

        self.setLayout(general_layout)

        # Signals
        install_button.clicked.connect(self.sig_install_button_clicked)
        dismiss_button.clicked.connect(self.sig_dismiss_button_clicked)

        if is_dark_interface():
            self.setStyleSheet("background-color: #262E38")
        self.setContentsMargins(18, 40, 18, 40)
        if not MAC:
            self.setFixedSize(800, 350)
Ejemplo n.º 4
0
    def __init__(self, parent):
        super(KiteInstallation, self).__init__(parent)

        # Left side
        action_layout = QVBoxLayout()
        progress_layout = QHBoxLayout()
        self._progress_widget = QWidget(self)
        self._progress_widget.setFixedHeight(50)
        self._progress_filter = HoverEventFilter()
        self._progress_bar = QProgressBar(self)
        self._progress_bar.setFixedWidth(180)
        self._progress_widget.installEventFilter(self._progress_filter)
        self.cancel_button = QPushButton()
        self.cancel_button.setIcon(ima.icon('DialogCloseButton'))
        self.cancel_button.hide()
        progress_layout.addWidget(self._progress_bar, alignment=Qt.AlignLeft)
        progress_layout.addWidget(self.cancel_button)
        self._progress_widget.setLayout(progress_layout)

        self._progress_label = QLabel(_('Downloading'))
        install_info = QLabel(
            _("Kite comes with a native app called the Copilot <br>"
              "which provides you with real time <br>"
              "documentation as you code.<br><br>"
              "When Kite is done installing, the Copilot will <br>"
              "launch automatically and guide you throught the <br>"
              "rest of the setup process."))

        button_layout = QHBoxLayout()
        self.ok_button = QPushButton(_('OK'))
        button_layout.addStretch()
        button_layout.addWidget(self.ok_button)
        button_layout.addStretch()

        action_layout.addStretch()
        action_layout.addWidget(self._progress_label)
        action_layout.addWidget(self._progress_widget)
        action_layout.addWidget(install_info)
        action_layout.addSpacing(10)
        action_layout.addLayout(button_layout)
        action_layout.addStretch()

        # Right side
        copilot_image_source = get_image_path('kite_copilot.png')

        copilot_image = QPixmap(copilot_image_source)
        copilot_label = QLabel()
        screen = QApplication.primaryScreen()
        device_pixel_ratio = screen.devicePixelRatio()
        if device_pixel_ratio > 1:
            copilot_image.setDevicePixelRatio(device_pixel_ratio)
            copilot_label.setPixmap(copilot_image)
        else:
            image_height = int(copilot_image.height() * 0.4)
            image_width = int(copilot_image.width() * 0.4)
            copilot_label.setPixmap(
                copilot_image.scaled(image_width, image_height,
                                     Qt.KeepAspectRatio,
                                     Qt.SmoothTransformation))

        # Layout
        general_layout = QHBoxLayout()
        general_layout.addLayout(action_layout)
        general_layout.addWidget(copilot_label)

        self.setLayout(general_layout)

        # Signals
        self._progress_filter.sig_hover_enter.connect(
            lambda: self.cancel_button.show())
        self._progress_filter.sig_hover_leave.connect(
            lambda: self.cancel_button.hide())
Ejemplo n.º 5
0
    def __init__(self, settings: QSettings, parent=None):
        super().__init__(parent)
        self.settings = settings
        self.parent = parent

        # Load wizard.ui
        self.ui = loadUi(dirname(__file__) + "/settings.ui", self)

        # Adjust widget sizes and resize window
        self.adjustSize()
        self.resize(self.minimumSize())

        # Center window on primary screen
        self.move(QApplication.primaryScreen().geometry().center() -
                  self.rect().center())

        # Load settings and define defaults
        self.ui.portLine.setText(
            self.settings.value("serial/port", "/dev/ttyUSB0"))
        self.ui.baudrateCombo.setCurrentText(
            self.settings.value("serial/baudrate", "115200"))
        self.ui.addressSpin.setValue(
            int(self.settings.value("serial/address", 1)))
        self.ui.pollingSpin.setValue(int(self.settings.value("polling", 500)))
        self.ui.inputVoltagePush.setStyleSheet(
            self.settings.value("style/input-voltage",
                                self.ui.inputVoltagePush.styleSheet()))
        self.ui.outputVoltagePush.setStyleSheet(
            self.settings.value("style/output-voltage",
                                self.ui.outputVoltagePush.styleSheet()))
        self.ui.outputCurrentPush.setStyleSheet(
            self.settings.value("style/output-current",
                                self.ui.outputCurrentPush.styleSheet()))
        self.ui.outputPowerPush.setStyleSheet(
            self.settings.value("style/output-power",
                                self.ui.outputPowerPush.styleSheet()))
        self.ui.voltageSetPush.setStyleSheet(
            self.settings.value("style/voltage-set",
                                self.ui.voltageSetPush.styleSheet()))
        self.ui.currentSetPush.setStyleSheet(
            self.settings.value("style/current-set",
                                self.ui.currentSetPush.styleSheet()))
        self.ui.outputOnTextPush.setStyleSheet(
            self.settings.value("style/output-on-text",
                                self.ui.outputOnTextPush.styleSheet()))
        self.ui.outputOffTextPush.setStyleSheet(
            self.settings.value("style/output-off-text",
                                self.ui.outputOffTextPush.styleSheet()))
        self.ui.outputFaultTextPush.setStyleSheet(
            self.settings.value("style/output-fault-text",
                                self.ui.outputFaultTextPush.styleSheet()))
        self.ui.outputOnButtonPush.setStyleSheet(
            self.settings.value("style/output-on-bg",
                                self.ui.outputOnButtonPush.styleSheet()))
        self.ui.outputOffButtonPush.setStyleSheet(
            self.settings.value("style/output-off-bg",
                                self.ui.outputOffButtonPush.styleSheet()))
        self.ui.outputFaultButtonPush.setStyleSheet(
            self.settings.value("style/output-fault-bg",
                                self.ui.outputFaultButtonPush.styleSheet()))
        self.ui.inputVoltageLine.setText(
            self.settings.value("format/voltage-input",
                                self.parent.default_voltage_input_format))
        self.ui.outputVoltageLine.setText(
            self.settings.value("format/voltage-output",
                                self.parent.default_voltage_output_format))
        self.ui.outputCurrentLine.setText(
            self.settings.value("format/current-output",
                                self.parent.default_current_output_format))
        self.ui.outputPowerLine.setText(
            self.settings.value("format/power-output",
                                self.parent.default_power_output_format))

        for button in (
                self.ui.inputVoltagePush,
                self.ui.outputVoltagePush,
                self.ui.outputCurrentPush,
                self.ui.outputPowerPush,
                self.ui.voltageSetPush,
                self.ui.currentSetPush,
                self.ui.outputOnTextPush,
                self.ui.outputOffTextPush,
                self.ui.outputFaultTextPush,
                self.ui.outputOnButtonPush,
                self.ui.outputOffButtonPush,
                self.ui.outputFaultButtonPush,
        ):
            button.clicked.connect(self.button_clicked)
Ejemplo n.º 6
0
    def __init__(self, parent):
        super(KiteIntegrationInfo, self).__init__(parent)
        # Images
        images_layout = QHBoxLayout()
        icon_filename = 'kite_completions'
        image_path = get_image_path(icon_filename)
        image = QPixmap(image_path)
        image_label = QLabel()
        screen = QApplication.primaryScreen()
        image_label = QLabel()
        image_height = int(image.height() * self.ICON_SCALE_FACTOR)
        image_width = int(image.width() * self.ICON_SCALE_FACTOR)
        image = image.scaled(image_width, image_height, Qt.KeepAspectRatio,
                             Qt.SmoothTransformation)
        image_label.setPixmap(image)

        images_layout.addStretch()
        images_layout.addWidget(image_label)
        images_layout.addStretch()

        ilayout = QHBoxLayout()
        ilayout.addLayout(images_layout)

        # Label
        integration_label_title = QLabel(
            "Get better code completions in Spyder")
        integration_label_title.setStyleSheet(
            f"font-size: {self.TITLE_FONT_SIZE}")
        integration_label_title.setWordWrap(True)
        integration_label = QLabel(
            _("Now Spyder can use Kite to provide better code "
              "completions for key packages in the scientific Python "
              "Ecosystem. Install Kite for a better editor experience in "
              "Spyder. <br><br>Kite is free to use but is not open "
              "source. <a href=\"{kite_url}\">Learn more about Kite </a>").
            format(kite_url=KITE_SPYDER_URL))
        integration_label.setStyleSheet(f"font-size: {self.CONTENT_FONT_SIZE}")
        integration_label.setOpenExternalLinks(True)
        integration_label.setWordWrap(True)
        integration_label.setFixedWidth(360)
        label_layout = QVBoxLayout()
        label_layout.addWidget(integration_label_title)
        label_layout.addWidget(integration_label)

        # Buttons
        install_button_color = QStylePalette.COLOR_ACCENT_2
        install_button_hover = QStylePalette.COLOR_ACCENT_3
        install_button_pressed = QStylePalette.COLOR_ACCENT_4
        dismiss_button_color = QStylePalette.COLOR_BACKGROUND_4
        dismiss_button_hover = QStylePalette.COLOR_BACKGROUND_5
        dismiss_button_pressed = QStylePalette.COLOR_BACKGROUND_6
        font_color = QStylePalette.COLOR_TEXT_1
        buttons_layout = QHBoxLayout()
        install_button = QPushButton(_('Install Kite'))
        install_button.setAutoDefault(False)
        install_button.setStyleSheet(
            ("QPushButton {{ "
             "background-color: {background_color};"
             "border-color: {border_color};"
             "font-size: {font_size};"
             "color: {font_color};"
             "padding: {padding}}}"
             "QPushButton:hover:!pressed {{ "
             "background-color: {color_hover}}}"
             "QPushButton:pressed {{ "
             "background-color: {color_pressed}}}").format(
                 background_color=install_button_color,
                 border_color=install_button_color,
                 font_size=self.BUTTONS_FONT_SIZE,
                 font_color=font_color,
                 padding=self.BUTTONS_PADDING,
                 color_hover=install_button_hover,
                 color_pressed=install_button_pressed))
        dismiss_button = QPushButton(_('Dismiss'))
        dismiss_button.setAutoDefault(False)
        dismiss_button.setStyleSheet(
            ("QPushButton {{ "
             "background-color: {background_color};"
             "border-color: {border_color};"
             "font-size: {font_size};"
             "color: {font_color};"
             "padding: {padding}}}"
             "QPushButton:hover:!pressed {{ "
             "background-color: {color_hover}}}"
             "QPushButton:pressed {{ "
             "background-color: {color_pressed}}}").format(
                 background_color=dismiss_button_color,
                 border_color=dismiss_button_color,
                 font_size=self.BUTTONS_FONT_SIZE,
                 font_color=font_color,
                 padding=self.BUTTONS_PADDING,
                 color_hover=dismiss_button_hover,
                 color_pressed=dismiss_button_pressed))
        buttons_layout.addStretch()
        buttons_layout.addWidget(install_button)
        if not MAC:
            buttons_layout.addSpacing(10)
        buttons_layout.addWidget(dismiss_button)

        # Buttons with label
        vertical_layout = QVBoxLayout()
        if not MAC:
            vertical_layout.addStretch()
            vertical_layout.addLayout(label_layout)
            vertical_layout.addSpacing(20)
            vertical_layout.addLayout(buttons_layout)
            vertical_layout.addStretch()
        else:
            vertical_layout.addLayout(label_layout)
            vertical_layout.addLayout(buttons_layout)

        general_layout = QHBoxLayout()
        general_layout.addStretch()
        general_layout.addLayout(ilayout)
        general_layout.addSpacing(15)
        general_layout.addLayout(vertical_layout)
        general_layout.addStretch()

        self.setLayout(general_layout)

        # Signals
        install_button.clicked.connect(self.sig_install_button_clicked)
        dismiss_button.clicked.connect(self.sig_dismiss_button_clicked)

        self.setStyleSheet(
            f"background-color: {QStylePalette.COLOR_BACKGROUND_2}")
        self.setContentsMargins(18, 40, 18, 40)
        if not MAC:
            self.setFixedSize(800, 350)
Ejemplo n.º 7
0
    def _pickColor(self, pos, constrain_to_picker=True):
        """
        picks the the current color displayed on screen at
        the current location of the cursor

        Args:
            pos (QPoint): Global pos
            constrain_to_pick (bool): determines whether or not the crosshair
                should be forced to remain inside of the picker while the user
                is selecting.
        """
        # preflight check (cursor)
        # forces the cursor to remain inside of the color picker
        # TODO Removing bouncing
        """
        display is bouncing when reaching ends as it snaps back to the last
        position in space.  It also cannot get the final 0/1 values =
        """
        if constrain_to_picker is True:
            cursor_sector_dict = checkMousePos(pos, self)
            if cursor_sector_dict["INSIDE"] is False:
                top_left = self.mapToGlobal(self.pos())
                top = top_left.y()
                left = top_left.x()
                right = left + self.geometry().width()
                bottom = top + self.geometry().height()

                if cursor_sector_dict["NORTH"] is True:
                    pos.setY(top + 1)
                if cursor_sector_dict["EAST"] is True:
                    pos.setX(right - 1)
                if cursor_sector_dict["SOUTH"] is True:
                    pos.setY(bottom - 1)
                if cursor_sector_dict["WEST"] is True:
                    pos.setX(left + 1)

                QCursor.setPos(pos)

        # self.scene().rgba_crosshair_item.hide()
        # get pixel data
        desktop = QApplication.desktop().winId()
        screen = QApplication.primaryScreen()
        pixmap = screen.grabWindow(
            desktop,
            pos.x(), pos.y(),
            1, 1
        )
        img = pixmap.toImage()
        color = QColor(img.pixel(0, 0))

        # if pure black recurse
        # if color.valueF() == 0:
        # TODO
        """
        Grabbing color of picker because fails
        """
        if color.valueF() < .0001:
            self._black_select = True
            pos = QPoint(pos.x() + 1, pos.y() + 1)
            return self._pickColor(pos)

        return color
Ejemplo n.º 8
0
                    return fullname


class MouseEventFilter(QtCore.QObject):
    def eventFilter(self, obj, event):
        if event.type() == QtCore.QEvent.GraphicsSceneMousePress:
            #print("Mouse Click observed")
            return True
        return False


if __name__ == "__main__":
    app = QApplication(sys.argv)
    #print("script location =", os.path.dirname(os.path.realpath(sys.argv[0])))
    #print("help location =", os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "instructions.png"))
    screen = app.primaryScreen()
    size = screen.size()
    rect = screen.availableGeometry()
    #print("Screen size =", size.width(), "X", size.height())
    #print("Available screen size =", rect.width(), "X", rect.height())
    pix_ratio = screen.devicePixelRatio()
    currentPath = os.getcwd()

    if node() == 'MacBook-Pro.local':
        myapp = MyForm(size.width(),
                       size.height() - 32, pix_ratio, currentPath)
    else:
        myapp = MyForm(size.width(), size.height(), pix_ratio, currentPath)

    myapp.show()
    sys.exit(app.exec_())