Example #1
0
    def on_startup(self, app):
        """
        Startup function.
        Loads the GtkBuilder resources, settings and start the main loop.
        """

        try:
            # Load settings
            helpers.debug_msg([GTK_MSG, i18n._("Obozrenie is starting")])
            guiactions = self.guiactions

            self.status = "starting"
            guiactions.fill_game_store()

            self.settings.load(
                callback_postgenload=self.guiactions.cb_post_settings_genload)

            # Connect signals
            self.builder.connect_signals(self.guiactions)
            guiactions.gtk_widgets["server-list-filter"].set_visible_func(
                guiactions.server_filter_func)

            gtk_helpers.set_widget_value(
                self.guiactions.gtk_widgets["game-combobox"],
                self.settings.settings_table["common"]
                ["selected-game-browser"])
            for entry in self.guiactions.filter_secure_list:
                guiactions.gtk_widgets["filter-secure"].append(
                    entry["id"], entry["text"])
            guiactions.cb_game_treeview_togglebutton_clicked()
            guiactions.cb_server_filters_changed()
            try:
                guiactions.cb_server_connect_data_changed()
            except ValueError:
                pass

            # Add main window
            main_window = self.guiactions.gtk_widgets["main-window"]
            self.add_window(main_window)

            # Create menu actions
            about_action = Gio.SimpleAction.new("about", None)
            quit_action = Gio.SimpleAction.new("quit", None)

            about_action.connect("activate", self.guiactions.cb_about,
                                 main_window)
            quit_action.connect("activate", self.guiactions.cb_quit, self)

            self.add_action(about_action)
            self.add_action(quit_action)

            self.set_app_menu(self.builder.get_object("app-menu"))

            gtk_helpers.set_object_properties(self.guiactions.gtk_widgets,
                                              GTK_STRING_TABLE)

            self.status = "up"
        except Exception as e:
            app.quit()
            raise e
Example #2
0
    def cb_post_settings_genload(self, widget_table, group, option, value):
        self.widget_table = widget_table
        widget_name = widget_table[group][option]["gtk_widget_name"]
        widget = self.builder.get_object(widget_name)

        gtk_helpers.set_widget_value(widget, value)
        gtk_helpers.bind_widget_to_callback(widget, self.update_settings_table)
Example #3
0
    def cb_post_settings_genload(self, widget_table, group, option, value):
        self.widget_table = widget_table
        widget_name = widget_table[group][option]["gtk_widget_name"]
        widget = self.builder.get_object(widget_name)

        gtk_helpers.set_widget_value(widget, value)
        gtk_helpers.bind_widget_to_callback(widget, self.update_settings_table)
Example #4
0
    def cb_game_combobox_changed(self, *args):
        """Actions on game combobox selection change."""
        combobox = self.gtk_widgets["game-combobox"]
        treeview = self.gtk_widgets["game-treeview"]
        game_id = gtk_helpers.get_widget_value(combobox)
        game_id_colnum = self.game_list_model_format.index("game_id")

        gtk_helpers.set_widget_value(treeview, game_id, treeview_colnum=game_id_colnum)
Example #5
0
    def fill_server_list_model(self, server_table):
        """Fill the server view"""

        view_table = helpers.deepcopy(server_table)

        model = self.gtk_widgets["server-list-model"]
        model_append = model.append
        model_format = self.server_list_model_format

        game_icons = self.game_icons
        flag_icons = self.flag_icons

        # Clears the model

        # UGLY HACK!
        # Workaround for chaotic TreeViewSelection on ListModel erase
        host_selection = gtk_helpers.get_widget_value(
            self.gtk_widgets["server-connect-host"])
        game_selection = gtk_helpers.get_widget_value(
            self.gtk_widgets["server-connect-game"])
        model.clear()
        gtk_helpers.set_widget_value(self.gtk_widgets["server-connect-host"],
                                     host_selection)
        gtk_helpers.set_widget_value(
            self.gtk_widgets["server-connect-game"],
            game_selection,
            treeview_colnum=self.game_list_model_format.index("game_id"))

        # Goodies for GUI
        for entry in view_table:
            game_id = entry.get("game_id")
            country = entry.get("country")
            # Game icon
            entry["game_icon"] = game_icons.get(game_id)

            # Lock icon
            if entry["password"] is True:
                entry["password_icon"] = "network-wireless-encrypted-symbolic"
            else:
                entry["password_icon"] = None

            if entry["secure"] is True:
                entry["secure_icon"] = "security-high-symbolic"
            else:
                entry["secure_icon"] = None

            # Country flags
            entry["country_icon"] = flag_icons.get(country)

            # Filtering stuff
            entry["full"] = entry["player_count"] >= entry["player_limit"]
            entry["empty"] = entry["player_count"] == 0

        view_table = helpers.sort_dict_table(view_table, "ping")
        server_list = helpers.dict_to_list(view_table, model_format)

        for entry in server_list:
            model_append(entry)
