Exemple #1
0
 def send_ctrl_to_process(self, letter):
     char = chr("abcdefghijklmnopqrstuvwxyz".index(letter) + 1)
     byte_array = QByteArray()
     byte_array.append(char)
     self.process.write(byte_array)
     self.process.waitForBytesWritten(-1)
     self.shell.write(LOCALE_CODEC.toUnicode(byte_array), flush=True)
Exemple #2
0
 def mouseMoveEvent(self, event):
     """Override Qt method"""
     if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \
        (event.pos() - self.__drag_start_pos).manhattanLength() > \
             QApplication.startDragDistance():
         drag = QDrag(self)
         mimeData = QMimeData()
         # Converting id's to long to avoid an OverflowError with PySide
         if PY2:
             ancestor_id = long(id(self.ancestor))
             parent_widget_id = long(id(self.parentWidget()))
             self_id = long(id(self))
         else:
             ancestor_id = id(self.ancestor)
             parent_widget_id = id(self.parentWidget())
             self_id = id(self)
         mimeData.setData("parent-id", QByteArray.number(ancestor_id))
         mimeData.setData("tabwidget-id",
                          QByteArray.number(parent_widget_id))
         mimeData.setData("tabbar-id", QByteArray.number(self_id))
         mimeData.setData("source-index", 
                      QByteArray.number(self.tabAt(self.__drag_start_pos)))
         drag.setMimeData(mimeData)
         drag.exec_()
     QTabBar.mouseMoveEvent(self, event)
Exemple #3
0
 def mouseMoveEvent(self, event):
     """Override Qt method"""
     if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \
        (event.pos() - self.__drag_start_pos).manhattanLength() > \
             QApplication.startDragDistance():
         drag = QDrag(self)
         mimeData = QMimeData()
         # Converting id's to long to avoid an OverflowError with PySide
         if PY2:
             ancestor_id = long(id(self.ancestor))
             parent_widget_id = long(id(self.parentWidget()))
             self_id = long(id(self))
         else:
             ancestor_id = id(self.ancestor)
             parent_widget_id = id(self.parentWidget())
             self_id = id(self)
         mimeData.setData("parent-id", QByteArray.number(ancestor_id))
         mimeData.setData("tabwidget-id",
                          QByteArray.number(parent_widget_id))
         mimeData.setData("tabbar-id", QByteArray.number(self_id))
         mimeData.setData(
             "source-index",
             QByteArray.number(self.tabAt(self.__drag_start_pos)))
         drag.setMimeData(mimeData)
         drag.exec_()
     QTabBar.mouseMoveEvent(self, event)
def QImage_to_compressed_bytes(qimage, format):
    """
    Compress QImage or QPixmap into bytes corresponding to a image file format (BMP,PNG,JPG)

    To reconstruct the QImage or QPixamp :
    image = QImage.fromData(data)
    image = QImage() ; image.loadFromData(data)
    image = QPixmap(); image.loadFromData(data)


    The QImage.format will be preserved when loading only if in format in :
    Format_Mono
    Format_Indexed8
    Format_RGB32
    Format_ARGB32
    Format_Grayscale8

    """
    # https://stackoverflow.com/questions/24965646/convert-pyqt4-qtgui-qimage-object-to-base64-png-data
    # https://stackoverflow.com/questions/57404778/how-to-convert-a-qpixmaps-image-into-a-bytes

    qbytearray = QByteArray()
    qbuffer = QBuffer(qbytearray)
    qbuffer.open(QIODevice.WriteOnly)
    ok = qimage.save(qbuffer, format)
    assert ok
    return qbytearray.data()  # fait une copie ?
Exemple #5
0
 def base64_from_icon_obj(self, icon_obj, width, height):
     """Convert icon object to base64 encoding."""
     image = QImage(icon_obj.pixmap(width, height).toImage())
     byte_array = QByteArray()
     buffer = QBuffer(byte_array)
     image.save(buffer, "PNG")
     return byte_array.toBase64().data().decode()
