Beispiel #1
0
 def test_matches(self):
     mydomain = GLib.quark_from_string('mydomain')
     notmydomain = GLib.quark_from_string('notmydomain')
     e = GLib.Error('test message', 'mydomain', 42)
     self.assertTrue(e.matches(mydomain, 42))
     self.assertFalse(e.matches(notmydomain, 42))
     self.assertFalse(e.matches(mydomain, 40))
Beispiel #2
0
 def test_matches(self):
     mydomain = GLib.quark_from_string('mydomain')
     notmydomain = GLib.quark_from_string('notmydomain')
     e = GLib.Error('test message', 'mydomain', 42)
     self.assertTrue(e.matches(mydomain, 42))
     self.assertFalse(e.matches(notmydomain, 42))
     self.assertFalse(e.matches(mydomain, 40))
Beispiel #3
0
def select_clips(scenario, action):
    should_select = True
    timeline = get_pipeline(scenario).props.timeline
    clip = timeline.get_element(action.structure["clip-name"])

    if clip is None:
        scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                               "Could not find container: %s"
                               % action.structure["container-name"])

        return 1

    mode = action.structure["mode"]
    if mode:
        mode = mode.lower()

    if mode == "ctrl":
        if clip.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
            should_select = False

        event = Event(Gdk.EventType.KEY_PRESS, keyval=Gdk.KEY_Control_L)
        timeline.ui.get_parent().do_key_press_event(event)

    event = Event(Gdk.EventType.BUTTON_RELEASE, button=1)
    with mock.patch.object(Gtk, "get_event_widget") as get_event_widget:
        get_event_widget.return_value = clip.ui
        clip.ui._button_release_event_cb(None, event)

    selection = action.structure["selection"]
    if not selection:
        if should_select:
            if not clip.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
                scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                       "Clip %s should be selected but is not"
                                       % clip.get_name())
        elif clip.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
            scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                   "Clip %s should be UNselected but is not"
                                   % clip.get_name())
    else:
        for l in timeline.get_layers():
            for c in l.get_clips():
                if c.get_name() in selection:
                    if not c.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
                        scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                               "Clip %s should be selected (as defined in selection %s)"
                                               " but is not" % (selection, clip.get_name()))
                else:
                    if c.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
                        scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                               "Clip %s should NOT be selected (as defined in selection %s)"
                                               " but it is" % (selection, clip.get_name()))

    if mode == "ctrl":
        event = Event(Gdk.EventType.KEY_RELEASE, keyval=Gdk.KEY_Control_L)
        timeline.ui.get_parent().do_key_release_event(event)

    return 1
Beispiel #4
0
def select_clips(scenario, action):
    should_select = True
    timeline = scenario.pipeline.props.timeline
    clip = timeline.get_element(action.structure["clip-name"])

    if clip is None:
        scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                               "Could not find container: %s"
                               % action.structure["container-name"])

        return 1

    mode = action.structure["mode"]
    if mode:
        mode = mode.lower()

    if mode == "ctrl":
        if clip.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
            should_select = False

        timeline.ui.sendFakeEvent(Event(event_type=Gdk.EventType.KEY_PRESS,
                                        keyval=Gdk.KEY_Control_L))

    event = Gdk.EventButton.new(Gdk.EventType.BUTTON_RELEASE)
    clip.ui.sendFakeEvent(event, clip.ui)

    selection = action.structure["selection"]
    if not selection:
        if should_select:
            if not clip.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
                scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                       "Clip %s should be selected but is not"
                                       % clip.get_name())
        elif clip.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
            scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                   "Clip %s should be UNselected but is not"
                                   % clip.get_name())
    else:
        for l in timeline.get_layers():
            for c in l.get_clips():
                if c.get_name() in selection:
                    if not c.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
                        scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                               "Clip %s should be selected (as defined in selection %s)"
                                               " but is not" % (selection, clip.get_name()))
                else:
                    if c.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
                        scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                               "Clip %s should NOT be selected (as defined in selection %s)"
                                               " but it is" % (selection, clip.get_name()))

    if mode == "ctrl":
        timeline.ui.sendFakeEvent(Event(Gdk.EventType.KEY_RELEASE, keyval=Gdk.KEY_Control_L))

    return 1
Beispiel #5
0
def select_clips(scenario, action):
    should_select = True
    timeline = scenario.pipeline.props.timeline
    clip = timeline.get_element(action.structure["clip-name"])

    if clip is None:
        scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                               "Could not find container: %s"
                               % action.structure["container-name"])

        return 1

    mode = action.structure["mode"]
    if mode:
        mode = mode.lower()

    if mode == "ctrl":
        if clip.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
            should_select = False

        timeline.ui.sendFakeEvent(Event(event_type=Gdk.EventType.KEY_PRESS,
                                        keyval=Gdk.KEY_Control_L))

    event = Gdk.EventButton.new(Gdk.EventType.BUTTON_RELEASE)
    clip.ui.sendFakeEvent(event, clip.ui)

    selection = action.structure["selection"]
    if not selection:
        if should_select:
            if not clip.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
                scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                       "Clip %s should be selected but is not"
                                       % clip.get_name())
        elif clip.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
            scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                   "Clip %s should be UNselected but is not"
                                   % clip.get_name())
    else:
        for l in timeline.get_layers():
            for c in l.get_clips():
                if c.get_name() in selection:
                    if not c.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
                        scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                               "Clip %s should be selected (as defined in selection %s)"
                                               " but is not" % (selection, clip.get_name()))
                else:
                    if c.ui.get_state_flags() & Gtk.StateFlags.SELECTED:
                        scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                               "Clip %s should NOT be selected (as defined in selection %s)"
                                               " but it is" % (selection, clip.get_name()))

    if mode == "ctrl":
        timeline.ui.sendFakeEvent(Event(Gdk.EventType.KEY_RELEASE, keyval=Gdk.KEY_Control_L))

    return 1
Beispiel #6
0
    def _collect_external_data(self, path, json_data):
        modules = json_data.get("modules")
        if modules is None:
            return
        elif not isinstance(modules, list):
            log.error('"modules" in %s is not a list', path)
            return
        for module in modules:
            if isinstance(module, str):
                module_path = os.path.join(os.path.dirname(path), module)
                log.info(
                    "Loading modules from %s",
                    os.path.relpath(module_path, self._root_manifest_dir),
                )

                try:
                    module = self._read_manifest(module_path)
                except GLib.Error as err:
                    if err.matches(
                            GLib.quark_from_string("g-file-error-quark"), 4):
                        log.warning("Referenced file not found: %s", module)
                        continue

                    raise
                except FileNotFoundError:
                    log.warning("Referenced file not found: %s", module)
                    continue
            else:
                module_path = path

            self._collect_external_data(path=module_path, json_data=module)

            sources = module.get("sources", [])
            external_sources = [
                s for s in sources if _external_source_filter(path, s)
            ]

            external_data = self._external_data.setdefault(module_path, [])
            datas = ExternalDataSource.from_sources(module_path, sources)
            external_data.extend(datas)

            for external_source in external_sources:
                external_source_path = os.path.join(os.path.dirname(path),
                                                    external_source)
                log.info(
                    "Loading sources from %s",
                    os.path.relpath(external_source_path,
                                    self._root_manifest_dir),
                )
                external_manifest = self._read_manifest(external_source_path)
                if isinstance(external_manifest, list):
                    external_source_data = external_manifest
                elif isinstance(external_manifest, dict):
                    external_source_data = [external_manifest]
                else:
                    raise TypeError(
                        f"Invalid data type in {external_source_path}")
                datas = ExternalDataSource.from_sources(
                    external_source_path, external_source_data)
                self._external_data[external_source_path] = datas
Beispiel #7
0
def archive_open(path):
    """ Opens the archive @path as a GFile representing it as a directory.
    @path must be a local path (for the moment). """

    # This is crazy, but it's the only way to get it working:
    # 1. get a URI with special characters escaped.  This makes sense.
    # 2. escape that result, so it can be part of the archive:// URI.  More tricky,
    #    but still makes some sense.
    # 3. escape the URI a *3rd* time, getting e.g. "/" to %253A.  Things that got
    #    escaped in step 1 are then escaped 3 times (e.g. "é" becomes %2525A9).
    #    GOD WHY!??
    # 4. make all this an archive:// URI
    uri = GLib.filename_to_uri(path)
    for i in range(2):  # WTF, seriously!??
        uri = GLib.uri_escape_string(uri, None, False)
    uri = 'archive://' + uri
    print(uri)

    zf = Gio.File.new_for_uri(uri)

    zf._was_already_mounted = False
    try:
        func = synchronize_async(
            type(zf).mount_enclosing_volume,
            type(zf).mount_enclosing_volume_finish)
        func(zf, Gio.MountMountFlags.NONE, None, None)
    except GLib.Error as ex:
        if ex.matches(GLib.quark_from_string('g-io-error-quark'),
                      Gio.IOErrorEnum.ALREADY_MOUNTED):
            zf._was_already_mounted = True
        else:
            raise

    return zf
Beispiel #8
0
 def test_no_executable(self):
     job = XmiMsim.Job.new(
         os.environ["XMIMSIM_NON_EXISTENT_EXEC"],
         "non-existent-file.xmsi",
         self.options,
         extra_options=type(self).EXTRA_OPTIONS
         )
     self.assertIsNotNone(job)
     try:
         logging.debug("command: {}".format(job.get_command()))
         job.start()
         self.fail("Starting a job without existent executable must throw an exception!")
     except GLib.Error as err:
         self.assertEqual(GLib.quark_from_string(err.domain), GLib.spawn_error_quark())
         self.assertTrue(err.code == GLib.SpawnError.NOENT or err.code == GLib.SpawnError.FAILED)
     self.assertFalse(job.is_running())
     self.assertFalse(job.is_suspended())
     self.assertFalse(job.has_finished())
     self.assertFalse(job.was_successful())
     try:
         job.stop()
     except GLib.Error as err:
         self.assertTrue(err.matches(XmiMsim.JobError.quark(), XmiMsim.JobError.UNAVAILABLE))
     try:
         job.suspend()
     except GLib.Error as err:
         self.assertTrue(err.matches(XmiMsim.JobError.quark(), XmiMsim.JobError.UNAVAILABLE))
     try:
         job.resume()
     except GLib.Error as err:
         self.assertTrue(err.matches(XmiMsim.JobError.quark(), XmiMsim.JobError.UNAVAILABLE))
Beispiel #9
0
def _releaseButtonIfNeeded(scenario, action, timeline, container, edge, layer_prio,
                           position, y):
    try:
        next_actions = scenario.get_actions()
        for next_action in next_actions[1:]:
            if next_action.type not in ["wait", "add-layer"]:
                break
    except KeyError:
        return

    need_release = True
    if next_action and next_action.type == "edit-container":
        edge = get_edge(next_action.structure)

        if edge == scenario.last_edge:
            need_release = False

    if next_action is None or need_release:
        scenario.dragging = False
        event = Gdk.EventButton.new(Gdk.EventType.BUTTON_RELEASE)
        event.button = 1
        event.x = timelineUtils.Zoomable.nsToPixelAccurate(position)
        event.y = y
        container.ui.sendFakeEvent(event, container.ui)

        if layer_prio > 0 and container.get_layer().get_priority() != layer_prio:
            scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                   "Resulting clip priority: %s"
                                   " is not the same as the wanted one: %s"
                                   % (container.get_layer().get_priority(),
                                      layer_prio))

        cleanEditModes(timeline, scenario)
Beispiel #10
0
def _releaseButtonIfNeeded(scenario, action, timeline, container, edge, layer_prio,
                           position, y):
    try:
        next_actions = scenario.get_actions()
        for next_action in next_actions[1:]:
            if next_action.type not in ["wait", "add-layer"]:
                break
    except KeyError:
        return

    need_release = True
    if next_action and next_action.type == "edit-container":
        edge = get_edge(next_action.structure)

        if edge == scenario.last_edge:
            need_release = False

    if next_action is None or need_release:
        scenario.dragging = False
        x = Zoomable.nsToPixelAccurate(position)
        event = Event(Gdk.EventType.BUTTON_RELEASE, button=1, x=x, y=y)
        with mock.patch.object(Gtk, "get_event_widget") as get_event_widget:
            get_event_widget.return_value = container.ui
            container.ui._button_release_event_cb(None, event)

        if layer_prio > 0 and container.get_layer().get_priority() != layer_prio:
            scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                   "Resulting clip priority: %s"
                                   " is not the same as the wanted one: %s"
                                   % (container.get_layer().get_priority(),
                                      layer_prio))

        cleanEditModes(timeline, scenario)