Example #6
0
 def apply_settings_to_preferences_dialog(
         self, game: str, widget_option_mapping: dict,
         dynamic_settings_table: dict) -> None:
     for option in widget_option_mapping:
         value = self.core.game_table.get_game_settings(game)[option]
         if dynamic_settings_table[option][
                 "gtk_type"] == "Multiline Entry with Label":
             value = "\n".join(value)
         gtk_helpers.set_widget_value(widget_option_mapping[option], value)
Example #7
0
    def cb_game_combobox_changed(self, *args):
        """Actions on game combobox selection change."""
        combobox = self.gtk_widgets["game-combobox"]
        treeview = self.gtk_widgets["game-treeview"]
        game_id = gtk_helpers.get_widget_value(combobox)
        game_id_colnum = self.game_list_model_format.index("game_id")

        gtk_helpers.set_widget_value(treeview,
                                     game_id,
                                     treeview_colnum=game_id_colnum)
Example #8
0
    def cb_game_treeview_selection_changed(self, *args):
        game_id = self.app.settings.settings_table["common"]["selected-game-browser"]
        query_status = self.core.game_table.get_query_status(game_id)

        gtk_helpers.set_widget_value(self.gtk_widgets["game-combobox"], game_id)
        if query_status == self.core.game_table.QUERY_STATUS.EMPTY:  # Refresh server list on first access
            self.cb_update_button_clicked()
        else:
            if query_status == self.core.game_table.QUERY_STATUS.WORKING:
                self.set_loading_state("working")
            GLib.idle_add(self.show_game_page, game_id)
Example #9
0
    def on_startup(self, app):
        """
        Startup function.
        Loads the GtkBuilder resources, settings and start the main loop.
        """

        try:
            # Load settings
            helpers.debug_msg([GTK_MSG, i18n._("Obozrenie is starting")])
            guiactions = self.guiactions

            self.status = "starting"
            guiactions.fill_game_store()

            self.settings.load(callback_postgenload=self.guiactions.cb_post_settings_genload)

            # Connect signals
            self.builder.connect_signals(self.guiactions)
            guiactions.gtk_widgets["server-list-filter"].set_visible_func(guiactions.server_filter_func)

            gtk_helpers.set_widget_value(self.guiactions.gtk_widgets["game-combobox"], self.settings.settings_table["common"]["selected-game-browser"])
            for entry in self.guiactions.filter_secure_list:
                guiactions.gtk_widgets["filter-secure"].append(entry["id"], entry["text"])
            guiactions.cb_game_treeview_togglebutton_clicked()
            guiactions.cb_server_filters_changed()
            try:
                guiactions.cb_server_connect_data_changed()
            except ValueError:
                pass

            # Add main window
            main_window = self.guiactions.gtk_widgets["main-window"]
            self.add_window(main_window)

            # Create menu actions
            about_action = Gio.SimpleAction.new("about", None)
            quit_action = Gio.SimpleAction.new("quit", None)

            about_action.connect("activate", self.guiactions.cb_about, main_window)
            quit_action.connect("activate", self.guiactions.cb_quit, self)

            self.add_action(about_action)
            self.add_action(quit_action)

            self.set_app_menu(self.builder.get_object("app-menu"))

            gtk_helpers.set_object_properties(self.guiactions.gtk_widgets, GTK_STRING_TABLE)

            self.status = "up"
        except Exception as e:
            app.quit()
            raise e