Exemple #6
0
    def _read_output(self, error=False):
        """
        Read otuput from QProcess.

        Parameters
        ----------
        error: bool, optional
            Process QProcess output or error channels. Default is False.
        """
        if error:
            self.process.setReadChannel(QProcess.StandardError)
        else:
            self.process.setReadChannel(QProcess.StandardOutput)

        qba = QByteArray()
        while self.process.bytesAvailable():
            if error:
                qba += self.process.readAllStandardError()
            else:
                qba += self.process.readAllStandardOutput()

        text = to_text_string(qba.data(), encoding='utf-8')
        if error:
            self.error_output += text
        else:
            self.output += text
Exemple #7
0
    def __init__(self, parent=None, standalone=False):
        super(Camera, self).__init__(parent)

        # This prevents doing unneeded initialization
        # when QtDesginer loads the plugin.
        if parent is None and not standalone:
            return

        if not multimedia_available:
            return

        self.ui = uic.loadUi(os.path.join(WIDGET_PATH, "camera.ui"), self)

        self.camera = None
        self.imageCapture = None
        self.mediaRecorder = None
        self.isCapturingImage = False
        self.applicationExiting = False

        self.imageSettings = QImageEncoderSettings()
        self.audioSettings = QAudioEncoderSettings()
        self.videoSettings = QVideoEncoderSettings()
        self.videoContainerFormat = ''

        camera_device = QByteArray()

        videoDevicesGroup = QActionGroup(self)

        videoDevicesGroup.setExclusive(True)

        if not QCamera.availableDevices():
            self.ui.devicesCombo.addItem("No Device")
        else:
            for deviceName in QCamera.availableDevices():
                description = QCamera.deviceDescription(deviceName)
                self.ui.devicesCombo.addItem(description)

                videoDeviceAction = QAction(description, videoDevicesGroup)
                videoDeviceAction.setCheckable(True)
                videoDeviceAction.setData(deviceName)

                if camera_device.isEmpty():
                    cameraDevice = deviceName
                    videoDeviceAction.setChecked(True)

                self.ui.devicesCombo.addAction(videoDeviceAction)

        videoDevicesGroup.triggered.connect(self.updateCameraDevice)

        self.ui.captureWidget.currentChanged.connect(self.updateCaptureMode)

        self.ui.devicesCombo.currentIndexChanged.connect(self.get_device_action)

        self.ui.lockButton.hide()
        
        if not IN_DESIGNER:
            # Start camera 2s after the UI has loaded
            QTimer.singleShot(2000, lambda: self.setCamera(camera_device))
Exemple #8
0
    def mouseMoveEvent(self, event):
        from qtpy.QtCore import QMimeData, QByteArray
        from qtpy.QtGui import QPixmap, QDrag

        if not (event.button() != Qt.LeftButton
                and isinstance(self.dragLabel, QLabel)):
            return

        if (event.pos() - self.dragStartPosition
            ).manhattanLength() < QApplication.startDragDistance():
            return

        axis_index = self.filters_layout.indexOf(self.dragLabel) // 2

        # prepare hotSpot, mimeData and pixmap objects
        mimeData = QMimeData()
        mimeData.setText(self.dragLabel.text())
        mimeData.setData("application/x-axis-index",
                         QByteArray.number(axis_index))
        pixmap = QPixmap(self.dragLabel.size())
        self.dragLabel.render(pixmap)

        # prepare drag object
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - self.dragStartPosition)

        drag.exec_(Qt.MoveAction | Qt.CopyAction, Qt.CopyAction)