Beispiel #11
0
        def _windowOpenedCb(self, screen, window):
            global monitor

            if window.get_name() == 'renderer' and monitor:
                monitor.report_simple(GLib.quark_from_string("pitivi::wrong-window-creation"),
                                      "New window created by the sink,"
                                      " that should not happen")
Beispiel #12
0
def _releaseButtonIfNeeded(scenario, action, timeline, container, edge, layer_prio,
                           position, y):
    try:
        next_actions = scenario.get_actions()
        for next_action in next_actions[1:]:
            if next_action.type not in ["wait", "add-layer"]:
                break
    except KeyError:
        return

    need_release = True
    if next_action and next_action.type == "edit-container":
        edge = get_edge(next_action.structure)

        if edge == scenario.last_edge:
            need_release = False

    if next_action is None or need_release:
        scenario.dragging = False
        event = Gdk.EventButton.new(Gdk.EventType.BUTTON_RELEASE)
        event.button = 1
        event.x = timelineUtils.Zoomable.nsToPixelAccurate(position)
        event.y = y
        container.ui.sendFakeEvent(event, container.ui)

        if layer_prio > 0 and container.get_layer().get_priority() != layer_prio:
            scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                                   "Resulting clip priority: %s"
                                   " is not the same as the wanted one: %s"
                                   % (container.get_layer().get_priority(),
                                      layer_prio))

        cleanEditModes(timeline, scenario)
Beispiel #13
0
 def _on_sink_change_notify(self, sink, param):
     if self.selected_sink != sink.props.current_device:
         domain = GLib.quark_from_string("g-exaile-error")
         err = GLib.Error.new_literal(domain, "Audio device disconnected",
                                      0)
         self.playbin.get_bus().post(
             Gst.Message.new_error(None, err, "Disconnected"))
         self.logger.info("Detected device disconnect, stopping playback")
Beispiel #14
0
 def _on_sink_change_notify(self, sink, param):
     if self.selected_sink != sink.props.current_device:
         domain = GLib.quark_from_string("g-exaile-error")
         err = GLib.Error.new_literal(domain, "Audio device disconnected", 0)
         self.playbin.get_bus().post(
             Gst.Message.new_error(None, err, "Disconnected")
         )
         self.logger.info("Detected device disconnect, stopping playback")
Beispiel #15
0
		def return_exception(exc):
			if isinstance(exc, GLib.GError):
				# the much simpler invocation.return_gerror(exc) raises TypeError.
				invocation.return_error_literal(GLib.quark_from_string(exc.domain), exc.code, exc.message)
			else:
				# TODO Think of a better way to translate Python exception types to DBus error types.
				e_type = type(exc).__name__
				if "." not in e_type:
					e_type = "unknown." + e_type
				invocation.return_dbus_error(e_type, str(exc))
Beispiel #16
0
 def checkWrongWindow(self):
     try:
         windows = subprocess.check_output(["xwininfo", "-tree", "-root"]).decode(locale.getdefaultlocale()[1])
         for w in windows.split('\n'):
             if "OpenGL renderer" in w and w.startswith("     0x"):
                 monitor.report_simple(GLib.quark_from_string("pitivi::wrong-window-creation"),
                                       "New window created by the sink,"
                                       " that should not happen, (current windows: %s)"
                                       % windows)
                 break
     except (subprocess.CalledProcessError, FileNotFoundError):
         pass
Beispiel #17
0
def position_changed_cb(pipeline, position, scenario, action, wanted_position):
    if pipeline._busy_async:
        return

    if pipeline._next_seek:
        return

    print(str(wanted_position), str(position))
    if wanted_position != position:
        scenario.report_simple(
            GLib.quark_from_string("scenario::execution-error"),
            "Position after seek (%s) does not match wanted one %s" %
            (Gst.TIME_ARGS(position), Gst.TIME_ARGS(wanted_position)))

    pipeline.disconnect_by_func(position_changed_cb)
    action.set_done()
Beispiel #18
0
def positionChangedCb(pipeline, position, scenario, action,
                      wanted_position):
    if pipeline._busy_async:
        return

    if pipeline._next_seek:
        return

    print(str(wanted_position), str(position))
    if wanted_position != position:
        scenario.report_simple(GLib.quark_from_string(
            "scenario::execution-error"),
            "Position after seek (%s) does not match wanted "
            "one %s" % (Gst.TIME_ARGS(position),
                        Gst.TIME_ARGS(wanted_position)))

    pipeline.disconnect_by_func(positionChangedCb)
    action.set_done()
