Changed working with favorites and bouquets

This commit is contained in:
Dmitriy Yefremov
2017-10-24 00:09:11 +03:00
parent f881681371
commit 096fb60d63
7 changed files with 117 additions and 48 deletions

View File

@@ -1,2 +1,2 @@
# DemonEditor
Enigma2 channel list editor for GNU/Linux
Enigma2 channel and satellites list editor for GNU/Linux

View File

@@ -28,5 +28,5 @@ SYSTEM = {"0": "DVB-S", "1": "DVB-S2"}
MODULATION = {"0": "Auto", "1": "QPSK", "2": "8PSK", "3": "16APSK", "5": "32APSK"}
SERVICE_TYPE = {-2: "Unknown", 1: "TV", 2: "Radio", 3: "Data",
10: "Radio", 12: "Data", 22: "TV", 25: "TV",
10: "Radio", 12: "Data", 22: "TV", 25: "TV (HD)",
136: "Data", 139: "Data"}

View File

@@ -1,5 +1,5 @@
from .lamedb import get_channels
from .bouquets import get_bouquets, get_bouquet
from .lamedb import get_channels, write_channels
from .bouquets import get_bouquets, get_bouquet, write_bouquet
from .satxml import get_satellites, write_satellites, Satellite, Transponder

View File

@@ -3,20 +3,30 @@ from collections import namedtuple
__BOUQUETS_PATH = "../data/"
Bouquet = namedtuple("Bouquet", ["name", "type"])
Bouquet = namedtuple("Bouquet", ["name", "type", "services"])
Bouquets = namedtuple("Bouquets", ["name", "bouquets"])
def get_bouquets(path):
return [parse_bouquets(path, "bouquets.tv"), parse_bouquets(path, "bouquets.radio")]
return parse_bouquets(path, "bouquets.tv", "tv"), parse_bouquets(path, "bouquets.radio", "radio")
def write_bouquets(path, channels):
pass
def write_bouquet(path, name, channels):
bouquet = ["#NAME {}\n".format(name)]
for ch in channels:
data_type = int(ch.data_id.split(":")[-2])
if data_type == 22:
data_type = 16
elif data_type == 25:
data_type = 19
bouquet.append("#SERVICE {}:0:{}:{}:0:0:0:\n".format(1, data_type, ch.fav_id))
with open(path + "_userbouquet.{}.tv".format(name), "w") as file:
file.writelines(bouquet)
def get_bouquet(path, name, type):
with open(path + "userbouquet.{}.{}".format(name, str(type))) as file:
def get_bouquet(path, name, bq_type):
""" Parsing services ids from bouquet file """
with open(path + "userbouquet.{}.{}".format(name, bq_type)) as file:
chs_list = file.read()
ids = []
for ch in chs_list.split("#SERVICE")[1:]:
@@ -25,8 +35,8 @@ def get_bouquet(path, name, type):
return ids
def parse_bouquets(path, name):
with open(path + name) as file:
def parse_bouquets(path, bq_name, bq_type):
with open(path + bq_name) as file:
lines = file.readlines()
bouquets = None
nm_sep = "#NAME"
@@ -34,8 +44,9 @@ def parse_bouquets(path, name):
if nm_sep in line:
_, _, name = line.partition(nm_sep)
bouquets = Bouquets(name.strip(), [])
if bouquets is not None and "#SERVICE" in line:
bouquets[1].append(line.split(".")[1])
if bouquets and "#SERVICE" in line:
name = line.split(".")[1]
bouquets[1].append(Bouquet(name=name, type=bq_type, services=get_bouquet(path, name, bq_type)))
return bouquets

View File

@@ -14,6 +14,10 @@ def get_channels(path):
return parse(path)
def write_channels(path, channels):
print(channels)
def parse(path):
""" Parsing lamedb """
with open(path, "r") as file:

View File