Exemple #9
0
    def mouseMoveEvent(self, event):
        if (self._clickPos is None
                or (event.pos() - self._clickPos).manhattanLength() <
                QApplication.startDragDistance()):
            return

        # _log.debug("Drag move")
        # render before detachment otherwise it might look ugly
        pixmap = QPixmap(self.size())
        self.render(pixmap)

        self.setVisible(False)
        if len(self._dock.parentContainer.flatDockList) == 1:
            self._dock.parentContainer.setVisible(False)

        # Build drag object
        event.accept()
        drag = QDrag(self)
        mimeData = QMimeData()
        encodedData = QByteArray(pickle.dumps(self._dock.uid))
        mimeData.setData(MIME_TYPE, encodedData)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        action = drag.exec_(Qt.MoveAction)

        _log.debug("After drag. Action: {}".format(action))
        if Qt.IgnoreAction == action:
            _log.debug("D'n'D canceled")
            self.setVisible(True)
            self._dock.parentContainer.setVisible(True)
Exemple #10
0
    def _create_window(self):
        """Create a QMainWindow instance containing this plugin."""
        self._undocked_window = window = PluginWindow(self)
        window.setAttribute(Qt.WA_DeleteOnClose)
        icon = self.get_plugin_icon()
        if is_text_string(icon):
            icon = self.get_icon(icon)

        window.setWindowIcon(icon)
        window.setWindowTitle(self.get_plugin_title())
        window.setCentralWidget(self)
        window.resize(self.size())

        # Restore window geometry
        geometry = self.get_option('window_geometry', default='')
        if geometry:
            try:
                window.restoreGeometry(QByteArray().fromHex(
                    str(geometry).encode('utf-8')))
            except Exception:
                pass

        self.refresh_plugin()
        self.set_ancestor(window)
        self.dockwidget.setFloating(False)
        self.dockwidget.setVisible(False)

        window.show()
Exemple #11
0
    def render_bytes(self, svg_bytes: bytes):
        s = self.scene()
        s.clear()
        self.__svg_items = []
        self.resetTransform()

        self.__svg_renderer.load(QByteArray(svg_bytes))
        import xml.etree.ElementTree as ET
        g = "{http://www.w3.org/2000/svg}g"
        xml = svg_bytes.decode('utf-8')
        # logger.debug(xml)
        for i in ET.fromstring(xml).findall(f"./{g}/{g}"):
            if i.attrib['class'] == 'edge':
                item = SvgItem(i.attrib['id'], self.__svg_renderer)
            else:
                node_name = next(
                    (c.text for c in i
                     if c.tag == '{http://www.w3.org/2000/svg}title'), None)
                if node_name:
                    # logger.debug(f"Adding clickable item for {node_name}")
                    item = ClickableSvgItem(i.attrib['id'],
                                            self.__svg_renderer, self.signal,
                                            node_name)
                else:
                    # logger.debug(f"Adding standard item for {i.attrib['id']}")
                    item = SvgItem(i.attrib['id'], self.__svg_renderer)
            item.setFlags(QGraphicsItem.ItemClipsToShape)
            item.setCacheMode(QGraphicsItem.NoCache)
            item.setZValue(1)
            s.addItem(item)
        rect: QRectF = s.itemsBoundingRect()
        rect.adjust(-10, -10, 10, 10)
        s.setSceneRect(rect)
Exemple #12
0
 def read_output(self, error=False):
     if error:
         self.process.setReadChannel(QProcess.StandardError)
     else:
         self.process.setReadChannel(QProcess.StandardOutput)
     qba = QByteArray()
     while self.process.bytesAvailable():
         if error:
             qba += self.process.readAllStandardError()
         else:
             qba += self.process.readAllStandardOutput()
     text = to_text_string( locale_codec.toUnicode(qba.data()) )
     if error:
         self.error_output += text
     else:
         self.output += text
Exemple #13
0
 def read_output(self, error=False):
     if error:
         self.process.setReadChannel(QProcess.StandardError)
     else:
         self.process.setReadChannel(QProcess.StandardOutput)
     qba = QByteArray()
     while self.process.bytesAvailable():
         if error:
             qba += self.process.readAllStandardError()
         else:
             qba += self.process.readAllStandardOutput()
     text = to_text_string(locale_codec.toUnicode(qba.data()))
     if error:
         self.error_output += text
     else:
         self.output += text
Exemple #14
0
 def read_output(self, error=False):
     if error:
         self.process.setReadChannel(QProcess.StandardError)
     else:
         self.process.setReadChannel(QProcess.StandardOutput)
     qba = QByteArray()
     while self.process.bytesAvailable():
         if error:
             qba += self.process.readAllStandardError()
         else:
             qba += self.process.readAllStandardOutput()
     text = str(qba.data(), 'utf-8')
     if error:
         self.error_output += text
     else:
         self.output += text
    def __init__(self, settings: StackSettings, parent=None):
        super().__init__(parent)
        self.settings = settings
        self.calculate_btn = QPushButton("Calculate")
        self.calculate_btn.clicked.connect(self.calculate)
        self.result_view = QTableWidget()
        self.channel_select = ChannelComboBox()
        self.units_select = EnumComboBox(Units)
        self.units_select.set_value(self.settings.get("simple_measurements.units", Units.nm))
        self.units_select.currentIndexChanged.connect(self.change_units)

        layout = QHBoxLayout()
        self.measurement_layout = QVBoxLayout()
        l1 = QHBoxLayout()
        l1.addWidget(QLabel("Units"))
        l1.addWidget(self.units_select)
        self.measurement_layout.addLayout(l1)
        l2 = QHBoxLayout()
        l2.addWidget(QLabel("Channel"))
        l2.addWidget(self.channel_select)
        self.measurement_layout.addLayout(l2)
        layout.addLayout(self.measurement_layout)
        result_layout = QVBoxLayout()
        result_layout.addWidget(self.result_view)
        result_layout.addWidget(self.calculate_btn)
        layout.addLayout(result_layout)
        self.setLayout(layout)
        self.setWindowTitle("Measurement")
        if self.window() == self:
            try:
                geometry = self.settings.get_from_profile("simple_measurement_window_geometry")
                self.restoreGeometry(QByteArray.fromHex(bytes(geometry, "ascii")))
            except KeyError:
                pass
Exemple #16
0
 def __init__(self, parent=None):
     super(Downloader, self).__init__(parent)
     self.manager = QNetworkAccessManager()
     self.url = 'http://localhost:9998/jpg/image.jpg'
     self.request = QNetworkRequest()
     self.request.setUrl(QUrl(self.url))
     self.buffer = QByteArray()
     self.reply = None
Exemple #17
0
 def dropEvent(self, event: QDropEvent):
     mimedata = event.mimeData()
     data = QByteArray(mimedata.data("application/x_nodepath.list"))
     stream = QDataStream(data, QIODevice.ReadOnly)
     while not stream.atEnd():
         path = stream.readQString()
         self.parent().add_plot(path)
     event.acceptProposedAction()
Exemple #18
0
def qbytearray_to_str(qbyte: QByteArray) -> str:
    """Convert a window state to a string.

    Used for restoring the state of the main window.

    Parameters
    ----------
    qbyte : QByteArray
        State array.
    """
    return QBYTE_FLAG + qbyte.toBase64().data().decode()
Exemple #19
0
    def mimeData(self, indexes):
        self.indexes = [
            index.internalPointer() for index in indexes if index.column() == 0
        ]
        mimedata = QMimeData()
        mimedata.setData('application/x-qabstractitemmodeldatalist',
                         QByteArray())

        # run virtual function
        self.dragStartEvent(self.indexes)
        return mimedata
