def show_user_manual(page=None): """Displays the user manual. First tries with Yelp and then tries opening the online version. Args: page (Optional[str]): A page ID to display instead of the index page, for contextual help. """ def get_page_uri(uri, page): if page: if uri.startswith("http://"): return "%s/%s.html" % (uri, page) if uri.startswith("ghelp://"): return "%s/%s" % (uri, page) if uri.startswith("help:"): return "%s/%s" % (uri, page) return uri time_now = int(time.time()) uris = (APPMANUALURL_OFFLINE, APPMANUALURL_ONLINE) for uri in uris: page_uri = get_page_uri(uri, page) try: Gtk.show_uri(None, page_uri, time_now) return except GLib.Error as e: log.info("utils", "Failed loading URI %s: %s", uri, e) # Last try calling yelp directly (used in flatpak while we do # not have a portal to access system wild apps) page_uri = get_page_uri(APPMANUALURL_OFFLINE, page) try: subprocess.Popen(["yelp", page_uri]) except FileNotFoundError as e: log.warning("utils", "Failed loading %s: %s", page_uri, e) dialog = Gtk.MessageDialog( modal=True, message_type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, text=_("Failed to open the user manual." " Make sure to have either the `yelp` GNOME " " documentation viewer or a web browser" " installed")) dialog.run() dialog.destroy()
def show_user_manual(page=None): """ Display the user manual with Yelp. Optional: for contextual help, a page ID can be specified. """ time_now = int(time.time()) if "APPDIR" in os.environ: uris = (APPMANUALURL_ONLINE,) else: uris = (APPMANUALURL_OFFLINE, APPMANUALURL_ONLINE) for uri in uris: if page is not None: uri += "#" + page try: Gtk.show_uri(None, uri, time_now) return except Exception as e: log.debug("utils", "Failed loading URI %s: %s", uri, e) continue log.warning("utils", "Failed loading URIs")
def show_user_manual(page=None): """ Display the user manual with Yelp. Optional: for contextual help, a page ID can be specified. """ time_now = int(time.time()) if "APPDIR" in os.environ: uris = (APPMANUALURL_ONLINE, ) else: uris = (APPMANUALURL_OFFLINE, APPMANUALURL_ONLINE) for uri in uris: if page is not None: uri += "#" + page try: Gtk.show_uri(None, uri, time_now) return except Exception as e: log.debug("utils", "Failed loading URI %s: %s", uri, e) continue log.warning("utils", "Failed loading URIs")
def show_user_manual(page=None): """Displays the user manual. First tries with Yelp and then tries opening the online version. Args: page (Optional[str]): A page ID to display instead of the index page, for contextual help. """ def get_page_uri(uri, page): if page is not None: return uri + "#" + page return uri time_now = int(time.time()) uris = (APPMANUALURL_OFFLINE, APPMANUALURL_ONLINE) for uri in uris: try: Gtk.show_uri(None, get_page_uri(uri, page), time_now) return except Exception as e: log.info("utils", "Failed loading URI %s: %s", uri, e) continue try: # Last try calling yelp directly (used in flatpak while we do # not have a portal to access system wild apps) subprocess.Popen(["yelp", get_page_uri(APPMANUALURL_OFFLINE, page)]) except FileNotFoundError: log.warning("utils", "Failed loading URIs") dialog = Gtk.MessageDialog(modal=True, message_type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, text=_("Failed to open the user manual." " Make sure to have either the `yelp` GNOME " " documentation viewer or a web browser" " installed")) dialog.run() dialog.destroy()
def get_compatible_sink_caps(factoryname, caps): """ Returns the compatible caps between 'caps' and the sink pad caps of 'factoryname' """ log.log("render", "factoryname : %s , caps : %s", factoryname, caps.to_string()) factory = Gst.Registry.get().lookup_feature(factoryname) if factory == None: log.warning("render", "%s is not a valid factoryname", factoryname) return None res = [] sinkcaps = [x.get_caps() for x in factory.get_static_pad_templates() if x.direction == Gst.PadDirection.SINK] for c in sinkcaps: log.log("render", "sinkcaps %s", c.to_string()) inter = caps.intersect(c) log.log("render", "intersection %s", inter.to_string()) if inter: res.append(inter) if len(res) > 0: return res[0] return None
def get_compatible_sink_pad(factoryname, caps): """ Returns the pad name of a (request) pad from factoryname which is compatible with the given caps. """ factory = Gst.Registry.get().lookup_feature(factoryname) if factory == None: log.warning("render", "%s is not a valid factoryname", factoryname) return None res = [] sinkpads = [x for x in factory.get_static_pad_templates() if x.direction == Gst.PadDirection.SINK] for p in sinkpads: c = p.get_caps() log.log("render", "sinkcaps %s", c.to_string()) inter = caps.intersect(c) log.log("render", "intersection %s", inter.to_string()) if inter: res.append(p.name_template) if len(res) > 0: return res[0] return None
"""return the element of seq that gives max(map(func, seq))""" def compare(a1, b1): if a1[0] > b1[0]: return a1 return b1 # using a generator expression here should save memory objs = ((func(val), val) for val in seq) return reduce(compare, objs)[1] def same(seq): i = iter(seq) first = i.next() for item in i: if first != item: return None return first def show_user_manual(): time_now = int(time.time()) for uri in (APPMANUALURL_OFFLINE, APPMANUALURL_ONLINE): try: gtk.show_uri(None, uri, time_now) return except Exception, e: log.debug("utils", "Failed loading URI %s: %s", uri, e) continue log.warning("utils", "Failed loading URIs") # TODO: Show an error message to the user.
def fixate_caps_with_default_values(template, restrictions, default_values, prev_vals=None): """Fixates @template taking into account other restriction values. The resulting caps will only contain the fields from @default_values, @restrictions and @prev_vals Args: template (Gst.Caps) : The pad template to fixate. restrictions (Gst.Caps): Restriction caps to be used to fixate @template. This is the minimum requested restriction. Can be None default_values (dict) : Dictionary containing the minimal fields to be fixated and some default values (can be ranges). prev_vals (Optional[Gst.Caps]) : Some values that were previously used, and should be kept instead of the default values if possible. Returns: Gst.Caps: The caps resulting from the previously defined operations. """ res = Gst.Caps.new_empty() fields = set(default_values.keys()) if restrictions: for struct in restrictions: fields.update(struct.keys()) log.log("utils", "Intersect template %s with the restriction %s", template, restrictions) tmp = template.intersect(restrictions) if not tmp: log.warning("utils", "No common format between template %s and restrictions %s", template, restrictions) else: template = tmp for struct in template: struct = struct.copy() for field in fields: prev_val = None default_val = default_values.get(field) if prev_vals and prev_vals[0].has_field(field): prev_val = prev_vals[0][field] if not struct.has_field(field): if prev_val: struct[field] = prev_val elif default_val: struct[field] = default_val else: v = None struct_val = struct[field] if prev_val: v = intersect(struct_val, prev_val) if v is not None: struct[field] = v if v is None and default_val: v = intersect(struct_val, default_val) if v is not None: struct[field] = v else: log.debug("utils", "Field %s from %s is plainly fixated", field, struct) struct = struct.copy() for key in struct.keys(): if key not in fields: struct.remove_field(key) log.debug("utils", "Adding %s to resulting caps", struct) res.append_structure(struct) res.mini_object.refcount += 1 res = res.fixate() log.debug("utils", "Fixated %s", res) return res
def fixate_caps_with_default_values(template, restrictions, default_values, prev_vals=None): """Fixates @template taking into account other restriction values. The resulting caps will only contain the fields from @default_values, @restrictions and @prev_vals Args: template (Gst.Caps) : The pad template to fixate. restrictions (Gst.Caps): Restriction caps to be used to fixate @template. This is the minimum requested restriction. Can be None default_values (dict) : Dictionary containing the minimal fields to be fixated and some default values (can be ranges). prev_vals (Optional[Gst.Caps]) : Some values that were previously used, and should be kept instead of the default values if possible. Returns: Gst.Caps: The caps resulting from the previously defined operations. """ log.log("utils", "\ntemplate=Gst.Caps(\"%s\")," "\nrestrictions=%s,\n" "default_values=%s,\n" "prev_vals=Gst.Caps(\"%s\"),\n", "\"\n \"".join(template.to_string().split(";")), "Gst.Caps(\"%s\')" % restrictions if restrictions is not None else "None", default_values, "Gst.Caps(\"%s\')" % prev_vals if prev_vals is not None else "None") res = Gst.Caps.new_empty() fields = set(default_values.keys()) if restrictions: for struct in restrictions: fields.update(struct.keys()) log.log("utils", "Intersect template %s with the restriction %s", template, restrictions) tmp = template.intersect(restrictions) if not tmp: log.warning("utils", "No common format between template %s and restrictions %s", template, restrictions) else: template = tmp for struct in template: struct = struct.copy() for field in fields: prev_val = None default_val = default_values.get(field) if prev_vals and prev_vals[0].has_field(field): prev_val = prev_vals[0][field] if not struct.has_field(field): if prev_val: struct[field] = prev_val elif default_val: struct[field] = default_val else: value = None struct_val = struct[field] if prev_val: value = intersect(struct_val, prev_val) if value is not None: struct[field] = value if value is None and default_val: value = intersect(struct_val, default_val) if value is not None: struct[field] = value else: log.debug("utils", "Field %s from %s is plainly fixated", field, struct) struct = struct.copy() for key in struct.keys(): if key not in fields: struct.remove_field(key) if prev_vals and struct.is_equal(prev_vals[0]): res = Gst.Caps.new_empty() res.append_structure(prev_vals[0]) res.mini_object.refcount += 1 res = res.fixate() log.debug("utils", "Returning previous caps %s as it is fully compatible" " with the template", res) return res log.debug("utils", "Adding %s to resulting caps", struct) res.append_structure(struct) res.mini_object.refcount += 1 log.debug("utils", "Fixating %s", res) res = res.fixate() log.debug("utils", "Fixated %s", res) return res
objs = ((func(val), val) for val in seq) return reduce(compare, objs)[1] def same(seq): i = iter(seq) first = i.next() for item in i: if first != item: return None return first def show_user_manual(page=None): """ Display the user manual with Yelp. Optional: for contextual help, a page ID can be specified. """ time_now = int(time.time()) for uri in (APPMANUALURL_OFFLINE, APPMANUALURL_ONLINE): if page is not None: uri += "#" + page try: Gtk.show_uri(None, uri, time_now) return except Exception, e: log.debug("utils", "Failed loading URI %s: %s", uri, e) continue log.warning("utils", "Failed loading URIs") # TODO: Show an error message to the user.