Example #10
0
    def fill_server_list_model(self, server_table):
        """Fill the server view"""

        view_table = helpers.deepcopy(server_table)

        model = self.gtk_widgets["server-list-model"]
        model_append = model.append
        model_format = self.server_list_model_format

        game_icons = self.game_icons
        flag_icons = self.flag_icons

        # Clears the model

        # UGLY HACK!
        # Workaround for chaotic TreeViewSelection on ListModel erase
        host_selection = gtk_helpers.get_widget_value(self.gtk_widgets["server-connect-host"])
        game_selection = gtk_helpers.get_widget_value(self.gtk_widgets["server-connect-game"])
        model.clear()
        gtk_helpers.set_widget_value(self.gtk_widgets["server-connect-host"], host_selection)
        gtk_helpers.set_widget_value(self.gtk_widgets["server-connect-game"], game_selection, treeview_colnum=self.game_list_model_format.index("game_id"))

        # Goodies for GUI
        for entry in view_table:
            game_id = entry.get("game_id")
            country = entry.get("country")
            # Game icon
            entry["game_icon"] = game_icons.get(game_id)

            # Lock icon
            if entry["password"] is True:
                entry["password_icon"] = "network-wireless-encrypted-symbolic"
            else:
                entry["password_icon"] = None

            if entry["secure"] is True:
                entry["secure_icon"] = "security-high-symbolic"
            else:
                entry["secure_icon"] = None

            # Country flags
            entry["country_icon"] = flag_icons.get(country)

            # Filtering stuff
            entry["full"] = entry["player_count"] >= entry["player_limit"]
            entry["empty"] = entry["player_count"] == 0

        view_table = helpers.sort_dict_table(view_table, "ping")
        server_list = helpers.dict_to_list(view_table, model_format)

        for entry in server_list:
            model_append(entry)
Example #11
0
    def cb_game_treeview_selection_changed(self, *args):
        game_id = self.app.settings.settings_table["common"][
            "selected-game-browser"]
        query_status = self.core.game_table.get_query_status(game_id)

        gtk_helpers.set_widget_value(self.gtk_widgets["game-combobox"],
                                     game_id)
        if query_status == self.core.game_table.QUERY_STATUS.EMPTY:  # Refresh server list on first access
            self.cb_update_button_clicked()
        else:
            if query_status == self.core.game_table.QUERY_STATUS.WORKING:
                self.set_loading_state("working")
            GLib.idle_add(self.show_game_page, game_id)
Example #12
0
    def cb_server_list_selection_changed(self, *args):
        """Updates text in Entry on TreeView selection change."""
        entry_field = self.gtk_widgets["server-connect-host"]
        game_selection = self.gtk_widgets["server-connect-game"]
        treeview = self.gtk_widgets["serverlist-view"]

        try:
            text = gtk_helpers.get_widget_value(treeview)[self.server_list_model_format.index("host")]
            game = gtk_helpers.get_widget_value(treeview)[self.server_list_model_format.index("game_id")]

            gtk_helpers.set_widget_value(entry_field, text)
            gtk_helpers.set_widget_value(game_selection, game, treeview_colnum=self.game_list_model_format.index("game_id"))
        except:
            pass
Example #13
0
    def cb_server_list_selection_changed(self, *args):
        """Updates text in Entry on TreeView selection change."""
        entry_field = self.gtk_widgets["server-connect-host"]
        game_selection = self.gtk_widgets["server-connect-game"]
        treeview = self.gtk_widgets["serverlist-view"]

        try:
            text = gtk_helpers.get_widget_value(treeview)[
                self.server_list_model_format.index("host")]
            game = gtk_helpers.get_widget_value(treeview)[
                self.server_list_model_format.index("game_id")]

            gtk_helpers.set_widget_value(entry_field, text)
            gtk_helpers.set_widget_value(
                game_selection,
                game,
                treeview_colnum=self.game_list_model_format.index("game_id"))
        except:
            pass
Example #14
0
 def apply_settings_to_preferences_dialog(self, game: str, widget_option_mapping: dict, dynamic_settings_table: dict) -> None:
     for option in widget_option_mapping:
         value = self.core.game_table.get_game_settings(game)[option]
         if dynamic_settings_table[option]["gtk_type"] == "Multiline Entry with Label":
             value = "\n".join(value)
         gtk_helpers.set_widget_value(widget_option_mapping[option], value)