Exemple #20
0
    def set_window_settings(self, hexstate, window_size, prefs_dialog_size,
                            pos, is_maximized, is_fullscreen):
        """
        Set window settings Symetric to the 'get_window_settings' accessor.
        """
        main = self.main
        main.setUpdatesEnabled(False)
        self.prefs_dialog_size = QSize(prefs_dialog_size[0],
                                       prefs_dialog_size[1])  # width,height
        main.set_prefs_size(self.prefs_dialog_size)
        self.window_size = QSize(window_size[0],
                                 window_size[1])  # width, height
        self.window_position = QPoint(pos[0], pos[1])  # x,y
        main.setWindowState(Qt.WindowNoState)
        main.resize(self.window_size)
        main.move(self.window_position)

        # Window layout
        if hexstate:
            hexstate_valid = self.main.restoreState(
                QByteArray().fromHex(str(hexstate).encode('utf-8')),
                version=WINDOW_STATE_VERSION
            )

            # Check layout validity. Spyder 4 and below use the version 0
            # state (default), whereas Spyder 5 will use version 1 state.
            # For more info see the version argument for
            # QMainWindow.restoreState:
            # https://doc.qt.io/qt-5/qmainwindow.html#restoreState
            if not hexstate_valid:
                self.main.setUpdatesEnabled(True)
                self.setup_layout(default=True)
                return

            # Workaround for spyder-ide/spyder#880.
            # QDockWidget objects are not painted if restored as floating
            # windows, so we must dock them before showing the mainwindow.
            for widget in self.children():
                if isinstance(widget, QDockWidget) and widget.isFloating():
                    self.floating_dockwidgets.append(widget)
                    widget.setFloating(False)

        # Is fullscreen?
        if is_fullscreen:
            self.main.setWindowState(Qt.WindowFullScreen)

        # Is maximized?
        if is_fullscreen:
            self._maximized_flag = is_maximized
        elif is_maximized:
            self.main.setWindowState(Qt.WindowMaximized)

        self.main.setUpdatesEnabled(True)
Exemple #21
0
    def restore_state_from_xml(self, state: QByteArray, version: int,
                               testing: bool) -> bool:
        '''
        Restores the state

        Parameters
        ----------
        state : QByteArray
        version : int
        testing : bool

        Returns
        -------
        value : bool
        '''
        if state.isEmpty():
            return False

        stream = QXmlStreamReader(state)
        stream.readNextStartElement()
        if stream.name() != "QtAdvancedDockingSystem":
            return False

        v = stream.attributes().value("Version")
        if int(v) != version:
            return False

        result = True
        dock_containers = stream.attributes().value("Containers")
        logger.debug('dock_containers %s', dock_containers)
        dock_container_count = 0
        while stream.readNextStartElement():
            if stream.name() == "Container":
                result = self.restore_container(dock_container_count,
                                                stream,
                                                testing=testing)
                if not result:
                    break
                dock_container_count += 1

        if testing or not dock_container_count:
            return result

        # Delete remaining empty floating widgets
        floating_widget_index = dock_container_count - 1
        delete_count = len(self.floating_widgets) - floating_widget_index

        for i in range(delete_count):
            to_remove = self.floating_widgets[floating_widget_index + i]
            self.public.remove_dock_container(to_remove.dock_container())
            to_remove.deleteLater()

        return result
