|
@ -6,7 +6,7 @@ This file implements the JackIO Python side of Jack Medata as described here: |
|
|
http://www.jackaudio.org/files/docs/html/group__Metadata.html |
|
|
http://www.jackaudio.org/files/docs/html/group__Metadata.html |
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
|
|
|
import base64 # for icons |
|
|
import os.path |
|
|
import os.path |
|
|
|
|
|
|
|
|
#get_thing |
|
|
#get_thing |
|
@ -47,6 +47,20 @@ class Metadata: |
|
|
return TypeError("value {} must be int or str but was {}".format(value, type(value))) |
|
|
return TypeError("value {} must be int or str but was {}".format(value, type(value))) |
|
|
do_cmd("/io/set_property", None, [port, key, value, jackPropertyType]) |
|
|
do_cmd("/io/set_property", None, [port, key, value, jackPropertyType]) |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
def client_set_property(key, value, jackPropertyType=""): |
|
|
|
|
|
"""empty jackPropertyType leads to UTF-8 string |
|
|
|
|
|
for convenience we see if value is a python int and send the right jack_property_t::type |
|
|
|
|
|
|
|
|
|
|
|
This is directly for our client, which we do not need to provide here. |
|
|
|
|
|
""" |
|
|
|
|
|
if type(value) is int: |
|
|
|
|
|
jackPropertyType = "http://www.w3.org/2001/XMLSchema#int" |
|
|
|
|
|
value = str(value) |
|
|
|
|
|
elif not type(value) is str: |
|
|
|
|
|
return TypeError("value {} must be int or str but was {}".format(value, type(value))) |
|
|
|
|
|
do_cmd("/io/client_set_property", None, [key, value, jackPropertyType]) |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def remove_property(port, key): |
|
|
def remove_property(port, key): |
|
|
"""port is the portname as string System:out_1""" |
|
|
"""port is the portname as string System:out_1""" |
|
@ -102,42 +116,47 @@ class Metadata: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def _set_icon_name(port, freeDeskopIconName): |
|
|
def set_icon_name(freeDeskopIconName): |
|
|
"""Internal function used in set_icon_small and set_icon_large""" |
|
|
""" |
|
|
|
|
|
This sets the name of the icon according to freedesktop specs. |
|
|
|
|
|
The name is the basename without extension like so: |
|
|
|
|
|
/usr/share/icons/hicolor/32x32/apps/patroneo.png -> "patroneo" |
|
|
|
|
|
|
|
|
|
|
|
The name of the icon for the subject (typically client). |
|
|
|
|
|
This is used for looking up icons on the system, possibly with many sizes or themes. Icons |
|
|
|
|
|
should be searched for according to the freedesktop Icon |
|
|
|
|
|
Theme Specification: |
|
|
|
|
|
https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html |
|
|
|
|
|
""" |
|
|
if not os.path.splitext(freeDeskopIconName)[0] == freeDeskopIconName: |
|
|
if not os.path.splitext(freeDeskopIconName)[0] == freeDeskopIconName: |
|
|
raise ValueEror(f"Icon name must not have a file extension. Expected {os.path.splitext(freeDeskopIconName)[0]} but was {freeDeskopIconName}") |
|
|
raise ValueEror(f"Icon name must not have a file extension. Expected {os.path.splitext(freeDeskopIconName)[0]} but was {freeDeskopIconName}") |
|
|
|
|
|
|
|
|
if not os.path.basename(freeDeskopIconName) == freeDeskopIconName: |
|
|
if not os.path.basename(freeDeskopIconName) == freeDeskopIconName: |
|
|
raise ValueError(f"Icon name must not be path. Expected {os.path.basename(freeDeskopIconName)} but was {freeDeskopIconName}") |
|
|
raise ValueError(f"Icon name must not be path. Expected {os.path.basename(freeDeskopIconName)} but was {freeDeskopIconName}") |
|
|
|
|
|
|
|
|
self.set_property(port, "http://jackaudio.org/metadata/icon-name", freeDeskopIconName) |
|
|
Metadata.client_set_property("http://jackaudio.org/metadata/icon-name", freeDeskopIconName) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def set_icon_small(port, freeDeskopIconName, base64png): |
|
|
def set_icon_small(base64png): |
|
|
""" A value with a MIME type of "image/png;base64" that is an encoding of an |
|
|
""" A value with a MIME type of "image/png;base64" that is an encoding of an |
|
|
NxN (with 32 < N <= 128) image to be used when displaying a visual representation of that |
|
|
NxN (with 32 < N <= 128) image to be used when displaying a visual representation of that |
|
|
client or port. |
|
|
client or port. |
|
|
|
|
|
|
|
|
The name of the icon for the subject (typically client). |
|
|
|
|
|
This is used for looking up icons on the system, possibly with many sizes or themes. Icons |
|
|
|
|
|
should be searched for according to the freedesktop Icon |
|
|
|
|
|
Theme Specification: |
|
|
|
|
|
https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html |
|
|
|
|
|
|
|
|
|
|
|
The small icon of our JACK client. |
|
|
The small icon of our JACK client. |
|
|
Setting icons to ports seems to be technically possible, but this is not the function |
|
|
Setting icons to ports seems to be technically possible, but this is not the function |
|
|
for port-icons. |
|
|
for port-icons. |
|
|
|
|
|
|
|
|
This function does not check if base64png has the correct format. |
|
|
This function checks if the data is actually base64 and a shallow test if the data is PNG. |
|
|
|
|
|
|
|
|
This also sets the name of the icon according to freedesktop specs. |
|
|
|
|
|
The name is the basename without extension like so: |
|
|
|
|
|
/usr/share/icons/hicolor/32x32/apps/patroneo.png -> "patroneo" |
|
|
|
|
|
""" |
|
|
""" |
|
|
|
|
|
testDecode = base64.b64decode(base64png) |
|
|
|
|
|
if not base64png.encode("utf-8") == base64.b64encode(testDecode): |
|
|
|
|
|
raise ValueError("Provided data must be uft-8 and base64 encoded. But it was not") |
|
|
|
|
|
|
|
|
self.set_property(port, "http://jackaudio.org/metadata/icon-small", base64png, jackPropertyType="image/png;base64") |
|
|
if not "PNG" in repr(testDecode)[:16]: |
|
|
self._set_icon_name(port, freeDeskopIconName) |
|
|
raise ValueError("Provided data does not seem to be a PNG image. It is missing the PNG header.") |
|
|
|
|
|
|
|
|
|
|
|
Metadata.client_set_property("http://jackaudio.org/metadata/icon-small", base64png, jackPropertyType="image/png;base64") |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def set_icon_large(base64png): |
|
|
def set_icon_large(base64png): |
|
@ -145,21 +164,17 @@ class Metadata: |
|
|
NxN (with N <=32) image to be used when displaying a visual representation of that client |
|
|
NxN (with N <=32) image to be used when displaying a visual representation of that client |
|
|
or port. |
|
|
or port. |
|
|
|
|
|
|
|
|
The name of the icon for the subject (typically client). |
|
|
|
|
|
This is used for looking up icons on the system, possibly with many sizes or themes. Icons |
|
|
|
|
|
should be searched for according to the freedesktop Icon |
|
|
|
|
|
Theme Specification: |
|
|
|
|
|
https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html |
|
|
|
|
|
|
|
|
|
|
|
The large icon of our JACK client. |
|
|
The large icon of our JACK client. |
|
|
Setting icons to ports seems to be technically possible, but this is not the function |
|
|
Setting icons to ports seems to be technically possible, but this is not the function |
|
|
for port-icons. |
|
|
for port-icons. |
|
|
|
|
|
This function checks if the data is actually base64 and a shallow test if the data is PNG. |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
This function does not check if base64png has the correct format. |
|
|
testDecode = base64.b64decode(base64png) |
|
|
|
|
|
if not base64png.encode("utf-8") == base64.b64encode(testDecode): |
|
|
|
|
|
raise ValueError("Provided data must be uft-8 and base64 encoded. But it was not") |
|
|
|
|
|
|
|
|
This also sets the name of the icon according to freedesktop specs. |
|
|
if not "PNG" in repr(testDecode)[:16]: |
|
|
The name is the basename without extension like so: |
|
|
raise ValueError("Provided data does not seem to be a PNG image. It is missing the PNG header.") |
|
|
/usr/share/icons/hicolor/32x32/apps/patroneo.png -> "patroneo" |
|
|
|
|
|
""" |
|
|
Metadata.client_set_property("http://jackaudio.org/metadata/icon-large", base64png, jackPropertyType="image/png;base64") |
|
|
self.set_property(port, "http://jackaudio.org/metadata/icon-large", base64png, jackPropertyType="image/png;base64") |
|
|
|
|
|
self._set_icon_name(port, freeDeskopIconName) |
|
|
|
|
|