mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2026-07-04 15:17:49 +02:00
refactoring of picon assignment
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018-2021 Dmitriy Yefremov
|
||||
Copyright (c) 2018-2022 Dmitriy Yefremov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -1929,11 +1929,14 @@ Author: Dmitriy Yefremov
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="min_width">25</property>
|
||||
<property name="title" translatable="yes">Picon</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="clickable">True</property>
|
||||
<property name="alignment">0.5</property>
|
||||
<property name="sort_column_id">9</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererPixbuf" id="picon_renderer"/>
|
||||
<object class="GtkCellRendererPixbuf" id="picon_renderer">
|
||||
<property name="ypad">2</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="cell-background-rgba">21</attribute>
|
||||
<attribute name="pixbuf">8</attribute>
|
||||
@@ -2744,6 +2747,25 @@ Author: Dmitriy Yefremov
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="fav_picon_column">
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="min_width">25</property>
|
||||
<property name="title" translatable="yes">Picon</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="clickable">True</property>
|
||||
<property name="alignment">0.5</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererPixbuf" id="fav_picon_renderer">
|
||||
<property name="ypad">2</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="cell-background-rgba">10</attribute>
|
||||
<attribute name="pixbuf">8</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="fav_service_column">
|
||||
<property name="resizable">True</property>
|
||||
@@ -2754,15 +2776,6 @@ Author: Dmitriy Yefremov
|
||||
<property name="clickable">True</property>
|
||||
<property name="alignment">0.5</property>
|
||||
<signal name="clicked" handler="on_fav_sort" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkCellRendererPixbuf" id="fav_picon_renderer">
|
||||
<property name="xpad">5</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="cell-background-rgba">10</attribute>
|
||||
<attribute name="pixbuf">8</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCellRendererPixbuf" id="fav_coded_renderer">
|
||||
<property name="width">24</property>
|
||||
|
||||
@@ -435,10 +435,10 @@ class Application(Gtk.Application):
|
||||
self._player_box.bind_property("visible", profile_box, "visible", 4)
|
||||
self._player_box.bind_property("visible", toolbar_box, "visible", 4)
|
||||
# Picons.
|
||||
column = builder.get_object("picon_column")
|
||||
column.set_cell_data_func(builder.get_object("picon_renderer"), self.picon_data_func)
|
||||
column = builder.get_object("fav_service_column")
|
||||
column.set_cell_data_func(builder.get_object("fav_picon_renderer"), self.fav_picon_data_func)
|
||||
self._picon_renderer = builder.get_object("picon_renderer")
|
||||
builder.get_object("picon_column").set_cell_data_func(self._picon_renderer, self.picon_data_func)
|
||||
self._fav_picon_renderer = builder.get_object("fav_picon_renderer")
|
||||
builder.get_object("fav_picon_column").set_cell_data_func(self._fav_picon_renderer, self.fav_picon_data_func)
|
||||
# Setting the last size of the window if it was saved.
|
||||
main_window_size = self._settings.get("window_size")
|
||||
if main_window_size:
|
||||
@@ -701,7 +701,10 @@ class Application(Gtk.Application):
|
||||
self._current_font = self._settings.list_font
|
||||
|
||||
if self._picons_size != self._settings.list_picon_size:
|
||||
self._picons_size = self._settings.list_picon_size
|
||||
self._picons.clear()
|
||||
self._picon_renderer.set_fixed_size(self._picons_size, self._picons_size * 0.65)
|
||||
self._fav_picon_renderer.set_fixed_size(self._picons_size, self._picons_size * 0.65)
|
||||
|
||||
if self._s_type is SettingsType.ENIGMA_2:
|
||||
self._use_colors = self._settings.use_colors
|
||||
@@ -1103,7 +1106,7 @@ class Application(Gtk.Application):
|
||||
self._wait_dialog.hide()
|
||||
yield True
|
||||
|
||||
# ***************** ####### *********************#
|
||||
# ***************** Bouquets ********************* #
|
||||
|
||||
def get_bouquet_file_name(self, bouquet):
|
||||
bouquet_file_name = "{}userbouquet.{}.{}".format(self._settings.get(self._s_type).get("data_dir_path"),
|
||||
@@ -2703,7 +2706,6 @@ class Application(Gtk.Application):
|
||||
|
||||
dialog = ImportDialog(self._main_window, path, self._settings, self._services.keys(), append)
|
||||
dialog.import_data() if force else dialog.show()
|
||||
self.update_picons()
|
||||
|
||||
def append_imported_data(self, bouquets, services, callback=None):
|
||||
try:
|
||||
@@ -3514,12 +3516,13 @@ class Application(Gtk.Application):
|
||||
alt_srv = self._services.get(alt_servs[0].data, None)
|
||||
if alt_srv:
|
||||
picon = self._picons.get(alt_srv.picon_id, None) if srv else None
|
||||
|
||||
renderer.set_property("pixbuf", picon)
|
||||
|
||||
@run_task
|
||||
@run_idle
|
||||
def update_picons(self):
|
||||
update_picons_data(self._settings.profile_picons_path, self._picons, self._picons_size)
|
||||
append_picons(self._picons, self._services_model)
|
||||
self._picons.clear()
|
||||
self._fav_model.foreach(lambda m, p, i: m.set_value(i, Column.FAV_PICON, None))
|
||||
|
||||
def get_picon(self, p_id):
|
||||
return get_picon_pixbuf(f"{self._settings.profile_picons_path}{p_id}", self._picons_size)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2018-2021 Dmitriy Yefremov
|
||||
# Copyright (c) 2018-2022 Dmitriy Yefremov
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,10 +29,10 @@
|
||||
""" Helper module for the GUI. """
|
||||
|
||||
__all__ = ("insert_marker", "move_items", "rename", "ViewTarget", "set_flags", "locate_in_services",
|
||||
"scroll_to", "get_base_model", "update_picons_data", "copy_picon_reference", "assign_picons",
|
||||
"remove_picon", "is_only_one_item_selected", "gen_bouquets", "BqGenType", "append_picons",
|
||||
"get_selection", "get_model_data", "remove_all_unused_picons", "get_picon_pixbuf", "get_base_itrs",
|
||||
"get_iptv_url", "update_entry_data", "append_text_to_tview", "on_popup_menu")
|
||||
"scroll_to", "get_base_model", "copy_picon_reference", "assign_picons", "remove_picon",
|
||||
"is_only_one_item_selected", "gen_bouquets", "BqGenType", "get_selection",
|
||||
"get_model_data", "remove_all_unused_picons", "get_picon_pixbuf", "get_base_itrs", "get_iptv_url",
|
||||
"update_entry_data", "append_text_to_tview", "on_popup_menu")
|
||||
|
||||
import os
|
||||
import shutil
|
||||
@@ -44,8 +44,8 @@ from gi.repository import GdkPixbuf, GLib
|
||||
from app.eparser import Service
|
||||
from app.eparser.ecommons import Flag, BouquetService, Bouquet, BqType
|
||||
from app.eparser.enigma.bouquets import BqServiceType, to_bouquet_id
|
||||
from app.settings import SettingsType, SEP, IS_WIN
|
||||
from .dialogs import show_dialog, DialogType, get_chooser_dialog
|
||||
from app.settings import SettingsType, SEP, IS_WIN, IS_DARWIN, IS_LINUX
|
||||
from .dialogs import show_dialog, DialogType, get_message
|
||||
from .uicommons import ViewTarget, BqGenType, Gtk, Gdk, HIDE_ICON, LOCKED_ICON, KeyboardKey, Column
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ def insert_marker(view, bouquets, selected_bouquet, services, parent_window, m_t
|
||||
show_dialog(DialogType.ERROR, parent_window, "The text of marker is empty, please try again!")
|
||||
return
|
||||
|
||||
fav_id = "1:64:0:0:0:0:0:0:0:0::{}\n#DESCRIPTION {}\n".format(response, response)
|
||||
fav_id = f"1:64:0:0:0:0:0:0:0:0::{response}\n#DESCRIPTION {response}\n"
|
||||
text = response
|
||||
|
||||
s_type = m_type.name
|
||||
@@ -110,8 +110,8 @@ def move_items(key, view: Gtk.TreeView):
|
||||
children_num = model.iter_n_children(parent_itr)
|
||||
if key in (KeyboardKey.PAGE_DOWN, KeyboardKey.END, KeyboardKey.END_KP, KeyboardKey.PAGE_DOWN_KP):
|
||||
children_num -= 1
|
||||
min_path = Gtk.TreePath.new_from_string("{}:{}".format(parent_index, 0))
|
||||
max_path = Gtk.TreePath.new_from_string("{}:{}".format(parent_index, children_num))
|
||||
min_path = Gtk.TreePath.new_from_string(f"{parent_index}:{0}")
|
||||
max_path = Gtk.TreePath.new_from_string(f"{parent_index}:{children_num}")
|
||||
is_tree_store = True
|
||||
|
||||
if key is KeyboardKey.UP:
|
||||
@@ -386,26 +386,36 @@ def scroll_to(index, view, paths=None):
|
||||
selection.select_path(index)
|
||||
|
||||
|
||||
# ***************** Picons *********************#
|
||||
# ***************** Picons ********************* #
|
||||
|
||||
def update_picons_data(path, picons, size=32):
|
||||
if not os.path.exists(path):
|
||||
return
|
||||
def get_picon_dialog(transient, title, button_text, multiple=True):
|
||||
""" Returns a copy dialog with a preview of images [picons -> *.png]. """
|
||||
dialog = Gtk.FileChooserNative.new(title, transient, Gtk.FileChooserAction.OPEN, button_text)
|
||||
dialog.set_select_multiple(multiple)
|
||||
dialog.set_modal(True)
|
||||
# Filter.
|
||||
file_filter = Gtk.FileFilter()
|
||||
file_filter.set_name("*.png")
|
||||
file_filter.add_pattern("*.png")
|
||||
file_filter.add_mime_type("image/png") if IS_DARWIN else None
|
||||
dialog.add_filter(file_filter)
|
||||
|
||||
for file in os.listdir(path):
|
||||
pf = get_picon_pixbuf(path + file, size)
|
||||
if pf:
|
||||
picons[file] = pf
|
||||
if IS_LINUX:
|
||||
preview_image = Gtk.Image(margin_right=10)
|
||||
dialog.set_preview_widget(preview_image)
|
||||
|
||||
def update_preview_widget(dlg):
|
||||
path = dialog.get_preview_filename()
|
||||
if not path:
|
||||
return
|
||||
|
||||
def append_picons(picons, model):
|
||||
def append_picons_data(pcs, mod):
|
||||
for r in mod:
|
||||
mod.set_value(mod.get_iter(r.path), Column.SRV_PICON, pcs.get(r[Column.SRV_PICON_ID], None))
|
||||
yield True
|
||||
pix = get_picon_pixbuf(path, 220)
|
||||
preview_image.set_from_pixbuf(pix)
|
||||
dlg.set_preview_widget_active(bool(pix))
|
||||
|
||||
app = append_picons_data(picons, model)
|
||||
GLib.idle_add(lambda: next(app, False), priority=GLib.PRIORITY_LOW)
|
||||
dialog.connect("update-preview", update_preview_widget)
|
||||
|
||||
return dialog
|
||||
|
||||
|
||||
def assign_picons(target, srv_view, fav_view, transient, picons, settings, services, src_path=None, dst_path=None):
|
||||
@@ -415,10 +425,12 @@ def assign_picons(target, srv_view, fav_view, transient, picons, settings, servi
|
||||
picons_files = []
|
||||
|
||||
if not src_path:
|
||||
src_path = get_chooser_dialog(transient, settings, "*.png files", ("*.png",))
|
||||
if src_path == Gtk.ResponseType.CANCEL:
|
||||
dialog = get_picon_dialog(transient, get_message("Picon selection"), get_message("Open"), False)
|
||||
if dialog.run() in (Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT) or not dialog.get_filenames():
|
||||
return picons_files
|
||||
|
||||
src_path = dialog.get_filenames()[0]
|
||||
|
||||
if IS_WIN:
|
||||
src_path = src_path.lstrip("/")
|
||||
dst_path = dst_path.lstrip("/") if dst_path else dst_path
|
||||
@@ -450,7 +462,7 @@ def assign_picons(target, srv_view, fav_view, transient, picons, settings, servi
|
||||
pass # NOP
|
||||
else:
|
||||
picons_files.append(picon_file)
|
||||
picon = get_picon_pixbuf(picon_file)
|
||||
picon = get_picon_pixbuf(picon_file, settings.list_picon_size)
|
||||
picons[picon_id] = picon
|
||||
model.set_value(itr, p_pos, picon)
|
||||
if target is ViewTarget.SERVICES:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2018-2021 Dmitriy Yefremov
|
||||
# Copyright (c) 2018-2022 Dmitriy Yefremov
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -37,13 +37,13 @@ from gi.repository import GLib, GdkPixbuf, Gio
|
||||
|
||||
from app.commons import run_idle, run_task, run_with_delay, log
|
||||
from app.connections import upload_data, DownloadType, download_data, remove_picons
|
||||
from app.settings import SettingsType, Settings, SEP, IS_LINUX, IS_DARWIN
|
||||
from app.settings import SettingsType, Settings, SEP, IS_DARWIN
|
||||
from app.tools.picons import (PiconsParser, parse_providers, Provider, convert_to, download_picon, PiconsCzDownloader,
|
||||
PiconsError)
|
||||
from app.tools.satellites import SatellitesParser, SatelliteSource
|
||||
from .dialogs import show_dialog, DialogType, get_message, get_builder, get_chooser_dialog
|
||||
from .main_helper import (update_entry_data, append_text_to_tview, scroll_to, on_popup_menu, get_base_model, set_picon,
|
||||
get_picon_pixbuf)
|
||||
get_picon_pixbuf, get_picon_dialog)
|
||||
from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH, TV_ICON, Column, KeyboardKey, Page, ViewTarget
|
||||
|
||||
|
||||
@@ -287,6 +287,7 @@ class PiconManager(Gtk.Box):
|
||||
yield True
|
||||
|
||||
self._dst_count_label.set_text("0")
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
for index, file in enumerate(os.listdir(path)):
|
||||
if self._terminate:
|
||||
return
|
||||
@@ -479,42 +480,12 @@ class PiconManager(Gtk.Box):
|
||||
|
||||
def on_add(self, item):
|
||||
""" Adds (copies) picons from an external folder to the profile picons folder. """
|
||||
dialog = self.get_copy_dialog()
|
||||
dialog = get_picon_dialog(self._app_window, get_message("Add picons"), get_message("Add"))
|
||||
if dialog.run() in (Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT):
|
||||
return
|
||||
|
||||
self.copy_picons_file(dialog.get_filenames())
|
||||
|
||||
def get_copy_dialog(self):
|
||||
""" Returns a copy dialog with a preview of images [picons -> *.png]. """
|
||||
dialog = Gtk.FileChooserNative.new(get_message("Add picons"), self._app_window,
|
||||
Gtk.FileChooserAction.OPEN, get_message("Add"))
|
||||
dialog.set_select_multiple(True)
|
||||
dialog.set_modal(True)
|
||||
# Filter.
|
||||
file_filter = Gtk.FileFilter()
|
||||
file_filter.set_name("*.png")
|
||||
file_filter.add_pattern("*.png")
|
||||
file_filter.add_mime_type("image/png") if IS_DARWIN else None
|
||||
dialog.add_filter(file_filter)
|
||||
|
||||
if IS_LINUX:
|
||||
preview_image = Gtk.Image(margin_right=10)
|
||||
dialog.set_preview_widget(preview_image)
|
||||
|
||||
def update_preview_widget(dlg):
|
||||
path = dialog.get_preview_filename()
|
||||
if not path:
|
||||
return
|
||||
|
||||
pix = get_picon_pixbuf(path, 220)
|
||||
preview_image.set_from_pixbuf(pix)
|
||||
dlg.set_preview_widget_active(bool(pix))
|
||||
|
||||
dialog.connect("update-preview", update_preview_widget)
|
||||
|
||||
return dialog
|
||||
|
||||
def on_extract(self, item):
|
||||
""" Extracts picons from an archives to the profile picons folder. """
|
||||
file_filter = None
|
||||
@@ -906,15 +877,6 @@ class PiconManager(Gtk.Box):
|
||||
self._is_downloading = False
|
||||
self.show_info_message(get_message("The task is canceled!"), Gtk.MessageType.WARNING)
|
||||
|
||||
def on_close(self, window, event):
|
||||
if self.on_cancel():
|
||||
return True
|
||||
|
||||
self._terminate = True
|
||||
self._is_downloading = False
|
||||
self._app.update_picons()
|
||||
GLib.idle_add(self._app_window.destroy)
|
||||
|
||||
@run_task
|
||||
def run_func(self, func, update=False):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user