diff --git a/data/meson.build b/data/meson.build index d0f2ed7fe..cb71d9c2e 100644 --- a/data/meson.build +++ b/data/meson.build @@ -71,7 +71,6 @@ blueprints_source = [ 'ui/import.blp', 'ui/help_overlay.blp', 'ui/item_box.blp', - 'ui/preferences.blp', 'ui/style_color_box.blp', 'ui/style_editor.blp', 'ui/style_preview.blp', diff --git a/data/se.sjoerd.Graphs.gresource.xml b/data/se.sjoerd.Graphs.gresource.xml index 7afb4afe8..e761cb360 100644 --- a/data/se.sjoerd.Graphs.gresource.xml +++ b/data/se.sjoerd.Graphs.gresource.xml @@ -40,7 +40,6 @@ ui/fitting_parameters.ui ui/import.ui ui/item_box.ui - ui/preferences.ui ui/style_color_box.ui ui/style_editor.ui ui/style_preview.ui diff --git a/data/se.sjoerd.Graphs.gschema.xml b/data/se.sjoerd.Graphs.gschema.xml index 520ac1666..5431e0c0d 100644 --- a/data/se.sjoerd.Graphs.gschema.xml +++ b/data/se.sjoerd.Graphs.gschema.xml @@ -1,8 +1,8 @@ - - - + + + @@ -45,7 +45,7 @@ - + @@ -53,12 +53,9 @@ - - - "Center at middle X value" - - - false + + + "middle-x" @@ -102,6 +99,9 @@ false + + false + diff --git a/data/ui/figure_settings.blp b/data/ui/figure_settings.blp index fd0691eac..189339d91 100644 --- a/data/ui/figure_settings.blp +++ b/data/ui/figure_settings.blp @@ -174,6 +174,10 @@ template $GraphsFigureSettingsWindow : Adw.Window { } } + Adw.SwitchRow hide_unselected { + title: _("Hide Unselected Items"); + } + Adw.ActionRow { title: _("Style"); hexpand: true; diff --git a/data/ui/help_overlay.blp b/data/ui/help_overlay.blp index e2e3cd513..af585acb0 100644 --- a/data/ui/help_overlay.blp +++ b/data/ui/help_overlay.blp @@ -15,11 +15,6 @@ ShortcutsWindow help_overlay { action-name: "win.show-help-overlay"; } - ShortcutsShortcut { - title: C_("shortcut window", "Open Preferences"); - accelerator: "comma"; - } - ShortcutsShortcut { title: C_("shortcut window", "Open Figure Settings"); accelerator: "comma"; diff --git a/data/ui/preferences.blp b/data/ui/preferences.blp deleted file mode 100644 index ce2b93e44..000000000 --- a/data/ui/preferences.blp +++ /dev/null @@ -1,24 +0,0 @@ -using Gtk 4.0; -using Adw 1; - -template $GraphsPreferencesWindow : Adw.PreferencesWindow { - can-navigate-back: true; - modal: true; - search-enabled: false; - - Adw.PreferencesPage { - Adw.PreferencesGroup { - Adw.ComboRow center { - title: _("Center Action Behaviour"); - subtitle: _("Which value to center on when performing a center action"); - model: StringList{ - strings [_("Center at maximum Y value"), _("Center at middle X value")] - }; - } - - Adw.SwitchRow hide_unselected { - title: _("Hide Unselected Items"); - } - } - } -} \ No newline at end of file diff --git a/data/ui/window.blp b/data/ui/window.blp index 7d236ecf1..3e1fb7eb3 100644 --- a/data/ui/window.blp +++ b/data/ui/window.blp @@ -312,7 +312,7 @@ template $GraphsWindow: Adw.ApplicationWindow { clicked => $perform_operation(); } - Button center_button { + Adw.SplitButton center_button { hexpand: true; sensitive: bind shift_button.sensitive; layout { @@ -325,6 +325,7 @@ template $GraphsWindow: Adw.ApplicationWindow { label: _("Center"); } tooltip-text: _("Center data"); + menu-model: center_menu; clicked => $perform_operation(); } @@ -626,7 +627,6 @@ menu primary_menu { } section { item (_("Figure Settings"), "app.figure_settings") - item (_("Preferences"), "app.preferences") } section { item (_("Keyboard Shortcuts"), "win.show-help-overlay") @@ -763,4 +763,17 @@ menu view_menu { } } } +} + +menu center_menu { + item { + label: _("At maximum Y value"); + action: "app.center"; + target: "max-y"; + } + item { + label: _("At middle X value"); + action: "app.center"; + target: "middle-x"; + } } \ No newline at end of file diff --git a/src/actions.py b/src/actions.py index 29834e71c..a886e8cd2 100644 --- a/src/actions.py +++ b/src/actions.py @@ -2,8 +2,6 @@ """Main actions.""" from gettext import gettext as _ -from gi.repository import Graphs - from graphs import operations, ui, utilities from graphs.add_equation import AddEquationWindow from graphs.export_figure import ExportFigureWindow @@ -21,7 +19,7 @@ def perform_operation(_action, target, self): return args = [] if operation in ("center", ): - args = [self.get_settings("general").get_enum(operation)] + args = [self.get_settings("actions").get_enum(operation)] if operation == "shift": figure_settings = self.get_data().get_figure_settings() right_range = (figure_settings.get_max_right() @@ -63,10 +61,6 @@ def about_action(_action, _target, self): ui.show_about_window(self) -def preferences_action(_action, _target, self): - Graphs.PreferencesWindow.new(self) - - def figure_settings_action(_action, _target, self): FigureSettingsWindow(self) diff --git a/src/application.py b/src/application.py index b63df740b..d6be3eb7d 100644 --- a/src/application.py +++ b/src/application.py @@ -17,11 +17,10 @@ _ACTIONS = [ - "quit", "about", "preferences", "figure_settings", "add_data", - "add_equation", "select_all", "select_none", "undo", "redo", - "optimize_limits", "view_back", "view_forward", "export_data", - "export_figure", "save_project", "open_project", "delete_selected", - "zoom_in", "zoom_out", + "quit", "about", "figure_settings", "add_data", "add_equation", + "select_all", "select_none", "undo", "redo", "optimize_limits", + "view_back", "view_forward", "export_data", "export_figure", + "save_project", "open_project", "delete_selected", "zoom_in", "zoom_out", ] @@ -100,6 +99,9 @@ def __init__(self, application_id, **kwargs): operation_action.connect("activate", actions.perform_operation, self) self.add_action(operation_action) + center_action = settings.get_child("actions").create_action("center") + self.add_action(center_action) + self.get_data().connect( "notify::items", ui.on_items_change, self, ) diff --git a/src/canvas.py b/src/canvas.py index 05619b700..ad07499de 100644 --- a/src/canvas.py +++ b/src/canvas.py @@ -75,6 +75,8 @@ class Canvas(FigureCanvas, Graphs.CanvasInterface): __gtype_name__ = "GraphsCanvas" application = GObject.Property(type=Graphs.Application) + hide_unselected = GObject.Property(type=bool, default=False) + items = GObject.Property(type=object) min_selected = GObject.Property(type=float, default=0) max_selected = GObject.Property(type=float, default=0) @@ -89,7 +91,9 @@ def __init__(self, application, style_params): """ self._style_params = style_params pyplot.rcParams.update(self._style_params) # apply style_params - GObject.Object.__init__(self, application=application, can_focus=False) + GObject.Object.__init__( + self, application=application, can_focus=False, items=[], + ) super().__init__() self.figure.set_tight_layout(True) self.mpl_connect("pick_event", self._on_pick) @@ -119,6 +123,9 @@ def __init__(self, application, style_params): zoom_gesture.connect("scale-changed", self._on_zoom_gesture) self.add_controller(zoom_gesture) + self.connect("notify::hide-unselected", self._redraw) + self.connect("notify::items", self._redraw) + def get_application(self): """Get application property.""" return self.props.application @@ -214,25 +221,13 @@ def on_draw_event(self, _widget, ctx): self._renderer.dpi = self.figure.dpi self.figure.draw(self._renderer) - @GObject.Property(flags=2) - def items(self): - """ignored, property is write-only.""" - - @items.setter - def items(self, items: list): - """ - Setter for items property. - - Automatically hide unused axes and refresh legend. - """ - hide_unselected = self.get_application().get_settings( - "general").get_boolean("hide-unselected") + def _redraw(self, *_args): drawable_items = [] # bottom, top, left, right visible_axes = [False, False, False, False] used_axes = [False, False, False, False] - for item in items: - if not (hide_unselected and not item.get_selected()): + for item in self.props.items: + if not (self.props.hide_unselected and not item.get_selected()): drawable_items.append(item) xposition = item.get_xposition() yposition = item.get_yposition() diff --git a/src/data.py b/src/data.py index 1f48ce93a..17c141f2c 100644 --- a/src/data.py +++ b/src/data.py @@ -271,9 +271,6 @@ def _on_item_position_change(self, _item, _ignored) -> None: def _on_item_select(self, _x, _y) -> None: self.notify("items_selected") - if self.get_application().get_settings( - "general").get_boolean("hide-unselected"): - self.notify("items") def _on_item_change(self, item_, param) -> None: self._current_batch.append((0, ( diff --git a/src/figure_settings.py b/src/figure_settings.py index 7171505b0..fbde7083c 100644 --- a/src/figure_settings.py +++ b/src/figure_settings.py @@ -40,6 +40,7 @@ class FigureSettingsWindow(Adw.Window): right_scale = Gtk.Template.Child() legend = Gtk.Template.Child() legend_position = Gtk.Template.Child() + hide_unselected = Gtk.Template.Child() left_limits = Gtk.Template.Child() right_limits = Gtk.Template.Child() bottom_limits = Gtk.Template.Child() diff --git a/src/figure_settings.vala b/src/figure_settings.vala index e3052fd03..1f5aee1a1 100644 --- a/src/figure_settings.vala +++ b/src/figure_settings.vala @@ -17,6 +17,7 @@ namespace Graphs { public int legend_position { get; set; default = 0; } public bool use_custom_style { get; set; default = false; } public string custom_style { get; set; default = "adwaita"; } + public bool hide_unselected { get; set; default = false; } public double min_bottom { get; set; default = 0; } public double max_bottom { get; set; default = 1; } diff --git a/src/meson.build b/src/meson.build index c18aa1bb5..2b2408b2f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -49,7 +49,6 @@ graphs_lib = shared_library( 'item.vala', 'inline-stack-switcher.vala', 'misc.vala', - 'preferences.vala', 'utilities.vala', 'window.vala', ), blueprints_hack, gresource_bundle, diff --git a/src/migrate.py b/src/migrate.py index e404ad289..0a603b1db 100644 --- a/src/migrate.py +++ b/src/migrate.py @@ -11,14 +11,14 @@ CONFIG_MIGRATION_TABLE = { # old-key: (category, key) - "action_center_data": ("general", "center"), + "action_center_data": ("actions", "center"), "addequation_equation": ("add-equation", "equation"), "addequation_step_size": ("add-equation", "step-size"), "addequation_x_start": ("add-equation", "x-start"), "addequation_x_stop": ("add-equation", "x-stop"), "export_figure_dpi": ("export-figure", "dpi"), "export_figure_transparent": ("export-figure", "transparent"), - "hide_unselected": ("general", "hide-unselected"), + "hide_unselected": ("figure", "hide-unselected"), "plot_custom_style": ("figure", "custom-style"), "plot_legend": ("figure", "legend"), "plot_right_label": ("figure", "right-label"), @@ -33,6 +33,11 @@ "plot_y_scale": ("figure", "left-scale"), } +CENTER_ACTION_MIGRATION_TABLE = { + "Center at middle coordinate": "middle-x", + "Center at middle X value": "max-y", +} + def migrate_config(settings): """Migrate old file-based user config to dconf""" @@ -58,7 +63,9 @@ def _migrate_config(settings_, config_file): for old_key, (category, key) in CONFIG_MIGRATION_TABLE.items(): with contextlib.suppress(KeyError, ValueError): value = config[old_key] - if "scale" in key: + if old_key == "action_center_data": + value = CENTER_ACTION_MIGRATION_TABLE[value] + elif "scale" in key: value = value.capitalize() settings_.get_child(category)[key] = value config_file.delete(None) diff --git a/src/preferences.vala b/src/preferences.vala deleted file mode 100644 index cf9109611..000000000 --- a/src/preferences.vala +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -using Adw; -using Gtk; - -namespace Graphs { - - [GtkTemplate (ui = "/se/sjoerd/Graphs/ui/preferences.ui")] - public class PreferencesWindow : Adw.PreferencesWindow { - - [GtkChild] - public unowned Adw.ComboRow center { get; } - - [GtkChild] - public unowned Adw.SwitchRow hide_unselected { get; } - - public PreferencesWindow (Application application) { - Object ( - application: application, - transient_for: application.window - ); - Tools.bind_settings_to_widgets ( - application.settings.get_child("general"), this - ); - present (); - } - } -} diff --git a/src/ui.py b/src/ui.py index 7548383f5..178e47e9d 100644 --- a/src/ui.py +++ b/src/ui.py @@ -245,6 +245,10 @@ def bind_values_to_object(source, window, ignorelist=None): bindings.append(source.bind_property( key, widget.get_adjustment(), "value", 1 | 2, )) + elif isinstance(widget, Adw.SwitchRow): + bindings.append(source.bind_property( + key, widget, "active", 1 | 2, + )) else: logging.warn(_("Unsupported Widget {}").format(type(widget))) except AttributeError: