Skip to content

Commit

Permalink
Merge pull request #226 from ARAKHN1D/adw-dialog-port
Browse files Browse the repository at this point in the history
Port to AdwDialog
  • Loading branch information
Huluti committed May 8, 2024
2 parents 2ee4a9e + 37aecb3 commit 24b9c85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion data/ui/preferences.ui
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="curtail">
<template class="CurtailPrefsWindow" parent="AdwPreferencesWindow">
<template class="CurtailPrefsDialog" parent="AdwPreferencesDialog">
<property name="title" translatable="yes">Preferences</property>
<child>
<object class="AdwPreferencesPage">
Expand Down
8 changes: 3 additions & 5 deletions src/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@


@Gtk.Template(resource_path=UI_PATH + 'preferences.ui')
class CurtailPrefsWindow(Adw.PreferencesWindow):
__gtype_name__ = 'CurtailPrefsWindow'
class CurtailPrefsDialog(Adw.PreferencesDialog):
__gtype_name__ = 'CurtailPrefsDialog'

toggle_recursive = Gtk.Template.Child()
toggle_metadata = Gtk.Template.Child()
Expand All @@ -46,9 +46,6 @@ def __init__(self, parent, **kwargs):
super().__init__(**kwargs)

self.parent = parent
self.set_transient_for(parent)
self.set_modal(True)

self.build_ui()

def build_ui(self):
Expand Down Expand Up @@ -143,3 +140,4 @@ def on_string_changed(self, entry, key):

def on_int_changed(self, spin, key):
self._settings.set_int(key, spin.get_value())

23 changes: 11 additions & 12 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pathlib import Path

from .resultitem import ResultItem
from .preferences import CurtailPrefsWindow
from .preferences import CurtailPrefsDialog
from .compressor import Compressor
from .tools import add_filechooser_filters, get_file_type, \
create_image_from_file, sizeof_fmt, debug_infos, \
Expand All @@ -37,7 +37,7 @@ class CurtailWindow(Adw.ApplicationWindow):
_settings = Gio.Settings.new(SETTINGS_SCHEMA)
settings = Gtk.Settings.get_default()

prefs_window = None
prefs_dialog = None
apply_window = None

headerbar = Gtk.Template.Child()
Expand Down Expand Up @@ -220,20 +220,20 @@ def on_dir_dialog_response(warn_dialog, response):
else:
warning_message_dialog = self._create_warning_dialog()
warning_message_dialog.connect("response", on_dir_dialog_response)
warning_message_dialog.show()
warning_message_dialog.present(self)

dialog.select_multiple_folders(self, None, handle_response)

def _create_warning_dialog(self):
dialog = None
if self._settings.get_boolean('new-file'):
dialog = Adw.MessageDialog.new(self,
dialog = Adw.AlertDialog.new(
_("Are you sure you want to compress images in these directories?"),
_("All of the images in the directories selected and their "
"subdirectories will be compressed. The original images will not "
"be modified."))
else:
dialog = Adw.MessageDialog.new(self,
dialog = Adw.AlertDialog.new(
_("Are you sure you want to compress images in these directories?"),
_("All of the images in the directories selected and their "
"subdirectories will be compressed and overwritten!"))
Expand Down Expand Up @@ -348,14 +348,13 @@ def on_lossy_changed(self, switch, state):
self._settings.set_boolean('lossy', switch.get_active())

def on_preferences(self, *args):
if self.prefs_window is not None:
self.prefs_window.destroy()
self.prefs_window = CurtailPrefsWindow(self)
self.prefs_window.present()
if self.prefs_dialog is not None:
self.prefs_dialog.force_close()
self.prefs_dialog = CurtailPrefsDialog(self)
self.prefs_dialog.present(self)

def on_about(self, *args):
about = Adw.AboutWindow(
transient_for=self,
about = Adw.AboutDialog(
application_name='Curtail',
application_icon='com.github.huluti.Curtail',
developer_name='Hugo Posnic',
Expand Down Expand Up @@ -385,7 +384,7 @@ def on_about(self, *args):
]
)
about.set_debug_info(debug_infos())
about.present()
about.present(self)

def on_quit(self, *args):
self.app.quit()

0 comments on commit 24b9c85

Please sign in to comment.