@@ -1,7 +1,6 @@
from threading import Thread
from main.eparser import get_channels, get_bouquets, get_bouquet
from main.eparser.__constants import SERVICE_TYPE
from main.eparser import get_channels, get_bouquets, write_bouquet, write_channels
from main.ftp import download_data, upload_data
from main.properties import get_config, write_config
from . import Gtk, Gdk
@@ -26,6 +25,7 @@ __bouquets_view = None
# Clearing only after the insertion!
__rows_buffer = []
__channels = {}
__bouquets = {}
def on_about_app(item):
@@ -121,6 +121,11 @@ def on_delete(item):
model.remove(itr)
if model.get_name() == FAV_LIST_NAME:
update_fav_num_column(model)
if model.get_name() == SERVICE_LIST_NAME:
for row in rows:
# There are channels with the same parameters except for the name.
# None because it can have duplicates! Need fix
__channels.pop(row[-1], None)
return rows
@@ -222,11 +227,13 @@ def data_open(model):
__channels[ch.fav_id] = ch
model.append(ch)
if model_name == BOUQUETS_LIST_NAME:
data = get_bouquets(data_path)
for name, bouquets in data:
parent = model.append(None, [name])
for bouquet in bouquets:
model.append(parent, [bouquet])
bouquets = get_bouquets(data_path)
for bouquet in bouquets:
parent = model.append(None, [bouquet.name, None])
for bt in bouquet.bouquets:
name, bt_type = bt.name, bt.type
model.append(parent, [name, bt_type])
__bouquets["{}:{}".format(name, bt_type)] = bt.services
except Exception as e:
__status_bar.push(1, getattr(e, "message", repr(e)))
@@ -239,12 +246,15 @@ def on_data_open(model):
def on_data_save(*args):
# Perhaps needs a dialog to choose what we need to save!!!
if is_bouquet_selected() and __fav_view.is_focus(): # bouquets
bouquet_name = is_bouquet_selected()
path = __options["data_dir_path"]
if bouquet_name and __fav_view.is_focus(): # bouquets
fav_ids = []
__fav_model.foreach(lambda model, path, itr: fav_ids.append(model.get(model.get_iter(path), 4)))
print(fav_ids)
__fav_model.foreach(lambda model, p, itr: fav_ids.append(model.get(model.get_iter(p), 4)))
channels = [__channels[fav_id[0]] for fav_id in fav_ids]
write_bouquet(path, bouquet_name, channels)
elif __services_view.is_focus():
pass
write_channels(path, __channels.values())
def on_services_selection(model, path, column):
@@ -259,22 +269,30 @@ def on_bouquets_selection(model, path, column):
__fav_model.clear()
if len(path) > 1:
delete_selection(__services_view)
tree_iter = model.get_iter(path)
name = model.get_value(tree_iter, 0)
# 'tv' Temporary! It is necessary to implement a row type attribute.
bq = get_bouquet(__options["data_dir_path"], name, SERVICE_TYPE[1].lower())
for num, ch_id in enumerate(bq):
channel = __channels.get(ch_id, None)
update_bouquet_channels(model, path)
def update_bouquet_channels(model, path):
""" Updates list of bouquet channels """
tree_iter = model.get_iter(path)
key = "{}:{}".format(*model.get(tree_iter, 0, 1))
services = __bouquets[key]
for num, ch_id in enumerate(services):
channel = __channels.get(ch_id, None)
if channel:
__fav_model.append((num + 1, channel.service, channel.service_type, channel.pos, channel.fav_id))
def is_bouquet_selected():
""" Checks whether the bouquet is selected """
""" Checks whether the bouquet is selected
returns name of selected bouquet or False
"""
selection = __bouquets_view.get_selection()
model, path = selection.get_selected_rows()
if len(path) < 1:
if len(path) < 1 or model.iter_has_child(model.get_iter(path)):
return False
return not model.iter_has_child(model.get_iter(path))
return model.get_value(model.get_iter(path), 0)
def show_message_dialog(text):

View File

