From 561b0c4e7dd21a70521c211cf07ea19c6da9bd45 Mon Sep 17 00:00:00 2001 From: Dmitriy Yefremov Date: Fri, 6 Oct 2017 23:27:08 +0300 Subject: [PATCH] app skeleton --- main/editor_ui.glade | 881 +++++++++++++++++++++++++++++++++++++++ main/eparser/__init__.py | 2 + main/eparser/bouquets.py | 0 main/eparser/lamedb.py | 15 + main/eparser/satxml.py | 36 ++ main/properties.py | 38 ++ main/ui.py | 94 +++++ 7 files changed, 1066 insertions(+) create mode 100644 main/editor_ui.glade create mode 100644 main/eparser/__init__.py create mode 100644 main/eparser/bouquets.py create mode 100644 main/eparser/lamedb.py create mode 100644 main/eparser/satxml.py create mode 100644 main/properties.py create mode 100644 main/ui.py diff --git a/main/editor_ui.glade b/main/editor_ui.glade new file mode 100644 index 00000000..b7cb3fa7 --- /dev/null +++ b/main/editor_ui.glade @@ -0,0 +1,881 @@ + + + + + + + True + False + gtk-edit + + + + + + + + + + + ntv + ntv+ + + + + + + + + + + + + + ort + NTV+ + + + + + 560 + False + Enigma2ChannelEditor + + + + True + False + vertical + + + True + False + + + True + False + _Файл + True + + + True + False + + + gtk-open + True + False + True + True + + + + + True + False + + + + + gtk-connect + True + False + True + True + + + + + + gtk-disconnect + True + False + True + True + + + + + True + False + + + + + gtk-quit + True + False + True + True + + + + + + + + + + True + False + _Правка + True + + + True + False + + + gtk-cut + True + False + True + True + + + + + gtk-copy + True + False + True + True + + + + + gtk-paste + True + False + True + True + + + + + gtk-delete + True + False + True + True + + + + + + + + + True + False + _Инструменты + True + + + True + False + + + Satellites editor + True + False + image1 + False + + + + + True + False + + + + + gtk-preferences + True + False + True + True + + + + + + + + + + True + False + _Справка + True + + + True + False + + + gtk-about + True + False + True + True + + + + + + + + + + False + True + 0 + + + + + True + False + + + True + False + toolbutton1 + True + gtk-connect + + + + False + True + + + + + True + False + + + False + True + + + + + True + False + toolbutton3 + True + gtk-floppy + + + False + True + + + + + True + False + + + False + True + + + + + True + False + toolbutton14 + True + gtk-go-up + + + False + True + + + + + True + False + toolbutton13 + True + gtk-go-down + + + False + True + + + + + True + False + + + False + False + + + + + True + False + toolbutton5 + True + gtk-cut + + + False + True + + + + + True + False + toolbutton6 + True + gtk-copy + + + False + True + + + + + True + False + toolbutton7 + True + gtk-paste + + + False + True + + + + + True + False + toolbutton8 + True + gtk-remove + + + False + True + + + + + True + False + + + False + True + + + + + True + False + toolbutton10 + True + gtk-preferences + + + + False + True + + + + + True + False + + + False + True + + + + + True + False + toolbutton12 + True + gtk-about + + + + False + True + + + + + False + True + 2 + + + + + 150 + True + True + True + + + True + True + liststore1 + both + + + + + + True + autosize + Service + + + + 0 + + + + + + + True + autosize + Package + + + + 1 + + + + + + + True + True + + + + + True + True + liststore2 + both + + + + + + True + autosize + FAV + + + + 0 + + + + + + + True + autosize + Srv + + + + 1 + + + + + + + True + True + + + + + True + True + 3 + + + + + True + False + 10 + 10 + 6 + 6 + vertical + 2 + + + False + True + 3 + + + + + + + False + normal + main_window + DemonEditor + 0.1 + Enigma2 channel editor for GNU/Linux + Dmitriy Yefremov + accessories-text-editor + mit-x11 + + + False + vertical + 2 + + + False + end + + + False + False + 0 + + + + + + + + + + False + dialog + main_window + question + ok-cancel + + + False + immediate + vertical + 2 + + + False + True + end + + + False + False + 0 + + + + + + + False + Options + False + True + dialog + main_window + + + False + 5 + 5 + 5 + vertical + 2 + + + False + end + + + gtk-undo + True + True + True + True + + + True + True + 0 + + + + + gtk-ok + True + True + True + True + + + True + True + 1 + + + + + False + False + 1 + + + + + True + False + + + True + False + Host: + + + 0 + 0 + + + + + True + True + 127.0.0.1 + + + 0 + 1 + + + + + True + False + Login: + + + 0 + 2 + + + + + True + False + Password: + + + 1 + 2 + + + + + True + True + 21 + + + 1 + 1 + + + + + True + False + Port: + + + 1 + 0 + + + + + True + True + root + + + 0 + 3 + + + + + True + True + False + + root + password + + + 1 + 3 + + + + + False + True + 1 + + + + + True + False + 2 + 2 + + + False + True + 2 + + + + + True + False + True + + + True + False + Services and Bouquets files: + + + 0 + 0 + + + + + True + True + /etc/enigma2/ + + + 0 + 1 + + + + + True + False + User bouquet files: + + + 0 + 2 + + + + + True + True + /etc/enigma2/ + + + 0 + 3 + + + + + True + False + Satellites.xml file: + + + 0 + 4 + + + + + True + True + /etc/tuxbox/ + + + 0 + 5 + + + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + + cancel_button + ok_button + + + + True + autosize + Package + + + True + autosize + Service + + diff --git a/main/eparser/__init__.py b/main/eparser/__init__.py new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/main/eparser/__init__.py @@ -0,0 +1,2 @@ + + diff --git a/main/eparser/bouquets.py b/main/eparser/bouquets.py new file mode 100644 index 00000000..e69de29b diff --git a/main/eparser/lamedb.py b/main/eparser/lamedb.py new file mode 100644 index 00000000..d9bc0f2e --- /dev/null +++ b/main/eparser/lamedb.py @@ -0,0 +1,15 @@ +from collections import namedtuple + +Channel = namedtuple("Channel", ["name", "service", "freq", "fec"]) + +FILE_PATH = "files/lamedb" + +with open(FILE_PATH) as file: + lines = file.readlines() + + +for l in lines: + l.split() + +print(lines) + diff --git a/main/eparser/satxml.py b/main/eparser/satxml.py new file mode 100644 index 00000000..a206dcfe --- /dev/null +++ b/main/eparser/satxml.py @@ -0,0 +1,36 @@ +from xml.dom.minidom import parse + +XML_PATH = "files/satellites.xml" + + +class Satellite: + __slots__ = ["_name", "_flags", "_position", "_transponders"] + + def __init__(self, name, flags=None, position=None, transponders=None): + self._name = name + self._flags = flags + self._position = position + self._transponders = transponders + + def __repr__(self): + return str([self._name, self._flags, self._position, self._transponders]) + + +dom = parse(XML_PATH) + +satellites = [] + +for elem in dom.getElementsByTagName("sat"): + if elem.hasAttributes(): + # print(elem.attributes.keys()) + # print(elem.attributes.values()) + + sat = Satellite(elem.attributes["name"].value, elem.attributes["flags"].value, elem.attributes["position"].value) + satellites.append(sat) + # for key in elem.attributes.keys(): + # satellites.append(Sat()) + # atr = elem.attributes[key] + # print(atr.name, atr.value) + +for sat in satellites: + print(sat) diff --git a/main/properties.py b/main/properties.py new file mode 100644 index 00000000..cced6085 --- /dev/null +++ b/main/properties.py @@ -0,0 +1,38 @@ +import json +import os +from pathlib import Path + +CONFIG_PATH = str(Path.home()) + "/.config/demon-editor/" +CONFIG_FILE = CONFIG_PATH + "config.json" + + +def get_config(): + os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True) # create dir if not exist + if not os.path.isfile(CONFIG_FILE) or os.stat(CONFIG_FILE).st_size == 0: + with open(CONFIG_FILE, "w") as default_config_file: + json.dump(get_default_settings(), default_config_file) + + with open(CONFIG_FILE, "r") as config_file: + return json.load(config_file) + + +def write_config(config): + assert isinstance(config, dict) + with open(CONFIG_FILE, "w") as config_file: + json.dump(config, config_file) + + +def get_default_settings(): + return {"host": "127.0.0.1", "port": "21", + "user": "root", "password": "root", + "services_path": "/etc/enigma2/", + "user_bouquet_path": "/etc/enigma2/", + "satellites_xml_path": "/etc/tuxbox/"} + + +if __name__ == "__main__": + prop = get_config() + print(prop) + prop["host"] = "192.168.1.11" + write_config(prop) + print(get_config()) diff --git a/main/ui.py b/main/ui.py new file mode 100644 index 00000000..6929dfb5 --- /dev/null +++ b/main/ui.py @@ -0,0 +1,94 @@ +import gi +from ftplib import FTP +from properties import get_config, write_config + +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + +status_bar = None + + +def on_about_app(item): + builder = Gtk.Builder() + builder.add_from_file("editor_ui.glade") + dialog = builder.get_object("about_dialog") + dialog.run() + dialog.destroy() + + +def on_preferences(item): + builder = Gtk.Builder() + builder.add_from_file("editor_ui.glade") + dialog = builder.get_object("settings_dialog") + options = get_config() + host_field = builder.get_object("host_field") + host_field.set_text(options["host"]) + port_field = builder.get_object("port_field") + port_field.set_text(options["port"]) + login_field = builder.get_object("login_field") + login_field.set_text(options["user"]) + password_field = builder.get_object("password_field") + password_field.set_text(options["password"]) + services_field = builder.get_object("services_field") + services_field.set_text(options["services_path"]) + user_bouquet_field = builder.get_object("user_bouquet_field") + user_bouquet_field.set_text(options["user_bouquet_path"]) + satellites_xml_field = builder.get_object("satellites_xml_field") + satellites_xml_field.set_text(options["satellites_xml_path"]) + + if dialog.run() == Gtk.ResponseType.OK: + options["host"] = host_field.get_text() + options["port"] = port_field.get_text() + options["user"] = login_field.get_text() + options["password"] = password_field.get_text() + options["services_path"] = services_field.get_text() + options["user_bouquet_path"] = user_bouquet_field.get_text() + options["satellites_xml_path"] = satellites_xml_field.get_text() + write_config(options) + dialog.destroy() + + +def on_connect(item): + connect(get_config()) + + +def connect(properties): + assert isinstance(properties, dict) + try: + with FTP(properties["host"]) as ftp: + ftp.login(user=properties["user"], passwd=properties["password"]) + status_bar.push(1, ftp.voidcmd("NOOP")) + ftp.cwd(properties["services_path"]) + ftp.retrlines("LIST") + except Exception as e: + status_bar.remove_all(1) + status_bar.push(1, getattr(e, "message", repr(e))) # Or maybe so: getattr(e, 'message', str(e)) + + +def init_ui(): + handlers = { + "on_close_main_window": Gtk.main_quit, + "on_about_app": on_about_app, + "on_preferences": on_preferences, + "on_connect": on_connect + } + builder = Gtk.Builder() + builder.add_from_file("editor_ui.glade") + main_window = builder.get_object("main_window") + global status_bar + status_bar = builder.get_object("status_bar") + builder.connect_signals(handlers) + main_window.show_all() + + +def start_app(): + init_ui() + Gtk.main() + + +def close_app(): + Gtk.main_quit() + + +if __name__ == "__main__": + start_app()