diff --git a/main/ftp.py b/main/ftp.py index 0e26f5a2..d9d50a8c 100644 --- a/main/ftp.py +++ b/main/ftp.py @@ -32,9 +32,6 @@ def download_data(*, properties): with open(save_path + xml_file, 'wb') as f: ftp.retrbinary('RETR ' + xml_file, f.write) - for name in os.listdir(save_path): - print(name) - return ftp.voidcmd("NOOP") diff --git a/main/ui/dialogs.glade b/main/ui/dialogs.glade index cde50082..45ee236e 100644 --- a/main/ui/dialogs.glade +++ b/main/ui/dialogs.glade @@ -101,4 +101,388 @@ dmitry.v.yefremov@gmail.com + + False + Options + False + True + preferences-desktop + dialog + + + False + 5 + vertical + 2 + + + False + end + end + + + gtk-undo + True + True + True + True + + + True + True + 2 + + + + + gtk-ok + True + True + True + True + + + True + True + 3 + + + + + False + False + 0 + + + + + True + False + True + + + 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 + emblem-personal + False + + + 0 + 3 + + + + + True + True + False + + root + emblem-nowrite + False + password + + + 1 + 3 + + + + + False + True + 0 + + + + + True + False + 2 + 2 + + + False + True + 1 + + + + + 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 + 2 + + + + + True + False + 2 + + + False + True + 3 + + + + + True + False + True + + + True + False + Data directory: + 0 + + + 0 + 0 + + + + + True + True + /data + gtk-open + False + Select + Select + + + + 0 + 1 + + + + + False + True + 5 + + + + + True + False + + + False + True + 2 + 6 + + + + + + cancel_button + ok_button + + + + False + + document-open + dialog + settings_dialog + save + + + False + vertical + 2 + + + False + end + + + gtk-undo + True + True + True + True + + + True + True + 0 + + + + + gtk-ok + True + True + True + True + 0.55000001192092896 + + + True + True + 1 + + + + + False + False + 0 + + + + + + + + + button2 + button1 + + diff --git a/main/ui/main_app_window.py b/main/ui/main_app_window.py index 42d3276e..00ccc856 100644 --- a/main/ui/main_app_window.py +++ b/main/ui/main_app_window.py @@ -27,6 +27,8 @@ __bouquets_view = None __rows_buffer = [] __channels = {} __bouquets = {} +# dynamically active elements depending on the selected view +__tool_elements = None def on_about_app(item): @@ -58,7 +60,8 @@ def get_handlers(): "on_services_tree_view_drag_data_get": on_services_tree_view_drag_data_get, "on_fav_tree_view_drag_data_get": on_fav_tree_view_drag_data_get, "on_fav_tree_view_drag_data_received": on_fav_tree_view_drag_data_received, - "on_view_popup_menu": on_view_popup_menu + "on_view_popup_menu": on_view_popup_menu, + "on_view_focus": on_view_focus } @@ -282,28 +285,35 @@ def on_satellite_editor_show(model): @run_task def on_data_open(model): + if show_dialog("path_chooser_dialog") == Gtk.ResponseType.CANCEL: + return + + open_data() + + +def open_data(): + """ Opening data and fill views. """ try: - model.clear() + __bouquets_model.clear() __fav_model.clear() - model_name = model.get_name() - data_path = get_config()["data_dir_path"] + __services_model.clear() + data_path = __options["data_dir_path"] - if model_name == SERVICE_LIST_NAME: - for ch in get_channels(data_path + "lamedb"): - # adding channels to dict with fav_id as keys - __channels[ch.fav_id] = ch - model.append(ch) + for ch in get_channels(data_path + "lamedb"): + # adding channels to dict with fav_id as keys + __channels[ch.fav_id] = ch + __services_model.append(ch) - if model_name == BOUQUETS_LIST_NAME: - bouquets = get_bouquets(data_path) - for bouquet in bouquets: - parent = model.append(None, [bouquet.name, bouquet.type]) - 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 + bouquets = get_bouquets(data_path) + for bouquet in bouquets: + parent = __bouquets_model.append(None, [bouquet.name, bouquet.type]) + for bt in bouquet.bouquets: + name, bt_type = bt.name, bt.type + __bouquets_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))) + raise e # temp for debug @run_task @@ -394,6 +404,8 @@ def show_dialog(dialog_name, text=None): dialog.set_transient_for(__main_window) if text: dialog.set_markup(text) + if dialog_name == "path_chooser_dialog": + dialog.set_current_folder(__options["data_dir_path"]) response = dialog.run() dialog.destroy() @@ -432,18 +444,48 @@ def on_tree_view_key_release(view, event): on_paste(view) +@run_task def on_upload(item): connect(__options, False) +@run_task def on_download(item): connect(__options) + open_data() def on_reload(item): pass +def on_view_focus(view, focus_event): + model = view.get_model() + model_name = model.get_name() + + empty = len(model) == 0 # if > 0 model has items + + if empty: + return + + fav_elements = ("up_tool_button", "down_tool_button", "cut_tool_button", "paste_tool_button") + service_elements = ("copy_tool_button", "to_fav_tool_button") + + if model_name == BOUQUETS_LIST_NAME: + for elem in __tool_elements: + __tool_elements[elem].set_sensitive(False) + __tool_elements["new_tool_button"].set_sensitive(True) + else: + is_service = model_name == SERVICE_LIST_NAME + for elem in fav_elements: + __tool_elements[elem].set_sensitive(not is_service) + for elem in service_elements: + __tool_elements[elem].set_sensitive(is_service) + __tool_elements["new_tool_button"].set_sensitive(False) + + __tool_elements["remove_tool_button"].set_sensitive(not empty) + + def connect(properties, download=True): try: res = download_data(properties=properties) if download else upload_data(properties=properties) @@ -470,8 +512,18 @@ def init_ui(): __bouquets_view = builder.get_object("bouquets_tree_view") global __fav_model __fav_model = builder.get_object("fav_list_store") + global __services_model + __services_model = builder.get_object("services_list_store") + global __bouquets_model + __bouquets_model = builder.get_object("bouquets_tree_store") global __status_bar __status_bar = builder.get_object("status_bar") + # dynamically active elements depending on the selected view + global __tool_elements + __tool_elements = {k: builder.get_object(k) for k in ("up_tool_button", "down_tool_button", + "cut_tool_button", "copy_tool_button", + "paste_tool_button", "to_fav_tool_button", + "new_tool_button", "remove_tool_button")} builder.connect_signals(get_handlers()) init_drag_and_drop() # drag and drop __main_window.show_all() diff --git a/main/ui/main_window.glade b/main/ui/main_window.glade index ed4da9b3..137d14f5 100644 --- a/main/ui/main_window.glade +++ b/main/ui/main_window.glade @@ -364,8 +364,7 @@ Open True gtk-open - - + False @@ -448,6 +447,7 @@ True + False False Move True @@ -472,6 +472,7 @@ True + False False Up True @@ -486,6 +487,7 @@ True + False False Down True @@ -500,6 +502,7 @@ True + False False Cut True @@ -514,6 +517,7 @@ True + False False Copy True @@ -528,6 +532,7 @@ True + False False Paste True @@ -539,9 +544,34 @@ True + + + True + False + + + False + False + + + + + True + False + False + New + True + gtk-new + + + False + True + + True + False False Remove True @@ -658,6 +688,7 @@ True + @@ -933,6 +964,8 @@ + + @@ -1030,6 +1063,7 @@ False True + diff --git a/main/ui/settings_dialog.glade b/main/ui/settings_dialog.glade deleted file mode 100644 index 16e4bb79..00000000 --- a/main/ui/settings_dialog.glade +++ /dev/null @@ -1,388 +0,0 @@ - - - - - - False - Options - False - True - preferences-desktop - dialog - - - False - 5 - vertical - 2 - - - False - end - end - - - gtk-undo - True - True - True - True - - - True - True - 2 - - - - - gtk-ok - True - True - True - True - - - True - True - 3 - - - - - False - False - 0 - - - - - True - False - True - - - 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 - emblem-personal - False - - - 0 - 3 - - - - - True - True - False - - root - emblem-nowrite - False - password - - - 1 - 3 - - - - - False - True - 0 - - - - - True - False - 2 - 2 - - - False - True - 1 - - - - - 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 - 2 - - - - - True - False - 2 - - - False - True - 3 - - - - - True - False - True - - - True - False - Data directory: - 0 - - - 0 - 0 - - - - - True - True - /data - gtk-open - False - Select - Select - - - - 0 - 1 - - - - - False - True - 5 - - - - - True - False - - - False - True - 2 - 6 - - - - - - cancel_button - ok_button - - - - False - - dialog - settings_dialog - save - - - False - vertical - 2 - - - False - end - - - gtk-undo - True - True - True - True - - - True - True - 0 - - - - - gtk-ok - True - True - True - True - 0.55000001192092896 - - - True - True - 1 - - - - - False - False - 0 - - - - - - - - - button2 - button1 - - - diff --git a/main/ui/settings_dialog.py b/main/ui/settings_dialog.py index 4e71bc3b..021f35e4 100644 --- a/main/ui/settings_dialog.py +++ b/main/ui/settings_dialog.py @@ -7,7 +7,7 @@ __current_data_path = "" def show_settings_dialog(transient, options): handlers = {"on_data_dir_field_icon_press": on_data_dir_field_icon_press} builder = Gtk.Builder() - builder.add_from_file("ui/settings_dialog.glade") + builder.add_from_file("ui/dialogs.glade") builder.connect_signals(handlers) dialog = builder.get_object("settings_dialog") dialog.set_transient_for(transient) @@ -43,14 +43,14 @@ def show_settings_dialog(transient, options): dialog.destroy() -def on_data_dir_field_icon_press(*args): +def on_data_dir_field_icon_press(entry, icon, event_button): builder = Gtk.Builder() - builder.add_from_file("ui/settings_dialog.glade") + builder.add_from_file("ui/dialogs.glade") dialog = builder.get_object("path_chooser_dialog") dialog.set_current_folder(__current_data_path) response = dialog.run() - if response == -12: # for fix assertion 'gtk_widget_get_can_default (widget)' failed - args[0].set_text(dialog.get_filename()) + if response == -12: # -12 for fix assertion 'gtk_widget_get_can_default (widget)' failed + entry.set_text(dialog.get_filename() if dialog.get_filename() else __current_data_path) dialog.destroy() return response