Exemple #22
0
    def paintEvent(self, event):
        """Handle appearence of the widget on state updates."""
        self.style().unpolish(self)
        self.style().polish(self)
        option = QStyleOption()
        option.initFrom(self)

        h = option.rect.height()
        w = option.rect.width()
        if self.m_shape in (self.ShapeMap.Triangle, self.ShapeMap.Round):
            aspect = (4 /
                      3.0) if self.m_shape == self.ShapeMap.Triangle else 2.0
            ah = w / aspect
            aw = w
            if ah > h:
                ah = h
                aw = h * aspect
            x = abs(aw - w) / 2.0
            y = abs(ah - h) / 2.0
            bounds = QRectF(x, y, aw, ah)
        else:
            size = min(w, h)
            x = abs(size - w) / 2.0
            y = abs(size - h) / 2.0
            bounds = QRectF(x, y, size, size)

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)

        ind = self.m_state % len(self.m_stateColors)
        dark_r, dark_g, dark_b = self.getRGBfromQColor(self.m_stateColors[ind])
        if not self.isEnabled():
            dark_r, dark_g, dark_b = self.getRGBfromQColor(self.m_dsblColor)

        sel1_r, sel1_g, sel1_b = self.getRGBfromQColor(self.SelColor)
        sel2_r, sel2_g, sel2_b = self.getRGBfromQColor(self.SelColor)
        opc = '1.000'
        if not self.isSelected():
            sel1_r, sel1_g, sel1_b = self.getRGBfromQColor(self.NotSelColor1)
            sel2_r, sel2_g, sel2_b = self.getRGBfromQColor(self.NotSelColor2)
            opc = '0.145'

        dark_str = "rgb(%d,%d,%d)" % (dark_r, dark_g, dark_b)
        light_str = "rgb(%d,%d,%d)" % self.adjust(dark_r, dark_g, dark_b)
        sel1_str = "rgb(%d,%d,%d)" % (sel1_r, sel1_g, sel1_b)
        sel2_str = "rgb(%d,%d,%d)" % (sel2_r, sel2_g, sel2_b)

        shape_bytes = bytes(
            self.shapesdict[self.m_shape] %
            (sel1_str, opc, sel2_str, dark_str, light_str), 'utf-8')

        self.renderer.load(QByteArray(shape_bytes))
        self.renderer.render(painter, bounds)
Exemple #23
0
def colorize_svg(
	src: Union[str, Path, IO[bytes]],
	dst: Union[None, str, Path, BinaryIO]=None,
	*,
	selected: bool=False,
	app: Optional[QApplication]=None,
) -> bytes:
	"""Inject colors into a breeze-style SVG.
	
	:param src: A file object or path to read SVG data from.
	:param dst: A file object or path to write SVG data to.
	:param selected: Use selection colors?
	:param app: Currently running QApplication. Uses QApplication.instance() by default.
	:return: Returns the SVG as binary data.
	"""
	
	if app is None:
		app = QApplication.instance()
	
	sheet = get_sheet(selected, app)
	
	if hasattr(src, 'read'):
		raw = src.read()
	else:
		path = Path(src)
		with gzip.open(str(path)) if path.suffix == '.svgz' else path.open('rb') as f:
			raw = f.read()
	
	processed = QByteArray()
	reader = QXmlStreamReader(raw)
	writer = QXmlStreamWriter(processed)
	while not reader.atEnd():
		if (
			reader.readNext() == QXmlStreamReader.StartElement and
			reader.qualifiedName() == 'style' and
			reader.attributes().value('id') == 'current-color-scheme'
		):
			writer.writeStartElement('style')
			writer.writeAttributes(reader.attributes())
			writer.writeCharacters(sheet)
			writer.writeEndElement()
			while reader.tokenType() != QXmlStreamReader.EndElement:
				reader.readNext()
		elif reader.tokenType() != QXmlStreamReader.Invalid:
			writer.writeCurrentToken(reader)
	
	processed = bytes(processed)
	if hasattr(dst, 'write'):
		dst.write(processed)
	elif dst is not None:
		with Path(dst).open('wb'):
			dst.write(processed)
	return processed
Exemple #24
0
    def _read_output(self, error=False):
        process = self._process
        if error:
            process.setReadChannel(QProcess.StandardError)
        else:
            process.setReadChannel(QProcess.StandardOutput)

        qba = QByteArray()
        while process.bytesAvailable():
            if error:
                qba += process.readAllStandardError()
            else:
                qba += process.readAllStandardOutput()

        text = str(qba.data(), "utf-8")
        if error:
            self.error_output += text
        else:
            self.output += text

        self.update_actions()
