diff --git a/dsst/dsst_gtk3/dialogs.py b/dsst/dsst_gtk3/dialogs.py
index e0a8f16..3793ef9 100644
--- a/dsst/dsst_gtk3/dialogs.py
+++ b/dsst/dsst_gtk3/dialogs.py
@@ -148,3 +148,41 @@ def show_edit_death_dialog(builder: Gtk.Builder, episode_id: int, death: sql.Dea
sql.Penalty.create(size=size, player=entry[3], death=death.id, drink=drink_id)
return result
+
+
+def show_edit_victory_dialog(builder: Gtk.Builder, episode_id: int, victory: sql.Victory=None):
+ """Show a dialog for editing or creating victory events.
+ :param builder: A Gtk.Builder object
+ :param episode_id: ID to witch the victory event belongs to
+ :param victory: (Optional) Victory event witch should be edited
+ :return: Gtk.ResponseType of the dialog
+ """
+ dialog = builder.get_object("edit_victory_dialog") # type: Gtk.Dialog
+ dialog.set_transient_for(builder.get_object("main_window"))
+ with sql.db.atomic():
+ if victory:
+ infos = [['edit_victory_player_combo', victory.player.id],
+ ['edit_victory_enemy_combo', victory.enemy.id]]
+ for info in infos:
+ combo = builder.get_object(info[0])
+ index = util.Util.get_index_of_combo_model(combo, 0, info[1])
+ combo.set_active(index)
+ builder.get_object('victory_comment_entry').set_text(victory.info)
+
+ # Run the dialog
+ result = dialog.run()
+ dialog.hide()
+ if result != Gtk.ResponseType.OK:
+ sql.db.rollback()
+ return result
+
+ # Collect info from widgets and save to database
+ player_id = util.Util.get_combo_value(builder.get_object('edit_victory_player_combo'), 0)
+ enemy_id = util.Util.get_combo_value(builder.get_object('edit_victory_enemy_combo'), 3)
+ comment = builder.get_object('victory_comment_entry').get_text()
+ if not victory:
+ sql.Victory.create(episode=episode_id, player=player_id, enemy=enemy_id, info=comment)
+ else:
+ victory.update(player=player_id, enemy=enemy_id, info=comment).execute()
+
+ return result
\ No newline at end of file
diff --git a/dsst/dsst_gtk3/gtk_ui.py b/dsst/dsst_gtk3/gtk_ui.py
index 83804cf..5e24631 100644
--- a/dsst/dsst_gtk3/gtk_ui.py
+++ b/dsst/dsst_gtk3/gtk_ui.py
@@ -104,8 +104,14 @@ class GtkUi:
penalties = [f'{number}x {drink}' for drink, number in Counter(penalties).items()]
penalty_string = ', '.join(penalties)
store.append([death.id, death.player.name, death.enemy.name, penalty_string])
+ # Reload victory store for notebook view
+ store = self.ui.get_object('episode_victories_store')
+ store.clear()
+ for victory in episode.victories:
+ store.append([victory.id, victory.player.name, victory.enemy.name, victory.info])
# Stat grid
+ self.ui.get_object('ep_stat_title').set_text('Stats for episode {}\n"{}"'.format(episode.number, episode.name))
self.ui.get_object('ep_death_count_label').set_text(str(len(episode.deaths)))
drink_count = sum(len(death.penalties) for death in episode.deaths)
self.ui.get_object('ep_drinks_label').set_text(str(drink_count))
diff --git a/dsst/dsst_gtk3/handlers/handlers.py b/dsst/dsst_gtk3/handlers/handlers.py
index ef57755..09ade40 100644
--- a/dsst/dsst_gtk3/handlers/handlers.py
+++ b/dsst/dsst_gtk3/handlers/handlers.py
@@ -5,10 +5,11 @@ from dsst_gtk3.handlers.season_handlers import SeasonHandlers
from dsst_gtk3.handlers.base_data_handlers import BaseDataHandlers
from dsst_gtk3.handlers.dialog_handlers import DialogHandlers
from dsst_gtk3.handlers.death_handlers import DeathHandlers
+from dsst_gtk3.handlers.victory_handlers import VictoryHandlers
from dsst_sql import sql_func
-class Handlers(SeasonHandlers, BaseDataHandlers, DialogHandlers, DeathHandlers):
+class Handlers(SeasonHandlers, BaseDataHandlers, DialogHandlers, DeathHandlers, VictoryHandlers):
"""Single callback handler class derived from specialized handler classes"""
def __init__(self, app):
""" Initialize handler class
@@ -20,6 +21,7 @@ class Handlers(SeasonHandlers, BaseDataHandlers, DialogHandlers, DeathHandlers):
BaseDataHandlers.__init__(self, app)
DialogHandlers.__init__(self, app)
DeathHandlers.__init__(self, app)
+ VictoryHandlers.__init__(self, app)
@staticmethod
def do_delete_event(*args):
diff --git a/dsst/dsst_gtk3/handlers/victory_handlers.py b/dsst/dsst_gtk3/handlers/victory_handlers.py
new file mode 100644
index 0000000..46627d9
--- /dev/null
+++ b/dsst/dsst_gtk3/handlers/victory_handlers.py
@@ -0,0 +1,17 @@
+from gi.repository import Gtk
+from dsst_gtk3 import dialogs, gtk_ui
+
+
+class VictoryHandlers:
+ """Callback handlers for signals related to managing victory events"""
+ def __init__(self, app: 'gtk_ui.GtkUi'):
+ self.app = app
+
+ def do_add_victory(self, *_):
+ ep_id = self.app.get_selected_episode_id()
+ if not ep_id:
+ return
+ result = dialogs.show_edit_victory_dialog(self.app.ui, ep_id)
+ if result == Gtk.ResponseType.OK:
+ self.app.reload_for_season()
+ self.app.reload_for_episode()
\ No newline at end of file
diff --git a/dsst/dsst_gtk3/resources/glade/window.glade b/dsst/dsst_gtk3/resources/glade/window.glade
index 3d00e28..e9d9684 100644
--- a/dsst/dsst_gtk3/resources/glade/window.glade
+++ b/dsst/dsst_gtk3/resources/glade/window.glade
@@ -22,6 +22,204 @@
+
@@ -511,7 +709,18 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1270,6 +1479,7 @@
False
Add Victory
True
+
@@ -1569,7 +1779,7 @@
False
vertical
-
+
True
False
[Episode Stats]
@@ -1841,6 +2051,9 @@
Player
+
+ 1
+
@@ -1849,6 +2062,20 @@
Enemy
+
+ 2
+
+
+
+
+
+
+ Comment
+
+
+
+ 3
+