Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Port dialogs toAdw.Dialog, update blueprint-compiler, ... #326

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

builddir/
.flatpak/
.flatpak-builder
_build/


Expand Down
18 changes: 8 additions & 10 deletions blanket/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from blanket.define import AUTHORS, ARTISTS, RES_PATH, SOUND_ARTISTS, SOUND_EDITORS
from blanket.main_player import MainPlayer
from blanket.mpris import MPRIS
from blanket.preferences import PreferencesWindow
from blanket.preferences import PreferencesDialog
from blanket.settings import Settings
from blanket.widgets import PresetDialog
from blanket.window import BlanketWindow
Expand Down Expand Up @@ -89,12 +89,12 @@ def setup_actions(self):
action.connect('activate', self.on_quit)
self.add_action(action)

# Show about window
# Show about dialog
action = Gio.SimpleAction.new('about', None)
action.connect('activate', self.on_about)
self.add_action(action)

# Show preferences window
# Show preferences dialog
action = Gio.SimpleAction.new('preferences', None)
action.connect('activate', self.on_preferences)
self.add_action(action)
Expand Down Expand Up @@ -223,14 +223,12 @@ def on_background(self, action, value):
self.window.props.hide_on_close = value

def on_preferences(self, _action, _param):
window = PreferencesWindow(self.window)
window.set_transient_for(self.window)
window.set_modal(True)
window.present()
prefs = PreferencesDialog(self.window)
prefs.present(self.window)

def on_about(self, _action, _param):
builder = Gtk.Builder.new_from_resource(f'{RES_PATH}/about.ui')
about: Adw.AboutWindow = builder.get_object('about') # type: ignore
about: Adw.AboutDialog = builder.get_object('about') # type: ignore

artists = self.__get_credits_list(ARTISTS)
sound_artists = self.__get_credits_list(SOUND_ARTISTS)
Expand All @@ -239,11 +237,11 @@ def on_about(self, _action, _param):
about.set_version(self.version)
about.set_developers(AUTHORS)
about.set_designers(artists)
about.add_link(_('Source Code'), 'https://github.com/rafaelmardojai/blanket')
about.add_credit_section(_('Sounds by'), sound_artists)
about.add_credit_section(_('Sounds edited by'), sound_editors)

about.set_transient_for(self.window)
about.present()
about.present(self.window)

def on_quit(self, _action, _param):
self.quit()
Expand Down
51 changes: 11 additions & 40 deletions blanket/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@


@Gtk.Template(resource_path=f'{RES_PATH}/preferences.ui')
class PreferencesWindow(Adw.PreferencesWindow):
__gtype_name__ = 'PreferencesWindow'
class PreferencesDialog(Adw.PreferencesDialog):
__gtype_name__ = 'PreferencesDialog'

dark_group: Adw.PreferencesGroup = Gtk.Template.Child() # type: ignore
dark: Adw.SwitchRow = Gtk.Template.Child() # type: ignore
Expand Down Expand Up @@ -104,16 +104,9 @@ def __request_autostart(self, active: bool):
except Exception as e:
print(e)

error_dialog = Gtk.MessageDialog(
message_type=Gtk.MessageType.WARNING,
buttons=Gtk.ButtonsType.OK,
text=_('Request error'),
)
error_dialog.props.transient_for = self
error_dialog.props.modal = True
error_dialog.props.secondary_text = _('The autostart request failed.')
error_dialog.connect('response', self.__on_dialog_response)
error_dialog.present()
error_dialog = Adw.AlertDialog.new(_('Request error'), _('The autostart request failed.'))
error_dialog.add_response('ok', _('Ok'))
error_dialog.present(self.window)
self.autostart_failed = True
self.autostart.set_active(self.autostart_saved)

Expand All @@ -128,40 +121,18 @@ def __receive_autostart(self, *args):
pass
elif state == 1:
if active:
error_dialog = Gtk.MessageDialog(
message_type=Gtk.MessageType.WARNING,
buttons=Gtk.ButtonsType.OK,
text=_('Authorization failed'),
)
error_dialog.props.transient_for = self
error_dialog.props.modal = True
error_dialog.props.secondary_text = _(
'Make sure Blanket has permission to run in '
'\nthe background in Settings → Applications → '
'\nBlanket and try again.'
)
error_dialog.connect('response', self.__on_dialog_response)
error_dialog.present()
error_dialog = Adw.AlertDialog.new(_('Authorization failed'), _('Make sure Blanket has permission to run in the background in Settings → Applications → Blanket and try again.'))
error_dialog.add_response('ok', _('Ok'))
error_dialog.present(self.window)
elif state == 2:
error_dialog = Gtk.MessageDialog(
message_type=Gtk.MessageType.WARNING,
buttons=Gtk.ButtonsType.OK,
text=_('Request error'),
)
error_dialog.props.transient_for = self
error_dialog.props.modal = True
error_dialog.props.secondary_text = _('The autostart request failed.')
error_dialog.connect('response', self.__on_dialog_response)
error_dialog.present()
error_dialog = Adw.AlertDialog.new(_('Request error'), _('The autostart request failed.'))
error_dialog.add_response('ok', _('Ok'))
error_dialog.present(self.window)

