mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2026-05-07 20:35:36 +02:00
added basic screenshots support
This commit is contained in:
@@ -51,6 +51,7 @@ class HttpRequestType(Enum):
|
||||
PLAYER_PREV = "mediaplayercmd?command=previous"
|
||||
PLAYER_STOP = "mediaplayercmd?command=stop"
|
||||
PLAYER_REMOVE = "mediaplayerremove?file="
|
||||
GRUB = "grab?format=jpg&mode="
|
||||
|
||||
|
||||
class TestException(Exception):
|
||||
@@ -334,6 +335,7 @@ class HttpAPI:
|
||||
self._settings = settings
|
||||
self._shutdown = False
|
||||
self._session_id = 0
|
||||
self._main_url = None
|
||||
self._base_url = None
|
||||
self._data = None
|
||||
self.init()
|
||||
@@ -351,6 +353,8 @@ class HttpAPI:
|
||||
url += urllib.parse.quote(ref)
|
||||
elif req_type is HttpRequestType.PLAY or req_type is HttpRequestType.PLAYER_REMOVE:
|
||||
url += "{}{}".format(ref_prefix, urllib.parse.quote(ref).replace("%3A", "%253A"))
|
||||
elif req_type is HttpRequestType.GRUB:
|
||||
url = "{}/{}{}".format(self._main_url, req_type.value, ref)
|
||||
|
||||
def done_callback(f):
|
||||
callback(f.result())
|
||||
@@ -362,10 +366,10 @@ class HttpAPI:
|
||||
def init(self):
|
||||
user, password = self._settings.http_user, self._settings.http_password
|
||||
use_ssl = self._settings.http_use_ssl
|
||||
url = "http{}://{}:{}".format("s" if use_ssl else "", self._settings.host, self._settings.http_port)
|
||||
self._base_url = "{}/web/".format(url)
|
||||
init_auth(user, password, url, use_ssl)
|
||||
url = "{}/web/{}".format(url, HttpRequestType.TOKEN.value)
|
||||
self._main_url = "http{}://{}:{}".format("s" if use_ssl else "", self._settings.host, self._settings.http_port)
|
||||
self._base_url = "{}/web/".format(self._main_url)
|
||||
init_auth(user, password, self._main_url, use_ssl)
|
||||
url = "{}/web/{}".format(self._main_url, HttpRequestType.TOKEN.value)
|
||||
s_id = get_session_id(user, password, url)
|
||||
if s_id != "0":
|
||||
self._data = urllib.parse.urlencode({"user": user, "password": password, "sessionid": s_id}).encode("utf-8")
|
||||
@@ -381,6 +385,8 @@ def get_response(req_type, url, data=None):
|
||||
with urlopen(Request(url, data=data), timeout=10) as f:
|
||||
if req_type is HttpRequestType.STREAM or req_type is HttpRequestType.STREAM_CURRENT:
|
||||
return {"m3u": f.read().decode("utf-8")}
|
||||
elif req_type is HttpRequestType.GRUB:
|
||||
return {"img_data": f.read()}
|
||||
elif req_type is HttpRequestType.CURRENT:
|
||||
for el in ETree.fromstring(f.read().decode("utf-8")).iter("e2event"):
|
||||
return {el.tag: el.text for el in el.iter()} # return first[current] event from the list
|
||||
|
||||
@@ -238,6 +238,9 @@ class Application(Gtk.Application):
|
||||
self._signal_level_bar.bind_property("visible", builder.get_object("record_button"), "visible")
|
||||
self._receiver_info_box.bind_property("visible", self._http_status_image, "visible", 4)
|
||||
self._receiver_info_box.bind_property("visible", self._signal_box, "visible")
|
||||
# Screenshots
|
||||
self._screenshots_button = builder.get_object("screenshots_button")
|
||||
self._receiver_info_box.bind_property("visible", self._screenshots_button, "visible")
|
||||
# Force ctrl press event for view. Multiple selections in lists only with Space key(as in file managers)!!!
|
||||
self._services_view.connect("key-press-event", self.force_ctrl)
|
||||
self._fav_view.connect("key-press-event", self.force_ctrl)
|
||||
@@ -347,6 +350,10 @@ class Application(Gtk.Application):
|
||||
set_action("upload_bouquets", lambda a, v: self.on_upload_data(DownloadType.BOUQUETS))
|
||||
# Edit
|
||||
set_action("on_edit", self.on_edit)
|
||||
# Screenshots
|
||||
set_action("on_screenshot_all", self.on_screenshot_all)
|
||||
set_action("on_screenshot_video", self.on_screenshot_video)
|
||||
set_action("on_screenshot_osd", self.on_screenshot_osd)
|
||||
|
||||
def set_accels(self):
|
||||
""" Setting accelerators for the actions. """
|
||||
@@ -2213,6 +2220,37 @@ class Application(Gtk.Application):
|
||||
self._service_epg_label.set_text(dsc)
|
||||
self._service_epg_label.set_tooltip_text(evn.get("e2eventdescription", ""))
|
||||
|
||||
# ******************** Screenshots ************************#
|
||||
|
||||
def on_screenshot_all(self, action, value=None):
|
||||
self._http_api.send(HttpRequestType.GRUB, "all", self.on_screenshot)
|
||||
|
||||
def on_screenshot_video(self, action, value=None):
|
||||
self._http_api.send(HttpRequestType.GRUB, "video", self.on_screenshot)
|
||||
|
||||
def on_screenshot_osd(self, action, value=None):
|
||||
self._http_api.send(HttpRequestType.GRUB, "osd", self.on_screenshot)
|
||||
|
||||
def on_screenshot(self, data):
|
||||
if "error_code" in data:
|
||||
return
|
||||
|
||||
img = data.get("img_data", None)
|
||||
if img:
|
||||
self._screenshots_button.set_sensitive(False)
|
||||
try:
|
||||
import tempfile
|
||||
import subprocess
|
||||
|
||||
with tempfile.NamedTemporaryFile(mode="wb", suffix=".jpg") as tf:
|
||||
tf.write(img)
|
||||
p = subprocess.Popen(["open" if self._settings.is_darwin else "xdg-open", tf.name],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
p.communicate()
|
||||
finally:
|
||||
self._screenshots_button.set_sensitive(True)
|
||||
|
||||
# ***************** Filter and search *********************#
|
||||
|
||||
def on_filter_toggled(self, action, value):
|
||||
|
||||
@@ -653,6 +653,70 @@ Author: Dmitriy Yefremov
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-save-as</property>
|
||||
</object>
|
||||
<object class="GtkPopoverMenu" id="screenshots_menu">
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="screenshots_menu_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_right">10</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">2</property>
|
||||
<child>
|
||||
<object class="GtkModelButton" id="screenshot_button_all">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="action_name">app.on_screenshot_all</property>
|
||||
<property name="text" translatable="yes">All</property>
|
||||
<property name="centered">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkModelButton" id="screenshot_button_video">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="action_name">app.on_screenshot_video</property>
|
||||
<property name="text" translatable="yes">Video</property>
|
||||
<property name="centered">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkModelButton" id="screenshot_button_osd">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="action_name">app.on_screenshot_osd</property>
|
||||
<property name="text" translatable="yes">OSD</property>
|
||||
<property name="centered">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="submenu">main</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkImage" id="select_all_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
@@ -2864,6 +2928,8 @@ Author: Dmitriy Yefremov
|
||||
<object class="GtkImage" id="info_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="stock">gtk-info</property>
|
||||
</object>
|
||||
<packing>
|
||||
@@ -2910,10 +2976,35 @@ Author: Dmitriy Yefremov
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child type="center">
|
||||
<object class="GtkMenuButton" id="screenshots_button">
|
||||
<property name="name">status-bar-button</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Screenshot</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="popover">screenshots_menu</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="screenshots_menu_button_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">zoom-best-fit</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage" id="http_status_image">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">No connection to the receiver!</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_right">10</property>
|
||||
<property name="icon_name">network-offline</property>
|
||||
@@ -2953,6 +3044,8 @@ Author: Dmitriy Yefremov
|
||||
<property name="can_focus">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Record</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<signal name="clicked" handler="on_record" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkImage" id="record_button_image">
|
||||
|
||||
Reference in New Issue
Block a user