3030from gradia .ui .image_exporters import ExportManager
3131
3232
33- class GradientWindow :
33+ class GradientWindow (Adw .ApplicationWindow ):
34+ __gtype_name__ = 'GradientWindow'
35+
3436 DEFAULT_WINDOW_WIDTH : int = 900
3537 DEFAULT_WINDOW_HEIGHT : int = 600
3638 DEFAULT_PANED_POSITION : int = 650
@@ -44,8 +46,10 @@ class GradientWindow:
4446 # Temp file names
4547 TEMP_PROCESSED_FILENAME : str = "processed.png"
4648
47- def __init__ (self , app : Adw .Application , temp_dir : str , version : str ) -> None :
48- self .app : Adw .Application = app
49+ def __init__ (self , temp_dir : str , version : str , ** kwargs ) -> None :
50+ super ().__init__ (** kwargs )
51+
52+ self .app : Adw .Application = kwargs ['application' ]
4953 self .temp_dir : str = temp_dir
5054 self .version : str = version
5155 self .image_path : Optional [str ] = None
@@ -81,7 +85,7 @@ def __init__(self, app: Adw.Application, temp_dir: str, version: str) -> None:
8185 self .create_action ("save" , lambda * _ : self .export_manager .save_to_file (), ["<Primary>s" ], enabled = False )
8286 self .create_action ("copy" , lambda * _ : self .export_manager .copy_to_clipboard (), ["<Primary>c" ], enabled = False )
8387
84- self .create_action ("quit" , lambda * _ : self .win . close (), ["<Primary>q" ])
88+ self .create_action ("quit" , lambda * _ : self .close (), ["<Primary>q" ])
8589
8690 def create_action (self , name : str , callback : Callable [..., None ], shortcuts : Optional [list [str ]] = None , enabled : bool = True ) -> None :
8791 action : Gio .SimpleAction = Gio .SimpleAction .new (name , None )
@@ -109,11 +113,10 @@ def build_ui(self) -> None:
109113 self ._setup_main_layout ()
110114
111115 def _setup_window (self ) -> None :
112- self .win : Adw .ApplicationWindow = Adw .ApplicationWindow (application = self .app )
113- self .win .set_title ("Gradia" )
114- self .win .set_default_size (self .DEFAULT_WINDOW_WIDTH , self .DEFAULT_WINDOW_HEIGHT )
116+ self .set_title ("Gradia" )
117+ self .set_default_size (self .DEFAULT_WINDOW_WIDTH , self .DEFAULT_WINDOW_HEIGHT )
115118 self .toast_overlay : Adw .ToastOverlay = Adw .ToastOverlay ()
116- self .win . set_content (self .toast_overlay )
119+ self .set_content (self .toast_overlay )
117120
118121 def _setup_toolbar (self ) -> None :
119122 self .toolbar_view : Adw .ToolbarView = Adw .ToolbarView ()
@@ -158,11 +161,11 @@ def _setup_main_layout(self) -> None:
158161 self .toolbar_view .set_content (self .main_box )
159162 self .toast_overlay .set_child (self .toolbar_view )
160163
161- self .win . connect ("notify::default-width" , self ._on_window_resize )
162- self .win . connect ("notify::default-height" , self ._on_window_resize )
164+ self .connect ("notify::default-width" , self ._on_window_resize )
165+ self .connect ("notify::default-height" , self ._on_window_resize )
163166
164167 def _on_window_resize (self , * args : Any ) -> None :
165- width : int = self .win . get_width ()
168+ width : int = self .get_width ()
166169 if width < 800 :
167170 self .main_box .set_orientation (Gtk .Orientation .VERTICAL )
168171 self .sidebar .set_size_request (- 1 , 200 )
@@ -171,7 +174,7 @@ def _on_window_resize(self, *args: Any) -> None:
171174 self .sidebar .set_size_request (300 , - 1 )
172175
173176 def show (self ) -> None :
174- self .win . present ()
177+ self .present ()
175178
176179 def _start_processing (self ) -> None :
177180 self .toolbar_view .set_top_bar_style (Adw .ToolbarStyle .RAISED )
@@ -291,17 +294,16 @@ def _set_loading_state(self, is_loading: bool) -> None:
291294
292295 def _on_about_activated (self , action : Gio .SimpleAction , param ) -> None :
293296 about = create_about_dialog (version = self .version )
294- about .present (self . win )
297+ about .present (self )
295298
296299 def _set_save_and_toggle_ (self , enabled : bool ) -> None :
297- app = self .app
298300 for action_name in ["save" , "copy" ]:
299- action : Optional [Gio .SimpleAction ] = app .lookup_action (action_name )
301+ action : Optional [Gio .SimpleAction ] = self . app .lookup_action (action_name )
300302 if action :
301303 action .set_enabled (enabled )
302304
303305 def _on_shortcuts_activated (self , action : Gio .SimpleAction , param ) -> None :
304- shortcuts = create_shortcuts_dialog (self . win )
306+ shortcuts = create_shortcuts_dialog (self )
305307 shortcuts .connect ("close-request" , self ._on_shortcuts_closed )
306308 shortcuts .present ()
307309
0 commit comments