Exemple #25
0
    def restore_state(self, state: QByteArray, version: int = 0) -> bool:
        '''
        Restores the state of this dockmanagers dockwidgets. The version number
        is compared with that stored in state. If they do not match, the
        dockmanager's state is left unchanged, and this function returns false;
        otherwise, the state is restored, and this function returns true.

        Parameters
        ----------
        state : QByteArray
        version : int

        Returns
        -------
        value : bool
        '''
        if not state.startsWith(b'<?xml'):
            if qUncompress is None:
                raise RuntimeError(
                    'Compression utilities unavailable with the '
                    'current qt bindings')
            state = qUncompress(state)

        # Prevent multiple calls as long as state is not restore. This may
        # happen, if QApplication.processEvents() is called somewhere
        if self._mgr.restoring_state:
            return False

        # We hide the complete dock manager here. Restoring the state means
        # that DockWidgets are removed from the DockArea internal stack layout
        # which in turn  means, that each time a widget is removed the stack
        # will show and raise the next available widget which in turn
        # triggers show events for the dock widgets. To avoid this we hide the
        # dock manager. Because there will be no processing of application
        # events until this function is finished, the user will not see this
        # hiding
        is_hidden = self.isHidden()
        if not is_hidden:
            self.hide()

        try:
            self._mgr.restoring_state = True
            self.restoring_state.emit()
            result = self._mgr.restore_state(state, version)
        finally:
            self._mgr.restoring_state = False

        self.state_restored.emit()
        if not is_hidden:
            self.show()

        return result
Exemple #26
0
    def add_widget_totree(self, pixmap_items):

        for item in pixmap_items:
            widget = QtWidgets.QWidget()

            vLayout = QtWidgets.QVBoxLayout()
            label1D = QtWidgets.QLabel()
            bytes = QByteArray(item['node']._v_attrs['pixmap1D'])
            im1 = QtGui.QImage.fromData(bytes)
            a = QtGui.QPixmap.fromImage(im1)
            label1D.setPixmap(a)

            label2D = QtWidgets.QLabel()
            bytes = QByteArray(item['node']._v_attrs['pixmap2D'])
            im2 = QtGui.QImage.fromData(bytes)
            b = QtGui.QPixmap.fromImage(im2)
            label2D.setPixmap(b)

            vLayout.addWidget(label1D)
            vLayout.addwidget(label2D)
            widget.setLayout(vLayout)
            self.ui.h5file_tree.ui.Tree.setItemWidget(item['item'], 1, widget)
Exemple #27
0
 def __init__(self, settings, parent=None):
     super().__init__(parent)
     self.setWindowTitle("Batch processing")
     self.settings = settings
     self.batch_manager = CalculationManager()
     self.file_choose = FileChoose(self.settings, self.batch_manager, self)
     self.calculate_planer = CalculatePlaner(self.settings, self)
     self.addTab(self.calculate_planer, "Prepare workflow")
     self.addTab(self.file_choose, "Input files")
     self.working = False
     with suppress(KeyError):
         geometry = self.settings.get_from_profile("batch_window_geometry")
         self.restoreGeometry(QByteArray.fromHex(bytes(geometry, "ascii")))
def test_read_standard_output(mocker):
    """Test that .read_standard_output() stores the output."""
    before = 'before\n'
    output = 'Αθήνα\n'  # check that we can handle non-ascii
    mock_read = mocker.Mock(return_value=QByteArray(output.encode()))
    mock_process = mocker.Mock(spec=QProcess, readAllStandardOutput=mock_read)
    server = ServerProcess(mock_process, '', output=before)
    serverManager = ServerManager()
    serverManager.servers = [server]

    serverManager.read_server_output(server)

    mock_read.assert_called_once()
    assert server.output == before + output
Exemple #29
0
def str_to_qbytearray(string: str) -> QByteArray:
    """Convert a string to a QbyteArray.

    Used for restoring the state of the main window.

    Parameters
    ----------
    string : str
        State string.
    """
    if len(string) < len(QBYTE_FLAG) or not is_qbyte(string):
        raise ValueError(
            f"Invalid QByte string. QByte strings start with '{QBYTE_FLAG}'")

    return QByteArray.fromBase64(string[len(QBYTE_FLAG):].encode())
