示例#1
0
    def _start_worker(self, job_input):
        self.worker_queue = Queue()
        self.worker_process = Process(target=predict,
                                      args=(self.worker_queue, job_input,
                                            self.tr))
        self.worker_process.start()

        while True:
            msg = self.worker_queue.get()
            QGuiApplication.instance().processEvents()
            if isinstance(msg, dict) and 'status' in msg and (
                    msg['status'] == 'done' or msg['status'] == 'stop'):
                break
            else:
                self.msg_from_job.emit(msg)
示例#2
0
文件: api.py 项目: schoentoon/runekit
    def __init__(self, api, **kwargs):
        super().__init__(**kwargs)
        self.api = api

        gui_app = QGuiApplication.instance()

        gui_app.screenAdded.connect(self.on_screen_update)
        gui_app.screenRemoved.connect(self.on_screen_update)

        self.api.app.game_instance.focusChanged.connect(
            self.on_game_active_change)
        self.api.app.game_instance.positionChanged.connect(
            self.on_game_position_change)
        self.api.app.game_instance.scalingChanged.connect(
            self.on_game_scaling_change)
        self.api.app.game_instance.alt1_pressed.connect(self.on_alt1)
        def setUp(self):
            '''Creates the QGuiApplication instance'''

            # Simple way of making instance a singleton
            super(UsesQGuiApplication, self).setUp()
            self.app = QGuiApplication.instance() or QGuiApplication([])
 def interrupter(self):
     if not self.interrupted:
         self.interrupted = True
         self.incubationShouldContinue.set(False)
         self.test.assertEqual(self.incubationShouldContinue.get(), False)
         QTimer.singleShot(0, QGuiApplication.instance().quit)
示例#5
0
from library.viewer import Viewer
from library.worker_interface import WorkerInterface
from library.worker_manager import WorkerManager


@Slot()
def update_app_language():
    app.installTranslator(translator.translator)
    engine.retranslate()


if __name__ == '__main__':
    # os.environ['QT_QUICK_CONTROLS_CONF'] = 'resources/qtquickcontrols2.conf'

    app = QGuiApplication(sys.argv)
    app.instance().thread().setObjectName('MainThread')

    worker_manager = WorkerManager()
    worker_interface_thread = QThread()
    worker_interface_thread.setObjectName("WorkerInterfaceThread")
    worker_interface = WorkerInterface(start_signal=worker_manager.start,
                                       stop_signal=worker_manager.stop)
    worker_interface.msg_from_job.connect(worker_manager.receive_msg)
    worker_interface.moveToThread(worker_interface_thread)
    worker_interface_thread.start()

    viewer = Viewer()
    translator = Translator()
    translator.updateAppLanguage.connect(update_app_language)

    qml_file = os.path.abspath(
示例#6
0
def svg_to_outlines(root, width_mm=None, height_mm=None, pixels_per_mm=5.0):
    """
    Given an SVG as a Python ElementTree, return a set of straight line
    segments which approximate the outlines in that SVG when rendered.

    Occlusion is not accounted for in the returned list of outlines. Even if
    one shape is completely occluded by another, both of their outlines will be
    reported. Simillarly, overlapping lines will also be passed through.

    .. note::

        This function internally uses the QSvg library from Qt to render the
        provided SVG to a special painting backend which captures the output
        lines. As a consequence, SVG feature support is as good or as bad as
        that library. QSvg is generally regarded as a high quality and
        relatively complete SVG implementation and so most SVG features should
        be supported.

    .. note::

        Due to its internal use of Qt, a PySide2.QtGui.QGuiApplication will be
        created if one has not already been created. Non-Qt users and most Qt
        users should not be affected by this.

    Parameters
    ----------
    root : ElementTree
        The SVG whose outlines should be extracted.
    width_mm, height_mm : float or None
        The page size to render the SVG at (in milimeters). If omitted, this
        will be determined automatically from the SVG's width and height
        attributes. These arguments are mandatory for SVGs lacking these
        attributes.
    pixels_per_mm : float
        Curved outlines will be approximated by straight lines in the output.
        This parameter controls how exactly curves will be approximated.
        Specifically, the curve approximation will be at least fine enough for
        rasterised versions of the lines to 'look right' at the specified pixel
        density.

    Returns
    -------
    [((r, g, b, a) or None, width, [(x, y), ...]), ...]
        A list of polylines described by (colour, line) pairs.

        The 'colour' values define the colour used to draw the line (if a solid
        colour was used) or None (if a gradient or patterned stroke was used).
        Colours are given as four-tuples in RGBA order with values from 0.0 to
        1.0.

        The 'width' value gives the line width used to draw the line (given in
        mm). If the shape being drawn has a non-uniform scaling applied, this
        value may not be meaningful and its actual value should be considered
        undefined.

        The 'line' part of each tuple defines the outline as a series of (x, y)
        coordinates (given in mm) which describe a continuous polyline. These
        polylines may be considered open. Closed lines in the input SVG will
        result in polylines where the first and last coordinate are identical.
        Lines may go beyond the bounds of the designated page size (as in the
        input SVG).
    """
    # This method internally uses various parts of Qt which require that a Qt
    # application exists. If one does not exist, one will be created.
    if QGuiApplication.instance() is None:
        QGuiApplication()

    # Determine the page size from the document if necessary
    if width_mm is None or height_mm is None:
        width_mm, height_mm = get_svg_page_size(root)

    # Load the SVG into QSvg
    xml_stream_reader = QXmlStreamReader()
    xml_stream_reader.addData(ElementTree.tostring(root, "unicode"))
    svg_renderer = QSvgRenderer()
    svg_renderer.load(xml_stream_reader)

    # Paint the SVG into the OutlinePaintDevice which will capture the set of
    # line segments which make up the SVG as rendered.
    outline_paint_device = OutlinePaintDevice(width_mm, height_mm,
                                              pixels_per_mm)
    painter = QPainter(outline_paint_device)
    try:
        svg_renderer.render(painter)
    finally:
        painter.end()

    return outline_paint_device.getOutlines()