Beispiel #19
0
 def makeGLibError(status, message=""):
     """
     Make a GLib error.
     It carries more information into a result?
     Gimp.Procedure.new_return_values() takes one.
     """
     FuResult.logger.info(f"makeGLibError for status: {status}")
     if status == Gimp.PDBStatusType.SUCCESS:
         # ??? creates an empty but valid GLib.Error ????
         result = GLib.Error()
     else:
         # Seems wierd that a "literal" is a Glib.Error
         quark = GLib.quark_from_string("GimpFu")
         result = GLib.Error.new_literal(quark, message, 0)
     assert isinstance(result, GLib.Error)
     # a GLib.Error seems to have a good repr() method
     # i.e. prints a tuple (domain string, message string, code numeric )
     FuResult.logger.info(f"makeGLibError result: {result}")
     return result
Beispiel #20
0
# SPDX-License-Identifier: GPL-3.0-only
from __future__ import annotations

import io
import logging
from pathlib import Path

from gi.repository import Gio, GLib, GObject
from pykeepass import PyKeePass

import gsecrets.config_manager as config
from gsecrets.safe_element import SafeEntry, SafeGroup

QUARK = GLib.quark_from_string("secrets")


class DatabaseManager(GObject.Object):
    # pylint: disable=too-many-public-methods
    # pylint: disable=too-many-instance-attributes

    """Implements database functionality that is independent of the UI

    Useful attributes:
     .path: str containing the filepath of the database
     .is_dirty: bool telling whether the database is in a dirty state

    Group objects are of type `pykeepass.group.Group`
    Entry objects are of type `pykeepass.entry.Entry`
    Instances of both have useful attributes:
    .uuid: a `uuid.UUID` object
    """
Beispiel #21
0
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import gi
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gio
from gi.repository import Gtk
gi.require_version('TelepathyGLib', '0.12')
from gi.repository import TelepathyGLib as Tp
import sys

GObject.threads_init()

# not available via g-i
USER_ACTION_TIME_NOT_USER_ACTION = 0
ACCOUNT_MANAGER_FEATURE_CORE = GLib.quark_from_string(
    'tp-account-manager-feature-core')

class Dialler(Gtk.Application):

    def __init__(self):
        Gtk.Application.__init__(self,
                application_id='im.telepathy.TpGLib.Example.PythonDialler',
                flags=Gio.ApplicationFlags.NON_UNIQUE)

        self.dbus = Tp.DBusDaemon.dup()
        self.am = Tp.AccountManager.dup()

        self.accounts = Gtk.ListStore(str, object)
        self.potential_handlers = set()
        self.handlers = Gtk.ListStore(str, str)