Exemple #30
0
    def set_window_settings(self, hexstate, window_size, prefs_dialog_size,
                            pos, is_maximized, is_fullscreen):
        """
        Set window settings Symetric to the 'get_window_settings' accessor.
        """
        main = self.main
        main.setUpdatesEnabled(False)
        self.prefs_dialog_size = QSize(prefs_dialog_size[0],
                                       prefs_dialog_size[1])  # width,height
        main.set_prefs_size(self.prefs_dialog_size)
        self.window_size = QSize(window_size[0],
                                 window_size[1])  # width, height
        self.window_position = QPoint(pos[0], pos[1])  # x,y
        main.setWindowState(Qt.WindowNoState)
        main.resize(self.window_size)
        main.move(self.window_position)

        # Window layout
        if hexstate:
            hexstate_valid = self.main.restoreState(
                QByteArray().fromHex(str(hexstate).encode('utf-8')),
                version=WINDOW_STATE_VERSION
            )

            # Check layout validity. Spyder 4 and below use the version 0
            # state (default), whereas Spyder 5 will use version 1 state.
            # For more info see the version argument for
            # QMainWindow.restoreState:
            # https://doc.qt.io/qt-5/qmainwindow.html#restoreState
            if not hexstate_valid:
                self.main.setUpdatesEnabled(True)
                self.setup_layout(default=True)
                return

        # Is fullscreen?
        if is_fullscreen:
            self.main.setWindowState(Qt.WindowFullScreen)

        # Is maximized?
        if is_fullscreen:
            self._maximized_flag = is_maximized
        elif is_maximized:
            self.main.setWindowState(Qt.WindowMaximized)

        self.main.setUpdatesEnabled(True)
Exemple #31
0
    def load_font(self,
                  prefix,
                  ttf_filename,
                  charmap_filename,
                  directory=None):
        """Loads a font file and the associated charmap

        If `directory` is None, the files will be looked up in ./fonts/

        Arguments
        ---------
        prefix: str
            prefix string to be used when accessing a given font set
        ttf_filename: str
            ttf font filename
        charmap_filename: str
            charmap filename
        directory: str or None, optional
            directory for font and charmap files
        """
        def hook(obj):
            result = {}
            for key in obj:
                result[key] = unichr(int(obj[key], 16))
            return result

        if directory is None:
            directory = os.path.join(
                os.path.dirname(os.path.realpath(__file__)), 'fonts')

        with open(os.path.join(directory, ttf_filename), 'rb') as f:
            font_data = QByteArray(f.read())

        with open(os.path.join(directory, charmap_filename), 'r') as codes:
            self.charmap[prefix] = json.load(codes, object_hook=hook)

        id_ = QFontDatabase.addApplicationFontFromData(font_data)
        loadedFontFamilies = QFontDatabase.applicationFontFamilies(id_)

        if (loadedFontFamilies):
            self.fontname[prefix] = loadedFontFamilies[0]
        else:
            print('Font is empty')
Exemple #32
0
    def __init__(self,
                 settings: ViewSettings,
                 image_view_names: List[str],
                 reload_list=None,
                 parent=None):
        super().__init__(parent)
        self.color_control = ColorControl(settings, image_view_names)
        self.settings = settings
        self.reload_list = reload_list if reload_list is not None else []

        self.develop = DevelopTab()
        self.addTab(self.color_control, "Color control")
        if state_store.develop:
            self.addTab(self.develop, "Develop")
        if self.window() == self:
            with suppress(KeyError):
                geometry = self.settings.get_from_profile(
                    "advanced_window_geometry")
                self.restoreGeometry(
                    QByteArray.fromHex(bytes(geometry, "ascii")))