@@ -29,6 +29,8 @@
<columns>
<!-- column-name bouquet -->
<column type="gchararray"/>
<!-- column-name type -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkListStore" id="fav_list_store">
@@ -697,7 +699,9 @@
<property name="reorderable">True</property>
<property name="sort_column_id">2</property>
<child>
<object class="GtkCellRendererText" id="type_cellrenderertex"/>
<object class="GtkCellRendererText" id="type_cellrenderertex">
<property name="xalign">0.51999998092651367</property>
</object>
<attributes>
<attribute name="text">2</attribute>
</attributes>
@@ -713,7 +717,9 @@
<property name="reorderable">True</property>
<property name="sort_column_id">3</property>
<child>
<object class="GtkCellRendererText" id="ssid_cellrenderertext"/>
<object class="GtkCellRendererText" id="ssid_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">3</attribute>
</attributes>
@@ -729,7 +735,9 @@
<property name="reorderable">True</property>
<property name="sort_column_id">4</property>
<child>
<object class="GtkCellRendererText" id="freq_cellrenderertext"/>
<object class="GtkCellRendererText" id="freq_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">4</attribute>
</attributes>
@@ -745,7 +753,9 @@
<property name="reorderable">True</property>
<property name="sort_column_id">5</property>
<child>
<object class="GtkCellRendererText" id="rate_cellrenderertext"/>
<object class="GtkCellRendererText" id="rate_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">5</attribute>
</attributes>
@@ -761,7 +771,9 @@
<property name="reorderable">True</property>
<property name="sort_column_id">6</property>
<child>
<object class="GtkCellRendererText" id="pol_cellrenderertext"/>
<object class="GtkCellRendererText" id="pol_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">6</attribute>
</attributes>
@@ -777,7 +789,9 @@
<property name="reorderable">True</property>
<property name="sort_column_id">7</property>
<child>
<object class="GtkCellRendererText" id="fec_cellrenderertext"/>
<object class="GtkCellRendererText" id="fec_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">7</attribute>
</attributes>
@@ -793,7 +807,9 @@
<property name="reorderable">True</property>
<property name="sort_column_id">8</property>
<child>
<object class="GtkCellRendererText" id="system_cellrenderertex"/>
<object class="GtkCellRendererText" id="system_cellrenderertex">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">8</attribute>
</attributes>
@@ -807,7 +823,9 @@
<property name="expand">True</property>
<property name="sort_column_id">9</property>
<child>
<object class="GtkCellRendererText" id="pos_cellrenderertext1"/>
<object class="GtkCellRendererText" id="pos_cellrenderertext1">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">9</attribute>
</attributes>
@@ -909,7 +927,9 @@
<property name="title" translatable="yes">Type</property>
<property name="expand">True</property>
<child>
<object class="GtkCellRendererText" id="type_cellrenderertext"/>
<object class="GtkCellRendererText" id="type_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">2</attribute>
</attributes>
@@ -921,7 +941,9 @@
<property name="title" translatable="yes">Pos</property>
<property name="expand">True</property>
<child>
<object class="GtkCellRendererText" id="pos_cellrenderertext"/>
<object class="GtkCellRendererText" id="pos_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">3</attribute>
</attributes>
@@ -945,7 +967,7 @@
</object>
<packing>
<property name="resize">True</property>
<property name="shrink">False</property>
<property name="shrink">True</property>
</packing>
</child>
<child>
@@ -969,22 +991,36 @@
<child>
<object class="GtkTreeViewColumn" id="bouquets_column">
<property name="resizable">True</property>
<property name="sizing">autosize</property>
<property name="title" translatable="yes">Bouquets</property>
<property name="expand">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<object class="GtkCellRendererText" id="bouquets_cellrenderertext"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="bouquet_type_column">
<property name="resizable">True</property>
<property name="sizing">autosize</property>
<property name="title" translatable="yes">Type</property>
<child>
<object class="GtkCellRendererText" id="bouquet_type_cellrenderertext"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="resize">True</property>
<property name="shrink">True</property>
<property name="shrink">False</property>
</packing>
</child>
</object>
@@ -1043,7 +1079,7 @@
<property name="version">0.1 Pre-alpha</property>
<property name="copyright" translatable="yes">2017 Dmitriy Yefremov
</property>
<property name="comments" translatable="yes">Enigma2 channel list editor for GNU/Linux</property>
<property name="comments" translatable="yes">Enigma2 channel and satellites list editor for GNU/Linux</property>
<property name="authors">Dmitriy Yefremov
</property>
<property name="logo_icon_name">accessories-text-editor</property>