Data loading over socket.
This commit is contained in:
0
dsst/dsst_gtk3/handlers/__init__.py
Normal file
0
dsst/dsst_gtk3/handlers/__init__.py
Normal file
54
dsst/dsst_gtk3/handlers/base_data_handlers.py
Normal file
54
dsst/dsst_gtk3/handlers/base_data_handlers.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import sql
|
||||
from dsst_gtk3 import dialogs
|
||||
|
||||
|
||||
class BaseDataHandlers:
|
||||
"""Callback handlers for signals related to the manipulation of base data (players, drinks, ...)"""
|
||||
def __init__(self, app: 'gtk_ui.GtkUi'):
|
||||
self.app = app
|
||||
|
||||
def do_manage_players(self, *_):
|
||||
dialogs.show_manage_players_dialog(self.app.ui, 'Manage Players')
|
||||
|
||||
def do_add_player(self, entry):
|
||||
if entry.get_text():
|
||||
sql.Player.create(name=entry.get_text())
|
||||
entry.set_text('')
|
||||
self.app.reload()
|
||||
|
||||
def do_manage_enemies(self, *_):
|
||||
dialogs.show_manage_enemies_dialog(self.app.ui, self.app.get_selected_season_id())
|
||||
|
||||
def on_player_name_edited(self, _, index, value):
|
||||
row = self.app.ui.get_object('all_players_store')[index]
|
||||
sql.Player.update(name=value)\
|
||||
.where(sql.Player.id == row[0])\
|
||||
.execute()
|
||||
self.app.reload()
|
||||
|
||||
def on_player_hex_edited(self, _, index, value):
|
||||
row = self.app.ui.get_object('all_players_store')[index]
|
||||
sql.Player.update(hex_id=value)\
|
||||
.where(sql.Player.id == row[0])\
|
||||
.execute()
|
||||
self.app.reload()
|
||||
|
||||
def do_add_drink(self, entry):
|
||||
if entry.get_text():
|
||||
sql.Drink.create(name=entry.get_text(), vol=0)
|
||||
entry.set_text('')
|
||||
self.app.reload()
|
||||
|
||||
def on_drink_name_edited(self, _, index, value):
|
||||
row = self.app.ui.get_object('drink_store')[index]
|
||||
sql.Drink.update(name=value)\
|
||||
.where(sql.Drink.id == row[0])\
|
||||
.execute()
|
||||
self.app.reload()
|
||||
|
||||
def on_drink_vol_edited(self, _, index, value):
|
||||
row = self.app.ui.get_object('drink_store')[index]
|
||||
sql.Drink.update(vol=value) \
|
||||
.where(sql.Drink.id == row[0]) \
|
||||
.execute()
|
||||
self.app.reload()
|
||||
20
dsst/dsst_gtk3/handlers/death_handlers.py
Normal file
20
dsst/dsst_gtk3/handlers/death_handlers.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from gi.repository import Gtk
|
||||
|
||||
from dsst_gtk3 import dialogs
|
||||
|
||||
|
||||
class DeathHandlers:
|
||||
"""Callback handlers for signals related to managing death events"""
|
||||
def __init__(self, app: 'gtk_ui.GtkUi'):
|
||||
self.app = app
|
||||
|
||||
def do_add_death(self, *_):
|
||||
ep_id = self.app.get_selected_episode_id()
|
||||
if not ep_id:
|
||||
return
|
||||
result = dialogs.show_edit_death_dialog(self.app.ui, ep_id)
|
||||
if result == Gtk.ResponseType.OK:
|
||||
self.app.reload()
|
||||
|
||||
def on_penalty_drink_changed(self, _, path, text):
|
||||
self.app.ui.get_object('player_penalties_store')[path][2] = text
|
||||
30
dsst/dsst_gtk3/handlers/dialog_handlers.py
Normal file
30
dsst/dsst_gtk3/handlers/dialog_handlers.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import sql
|
||||
from dsst_gtk3 import dialogs, util
|
||||
|
||||
|
||||
class DialogHandlers:
|
||||
""" Callback handlers for signals emitted from dialogs of the main window"""
|
||||
def __init__(self, app: 'gtk_ui.GtkUi'):
|
||||
self.app = app
|
||||
|
||||
def do_add_player_to_episode(self, combo):
|
||||
""" Signal Handler for Add Player to Episode Button in Manage Episode Dialog
|
||||
:param combo: Combo box with all the available players
|
||||
"""
|
||||
player_id = util.get_combo_value(combo, 0)
|
||||
if player_id:
|
||||
self.app.ui.get_object('add_player_combo_box').set_active(-1)
|
||||
player = sql.Player.get(sql.Player.id == player_id)
|
||||
store = self.app.ui.get_object('episode_players_store')
|
||||
if not any(row[0] == player_id for row in store):
|
||||
store.append([player_id, player.name, player.hex_id])
|
||||
|
||||
def do_add_enemy(self, entry):
|
||||
if entry.get_text():
|
||||
store = self.app.ui.get_object('enemy_season_store')
|
||||
enemy = sql.Enemy.create(name=entry.get_text(), season=self.app.get_selected_season_id())
|
||||
store.append([enemy.name, False, 0, enemy.id])
|
||||
entry.set_text('')
|
||||
|
||||
def do_manage_drinks(self, *_):
|
||||
result = dialogs.show_manage_drinks_dialog(self.app.ui)
|
||||
40
dsst/dsst_gtk3/handlers/handlers.py
Normal file
40
dsst/dsst_gtk3/handlers/handlers.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
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
|
||||
import sql_func
|
||||
import sql
|
||||
|
||||
|
||||
class Handlers(SeasonHandlers, BaseDataHandlers, DialogHandlers, DeathHandlers, VictoryHandlers):
|
||||
"""Single callback handler class derived from specialized handler classes"""
|
||||
def __init__(self, app):
|
||||
""" Initialize handler class
|
||||
:param app: reference to the main application object
|
||||
"""
|
||||
self.app = app
|
||||
# Call constructors of superclasses
|
||||
SeasonHandlers.__init__(self, app)
|
||||
BaseDataHandlers.__init__(self, app)
|
||||
DialogHandlers.__init__(self, app)
|
||||
DeathHandlers.__init__(self, app)
|
||||
VictoryHandlers.__init__(self, app)
|
||||
|
||||
@staticmethod
|
||||
def do_delete_event(*_):
|
||||
""" Signal will be sent when app should close
|
||||
:param _: Arguments to the delete event
|
||||
"""
|
||||
sql.db.close()
|
||||
Gtk.main_quit()
|
||||
|
||||
# DEBUG Functions ##################################################################################################
|
||||
|
||||
@staticmethod
|
||||
def do_delete_database(*_):
|
||||
sql_func.drop_tables()
|
||||
sql_func.create_tables()
|
||||
30
dsst/dsst_gtk3/handlers/season_handlers.py
Normal file
30
dsst/dsst_gtk3/handlers/season_handlers.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from data_access import sql
|
||||
from dsst_gtk3 import dialogs
|
||||
|
||||
|
||||
class SeasonHandlers:
|
||||
"""Callback handlers related to signals for managing seasonal data"""
|
||||
def __init__(self, app: 'gtk_ui.GtkUi'):
|
||||
self.app = app
|
||||
|
||||
def do_add_season(self, *_):
|
||||
name = dialogs.enter_string_dialog(self.app.ui, 'Name for the new Season')
|
||||
if name:
|
||||
sql.Season.create(game_name=name, number=1)
|
||||
self.app.reload()
|
||||
|
||||
def do_season_selected(self, *_):
|
||||
self.app.reload()
|
||||
|
||||
def do_add_episode(self, *_):
|
||||
season_id = self.app.get_selected_season_id()
|
||||
if not season_id:
|
||||
return
|
||||
dialogs.show_episode_dialog(self.app.ui, 'Create new Episode', season_id)
|
||||
self.app.reload()
|
||||
|
||||
def on_selected_episode_changed(self, *_):
|
||||
self.app.reload()
|
||||
|
||||
def on_episode_double_click(self, *_):
|
||||
self.app.ui.get_object('stats_notebook').set_current_page(1)
|
||||
17
dsst/dsst_gtk3/handlers/victory_handlers.py
Normal file
17
dsst/dsst_gtk3/handlers/victory_handlers.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from gi.repository import Gtk
|
||||
|
||||
from dsst_gtk3 import dialogs
|
||||
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user