Beispiel #22
0
def init():
    global has_validate
    try:
        from gi.repository import GstValidate
        GstValidate.init()
        has_validate = GES.validate_register_action_types()
        GstValidate.register_action_type("stop", "pitivi",
                                         stop, None,
                                         "Pitivi override for the stop action",
                                         GstValidate.ActionTypeFlags.NONE)

        GstValidate.register_action_type("seek", "pitivi",
                                         seek, None,
                                         "Pitivi override for the seek action",
                                         GstValidate.ActionTypeFlags.NONE)

        GstValidate.register_action_type("pause", "pitivi",
                                         set_state, None,
                                         "Pitivi override for the pause action",
                                         GstValidate.ActionTypeFlags.NONE)

        GstValidate.register_action_type("play", "pitivi",
                                         set_state, None,
                                         "Pitivi override for the pause action",
                                         GstValidate.ActionTypeFlags.NONE)

        GstValidate.register_action_type("set-state", "pitivi",
                                         set_state, None,
                                         "Pitivi override for the set-state action",
                                         GstValidate.ActionTypeFlags.NONE)

        GstValidate.register_action_type("edit-container", "pitivi",
                                         editContainer, None,
                                         "Start dragging a clip in the timeline",
                                         GstValidate.ActionTypeFlags.NONE)

        GstValidate.register_action_type("split-clip", "pitivi",
                                         split_clip, None,
                                         "Split a clip",
                                         GstValidate.ActionTypeFlags.NONE)

        GstValidate.register_action_type("add-layer", "pitivi",
                                         add_layer, None,
                                         "Add layer",
                                         GstValidate.ActionTypeFlags.NONE)

        GstValidate.register_action_type("remove-clip", "pitivi",
                                         remove_clip, None,
                                         "Remove clip",
                                         GstValidate.ActionTypeFlags.NONE)
        GstValidate.register_action_type("select-clips", "pitivi",
                                         select_clips, [Parametter("clip-name",
                                                                   "The name of the clip to select",
                                                                   True, None, "str")],
                                         "Select clips",
                                         GstValidate.ActionTypeFlags.NONE)

        for z in ["zoom-fit", "zoom-out", "zoom-in"]:
            GstValidate.register_action_type(z, "pitivi", zoom, None, z,
                                             GstValidate.ActionTypeFlags.NO_EXECUTION_NOT_FATAL)
        GstValidate.register_action_type('set-zoom-level', "pitivi", setZoomLevel, None, z,
                                         GstValidate.ActionTypeFlags.NO_EXECUTION_NOT_FATAL)

        Gst.info("Adding pitivi::wrong-window-creation")
        GstValidate.Issue.register(GstValidate.Issue.new(
                                   GLib.quark_from_string("pitivi::wrong-window-creation"),
                                   "A new window for the sink has wrongly been created",
                                   "All sink should display their images in an embedded "
                                   "widget and thus not create a new window",
                                   GstValidate.ReportLevel.CRITICAL))
        return True
    except ImportError:
        has_validate = False
        return False
Beispiel #23
0
 def test_new_literal(self):
     mydomain = GLib.quark_from_string('mydomain')
     e = GLib.Error.new_literal(mydomain, 'test message', 42)
     self.assertEqual(e.message, 'test message')
     self.assertEqual(e.domain, 'mydomain')
     self.assertEqual(e.code, 42)
Beispiel #24
0
def editContainer(scenario, action):
    timeline = get_pipeline(scenario).props.timeline
    container = timeline.get_element(action.structure["container-name"])

    if container is None:
        for layer in timeline.get_layers():
            for clip in layer.get_clips():
                Gst.info("Exisiting clip: %s" % clip.get_name())

        scenario.report_simple(GLib.quark_from_string("scenario::execution-error"),
                               "Could not find container: %s"
                               % action.structure["container-name"])

        return 1

    res, position = GstValidate.action_get_clocktime(scenario, action, "position")
    layer_prio = action.structure["new-layer-priority"]

    if res is False:
        return 0

    edge = get_edge(action.structure)
    container_ui = container.ui

    setEditingMode(timeline, scenario, action)

    y = 21 - container_ui.translate_coordinates(timeline.ui, 0, 0)[1]

    if container.get_layer().get_priority() != layer_prio and layer_prio != -1:
        try:
            layer = timeline.get_layers()[layer_prio]
            Gst.info("Y is: %s Realized?? %s Priori: %s layer prio: %s"
                     % (layer.ui.get_allocation().y,
                        container_ui.get_realized(),
                        container.get_layer().get_priority(),
                        layer_prio))
            y = layer.ui.get_allocation().y - container_ui.translate_coordinates(timeline.ui, 0, 0)[1]
            if y < 0:
                y += 21
            elif y > 0:
                y -= 21
        except IndexError:
            if layer_prio == -1:
                y = -5
            else:
                layer = timeline.get_layers()[-1]
                alloc = layer.ui.get_allocation()
                y = alloc.y + alloc.height + 10 - container_ui.translate_coordinates(timeline.ui, 0, 0)[1]

    if not hasattr(scenario, "last_edge"):
        scenario.last_edge = edge

    if not hasattr(scenario, "dragging") or scenario.dragging is False \
            or scenario.last_edge != edge:
        event_widget = container.ui
        if isinstance(container, GES.SourceClip):
            if edge == GES.Edge.EDGE_START:
                event_widget = container.ui.leftHandle
            elif edge == GES.Edge.EDGE_END:
                event_widget = container.ui.rightHandle

        scenario.dragging = True
        event = Event(Gdk.EventType.BUTTON_PRESS, button=1, y=y)
        with mock.patch.object(Gtk, "get_event_widget") as get_event_widget:
            get_event_widget.return_value = event_widget
            timeline.ui._button_press_event_cb(event_widget, event)

    event = Event(Gdk.EventType.MOTION_NOTIFY, button=1,
                  x=Zoomable.nsToPixelAccurate(position) -
                  container_ui.translate_coordinates(timeline.ui.layout.layers_vbox, 0, 0)[0],
                  y=y, state=Gdk.ModifierType.BUTTON1_MASK)
    with mock.patch.object(Gtk, "get_event_widget") as get_event_widget:
        get_event_widget.return_value = container.ui
        timeline.ui._motion_notify_event_cb(None, event)

    GstValidate.print_action(action, "Editing %s to %s in %s mode, edge: %s "
                             "with new layer prio: %d\n" % (action.structure["container-name"],
                                                            Gst.TIME_ARGS(position),
                                                            scenario.last_mode,
                                                            edge,
                                                            layer_prio))

    _releaseButtonIfNeeded(scenario, action, timeline, container, edge, layer_prio,
                           position, y)
    scenario.last_edge = edge

    return 1