Example #15
0
    def cb_info_button_clicked(self, *args):
        """Shows server information window."""
        dialog = self.gtk_widgets["serverinfo-dialog"]

        game_table = self.core.game_table.get_game_table_copy()
        game = self.app.settings.settings_table["common"]["selected-game-connect"]
        server_list_table = game_table[game]["servers"]
        host = self.app.settings.settings_table["common"]["server-host"]
        server_entry_index = helpers.search_dict_table(server_list_table, "host", host)
        if server_entry_index is not None:
            server_entry = server_list_table[server_entry_index]
            player_model = self.gtk_widgets["player-list-model"]
            player_scrolledview = self.gtk_widgets["serverinfo-players-scrolledview"]

            gtk_helpers.set_widget_value(self.gtk_widgets["serverinfo-name"], server_entry["name"])
            gtk_helpers.set_widget_value(self.gtk_widgets["serverinfo-host"], server_entry["host"])
            gtk_helpers.set_widget_value(self.gtk_widgets["serverinfo-game"], game_table[server_entry["game_id"]]["info"]["name"])
            gtk_helpers.set_widget_value(self.gtk_widgets['serverinfo-gameid'], server_entry['game_id'])
            gtk_helpers.set_widget_value(self.gtk_widgets["serverinfo-terrain"], server_entry["terrain"])
            gtk_helpers.set_widget_value(self.gtk_widgets["serverinfo-players"], i18n._("%(player_count)s / %(player_limit)s") % {'player_count': str(server_entry["player_count"]), 'player_limit': str(server_entry["player_limit"])})
            gtk_helpers.set_widget_value(self.gtk_widgets["serverinfo-ping"], server_entry["ping"])

            player_model.clear()
            try:
                player_table = helpers.dict_to_list(server_entry["players"], self.player_list_model_format)
                for entry in player_table:
                    player_model.append(entry)
                player_scrolledview.set_property("visible", True)
            except:
                player_scrolledview.set_property("visible", False)

            dialog.run()
            dialog.hide()
Example #16
0
    def cb_info_button_clicked(self, *args):
        """Shows server information window."""
        dialog = self.gtk_widgets["serverinfo-dialog"]

        game_table = self.core.game_table.get_game_table_copy()
        game = self.app.settings.settings_table["common"][
            "selected-game-connect"]
        server_list_table = game_table[game]["servers"]
        host = self.app.settings.settings_table["common"]["server-host"]
        server_entry_index = helpers.search_dict_table(server_list_table,
                                                       "host", host)
        if server_entry_index is not None:
            server_entry = server_list_table[server_entry_index]
            player_model = self.gtk_widgets["player-list-model"]
            player_scrolledview = self.gtk_widgets[
                "serverinfo-players-scrolledview"]

            gtk_helpers.set_widget_value(self.gtk_widgets["serverinfo-name"],
                                         server_entry["name"])
            gtk_helpers.set_widget_value(self.gtk_widgets["serverinfo-host"],
                                         server_entry["host"])
            gtk_helpers.set_widget_value(
                self.gtk_widgets["serverinfo-game"],
                game_table[server_entry["game_id"]]["info"]["name"])
            gtk_helpers.set_widget_value(self.gtk_widgets['serverinfo-gameid'],
                                         server_entry['game_id'])
            gtk_helpers.set_widget_value(
                self.gtk_widgets["serverinfo-terrain"],
                server_entry["terrain"])
            gtk_helpers.set_widget_value(
                self.gtk_widgets["serverinfo-players"],
                i18n._("%(player_count)s / %(player_limit)s") % {
                    'player_count': str(server_entry["player_count"]),
                    'player_limit': str(server_entry["player_limit"])
                })
            gtk_helpers.set_widget_value(self.gtk_widgets["serverinfo-ping"],
                                         server_entry["ping"])

            player_model.clear()
            try:
                player_table = helpers.dict_to_list(
                    server_entry["players"], self.player_list_model_format)
                for entry in player_table:
                    player_model.append(entry)
                player_scrolledview.set_property("visible", True)
            except:
                player_scrolledview.set_property("visible", False)

            dialog.run()
            dialog.hide()