2025-02-18 15:43:02

This commit is contained in:
Christian Moser 2025-02-18 15:43:02 +01:00
parent 094928e187
commit fed28c8b23
Failed to extract signature

View File

@ -16,11 +16,15 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # # along with this program. If not, see <https://www.gnu.org/licenses/>. #
############################################################################### ###############################################################################
from gi.repository import Gtk,GLib from gi.repository import Gtk,GLib,GObject,Gio
from ..game import GameManager,Game from ..game import GameManager,Game
from ..archiver import ArchiverManager from ..archiver import ArchiverManager
from threading import Thread,ThreadError from threading import Thread,ThreadError
import logging
logger = logging.getLogger(__name__)
class BackupSingleDialog(Gtk.Dialog): class BackupSingleDialog(Gtk.Dialog):
def __init__(self,parent:Gtk.Window,game:Game): def __init__(self,parent:Gtk.Window,game:Game):
Gtk.Dialog.__init__(self) Gtk.Dialog.__init__(self)
@ -98,3 +102,60 @@ class BackupSingleDialog(Gtk.Dialog):
thread = Thread(target=_thread_func,args=(am,self.__game),daemon=True) thread = Thread(target=_thread_func,args=(am,self.__game),daemon=True)
thread.start() thread.start()
class BackupGameData(GObject.GObject):
def __init__(self,game:Game):
GObject.__init__(self)
self.__progress = 0.0
self.__game = game
@GObject.Property
def game(self)->Game:
return self.__game
@GObject.Property(type=float)
def progress(self)->float:
return self.__progress
@progress.setter
def progress(self,fraction:float):
if fraction < 0.0:
fraction = 0.0
elif fraction > 1.0:
fraction = 1.0
self.__progress = fraction
class BackupMultiDialog(Gtk.Dialog):
logger = logger.getChild('BackupMultiDialog')
def __init__(self,parent:Gtk.Window|None=None,games:list[Game]|None=None):
Gtk.Dialog.__init__(self)
if parent:
self.set_transient_for(parent)
self.__scrolled = Gtk.ScrolledWindow()
self.__games_liststore = Gio.Liststore(BackupGameData)
self.__ok_button = self.add_button("Close",Gtk.ResponseType.OK)
self.games = games
@GObject.Property
def games(self)->list[Game]:
return self.__games
@games.setter
def games(self,games:list[Game]|None):
self.__games = []
if games:
for g in games:
if not isinstance(g,Game):
self.__games = []
raise TypeError("\"games\" is not an Iterable of \"Game\" instances!")
if g.get_backup_files():
self.__games.append(Game)
if self.__games:
self.__ok_button.set_sensitive(False)
else:
self.__ok_button.set_sensitive(True)