self.autostart.set_active(autostart)
Settings.get().autostart = autostart
return

def __on_dialog_response(self, dialog, response_id):
if response_id == Gtk.ResponseType.OK:
dialog.destroy()

def __get_window_identifier(self):
session = os.getenv('XDG_SESSION_TYPE')
surface = self.window.get_surface()
Expand Down
14 changes: 7 additions & 7 deletions blanket/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,17 @@ def populate_sounds(self):
else:
Settings.get().remove_custom_audio(name)

message = Adw.MessageDialog.new(
self,
alert = Adw.AlertDialog.new(
_('Sound Automatically Removed'),
_(
'The {name} sound is no longer accessible, so it has been removed'
).format(name=f'<b><i>{name}</i></b>'),
)
message.add_response('accept', _('Accept'))
message.props.body_use_markup = True
message.props.default_response = 'accept'
message.props.close_response = 'accept'
message.present()
alert.add_response('accept', _('Accept'))
alert.props.body_use_markup = True
alert.props.default_response = 'accept'
alert.props.close_response = 'accept'
alert.present(self)

def open_audio(self):
def on_response(_filechooser, _id):
Expand Down Expand Up @@ -179,6 +178,7 @@ def on_response(_filechooser, _id):
self.filechooser = Gtk.FileChooserNative.new( # type: ignore
_('Open audio'), self, Gtk.FileChooserAction.OPEN, None, None
)
self.filechooser.set_modal(True)
self.filechooser.connect('response', on_response)

for f, mts in filters.items():
Expand Down
4 changes: 2 additions & 2 deletions com.rafaelmardojai.Blanket.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
{
"type": "git",
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler",
"tag": "v0.8.1",
"commit": "aa7679618e864748f4f4d8f15283906e712752fe"
"tag": "v0.10.0",
"commit": "2a39a16391122af2f3d812e478c1c1398c98b972"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion data/com.rafaelmardojai.Blanket.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<li>Wind</li>
</ul>
</description>
<url type="homepage">https://github.com/rafaelmardojai/blanket</url>
<url type="homepage">https://apps.gnome.org/Blanket</url>
<url type="bugtracker">https://github.com/rafaelmardojai/blanket/issues</url>
<url type="translate">https://hosted.weblate.org/engage/blanket/</url>
<url type="donation">https://rafaelmardojai.com/donate/</url>
Expand Down
5 changes: 2 additions & 3 deletions data/resources/about.blp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Gtk 4.0;
using Adw 1;

Adw.AboutWindow about {
destroy-with-parent: true;
Adw.AboutDialog about {
application-name: "Blanket";
comments: _("Listen to different sounds");
copyright: _("Copyright 2020-2022 Rafael Mardojai CM");
developer-name: _("Rafael Mardojai CM");
website: "https://github.com/rafaelmardojai/blanket/";
website: "https://apps.gnome.org/Blanket";
issue-url: "https://github.com/rafaelmardojai/blanket/issues";
application-icon: "com.rafaelmardojai.Blanket";
license-type: gpl_3_0;
Expand Down
7 changes: 1 addition & 6 deletions data/resources/preferences.blp
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using Gtk 4.0;
using Adw 1;

template $PreferencesWindow : Adw.PreferencesWindow {
default-height: 300;
default-width: 500;
modal: true;
search-enabled: false;

template $PreferencesDialog : Adw.PreferencesDialog {
Adw.PreferencesPage {
Adw.PreferencesGroup dark_group {
title: _("Appearance");
Expand Down
2 changes: 1 addition & 1 deletion data/resources/preset-dialog.blp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ template $PresetDialog : Adw.Window {
show-start-title-buttons: false;

title-widget: Adw.WindowTitle title_widget {
title: bind-property template.title;
title: bind template.title;
};

Button {
Expand Down
2 changes: 1 addition & 1 deletion data/resources/volume-row.blp
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ Adjustment volume_adjustment {
upper: 1;
step-increment: 0.01;
page-increment: 0.01;
value: bind-property template.volume no-sync-create bidirectional;
value: bind template.volume no-sync-create bidirectional;
}
2 changes: 1 addition & 1 deletion data/resources/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ template $BlanketWindow : Adw.ApplicationWindow {
default-width: 520;
default-height: 600;
width-request: 360;
height-request: 200;
height-request: 294;

Adw.Breakpoint {
condition ("max-width: 360px")
Expand Down
Loading