mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2025-12-22 08:29:41 +01:00
convert to impl
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
|
||||||
from app.commons import log
|
from app.commons import log, run_task
|
||||||
from app.properties import Profile
|
from app.properties import Profile
|
||||||
|
|
||||||
_ENIGMA2_PICON_KEY = "{:X}:{:X}:{:X}0000"
|
_ENIGMA2_PICON_KEY = "{:X}:{:X}:{:X}0000"
|
||||||
@@ -184,5 +185,23 @@ def parse_providers(open_path):
|
|||||||
return [Provider(logo=r[2], name=r[5], pos=r[0], url=r[6], on_id=r[-2], selected=True) for r in rows]
|
return [Provider(logo=r[2], name=r[5], pos=r[0], url=r[6], on_id=r[-2], selected=True) for r in rows]
|
||||||
|
|
||||||
|
|
||||||
|
@run_task
|
||||||
|
def convert_to(src_path, dest_path, profile, callback, done_callback):
|
||||||
|
""" Converts names format of picons.
|
||||||
|
|
||||||
|
Copies resulting files from src to dest and writes state to callback.
|
||||||
|
"""
|
||||||
|
pattern = "/*_0_0_0.png" if profile is Profile.ENIGMA_2 else "/*.png"
|
||||||
|
for file in glob.glob(src_path + pattern):
|
||||||
|
base_name = os.path.basename(file)
|
||||||
|
pic_data = base_name.rstrip(".png").split("_")
|
||||||
|
dest_file = _NEUTRINO_PICON_KEY.format(int(pic_data[4], 16), int(pic_data[5], 16), int(pic_data[3], 16))
|
||||||
|
dest = "{}/{}".format(dest_path, dest_file)
|
||||||
|
callback('Converting "{}" to "{}"\n'.format(base_name, dest_file))
|
||||||
|
shutil.copyfile(file, dest)
|
||||||
|
|
||||||
|
done_callback()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from gi.repository import GLib, GdkPixbuf
|
|||||||
|
|
||||||
from app.commons import run_idle, run_task
|
from app.commons import run_idle, run_task
|
||||||
from app.ftp import upload_data, DownloadDataType
|
from app.ftp import upload_data, DownloadDataType
|
||||||
from app.picons.picons import PiconsParser, parse_providers, Provider
|
from app.picons.picons import PiconsParser, parse_providers, Provider, convert_to
|
||||||
from app.properties import Profile
|
from app.properties import Profile
|
||||||
from . import Gtk, Gdk, UI_RESOURCES_PATH, TEXT_DOMAIN
|
from . import Gtk, Gdk, UI_RESOURCES_PATH, TEXT_DOMAIN
|
||||||
from .dialogs import show_dialog, DialogType
|
from .dialogs import show_dialog, DialogType
|
||||||
@@ -239,12 +239,20 @@ class PiconsDialog:
|
|||||||
if self._enigma2_path_button.get_filename() is None:
|
if self._enigma2_path_button.get_filename() is None:
|
||||||
self._enigma2_path_button.set_current_folder(self._enigma2_picons_path)
|
self._enigma2_path_button.set_current_folder(self._enigma2_picons_path)
|
||||||
|
|
||||||
|
@run_idle
|
||||||
def on_convert(self, item):
|
def on_convert(self, item):
|
||||||
picons_path = self._enigma2_path_button.get_filename()
|
picons_path = self._enigma2_path_button.get_filename()
|
||||||
save_path = self._save_to_button.get_filename()
|
save_path = self._save_to_button.get_filename()
|
||||||
if not picons_path or not save_path:
|
if not picons_path or not save_path:
|
||||||
show_dialog(DialogType.ERROR, transient=self._dialog, text="Select paths!")
|
show_dialog(DialogType.ERROR, transient=self._dialog, text="Select paths!")
|
||||||
|
|
||||||
|
self._expander.set_expanded(True)
|
||||||
|
convert_to(src_path=picons_path,
|
||||||
|
dest_path=save_path,
|
||||||
|
profile=Profile.ENIGMA_2,
|
||||||
|
callback=self.append_output,
|
||||||
|
done_callback=lambda: self.show_info_message("Done!", Gtk.MessageType.INFO))
|
||||||
|
|
||||||
@run_idle
|
@run_idle
|
||||||
def update_receive_button_state(self):
|
def update_receive_button_state(self):
|
||||||
self._receive_tool_button.set_sensitive(len(self.get_selected_providers()) > 0)
|
self._receive_tool_button.set_sensitive(len(self.get_selected_providers()) > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user