Beispiel #25
0
import gi
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gio
from gi.repository import Gtk

gi.require_version('TelepathyGLib', '0.12')
from gi.repository import TelepathyGLib as Tp
import sys

GObject.threads_init()

# not available via g-i
USER_ACTION_TIME_NOT_USER_ACTION = 0
ACCOUNT_MANAGER_FEATURE_CORE = GLib.quark_from_string(
    'tp-account-manager-feature-core')


class Dialler(Gtk.Application):
    def __init__(self):
        Gtk.Application.__init__(
            self,
            application_id='im.telepathy.TpGLib.Example.PythonDialler',
            flags=Gio.ApplicationFlags.NON_UNIQUE)

        self.dbus = Tp.DBusDaemon.dup()
        self.am = Tp.AccountManager.dup()

        self.accounts = Gtk.ListStore(str, object)
        self.potential_handlers = set()
        self.handlers = Gtk.ListStore(str, str)
Beispiel #26
0
    def _collect_external_data(self, path, json_data):
        modules = json_data.get('modules')
        if modules is None:
            return
        elif not isinstance(modules, list):
            log.warning("\"modules\" in %s is not a list", path)
            return
        for module in modules:
            if isinstance(module, str):
                module_path = os.path.join(os.path.dirname(path), module)
                log.debug("Loading modules from %s", module_path)

                try:
                    module = self._read_manifest(module_path)
                except GLib.Error as err:
                    if err.matches(
                            GLib.quark_from_string('g-file-error-quark'), 4):
                        log.info("Referenced file not found: %s", module)
                        continue

                    raise
                except FileNotFoundError:
                    log.info("Referenced file not found: %s", module)
                    continue
            else:
                module_path = path

            self._collect_external_data(path=module_path, json_data=module)

            module_name = module.get('name')
            module_data = ModuleData(module_name, module_path, module)

            sources = module.get('sources', [])
            external_sources = [
                source for source in sources if isinstance(source, str)
            ]
            for source in external_sources:
                source_path = os.path.join(os.path.dirname(path), source)
                source_stat = os.stat(source_path)
                if source_stat.st_size > 102400:
                    log.info(
                        "External source file is over 100KB, skipping: %s",
                        source)
                    external_sources.remove(source)

            external_data = self._external_data.setdefault(module_path, [])
            datas = ExternalDataSource.from_sources(module_path, sources)
            external_data.extend(datas)
            module_data.external_data.extend(datas)

            for external_source in external_sources:
                external_source_path = os.path.join(os.path.dirname(path),
                                                    external_source)
                external_source_data = self._read_manifest(
                    external_source_path)
                datas = ExternalDataSource.from_sources(
                    external_source_path, external_source_data)
                self._external_data[external_source_path] = datas
                module_data.external_data.extend(datas)

            self._modules_data[module_name] = module_data
Beispiel #27
0
 def test_new_literal(self):
     mydomain = GLib.quark_from_string('mydomain')
     e = GLib.Error.new_literal(mydomain, 'test message', 42)
     self.assertEqual(e.message, 'test message')
     self.assertEqual(e.domain, 'mydomain')
     self.assertEqual(e.code, 42)
 def set_roi_type(self, new_type: str) -> None:
     self.roi_type = GLib.quark_from_string(new_type)