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

remove preferences window #586

Merged
merged 2 commits into from
Nov 16, 2023
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: 0 additions & 1 deletion data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion data/se.sjoerd.Graphs.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<file preprocess="xml-stripblanks">ui/fitting_parameters.ui</file>
<file preprocess="xml-stripblanks">ui/import.ui</file>
<file preprocess="xml-stripblanks">ui/item_box.ui</file>
<file preprocess="xml-stripblanks">ui/preferences.ui</file>
<file preprocess="xml-stripblanks">ui/style_color_box.ui</file>
<file preprocess="xml-stripblanks">ui/style_editor.ui</file>
<file preprocess="xml-stripblanks">ui/style_preview.ui</file>
Expand Down
20 changes: 10 additions & 10 deletions data/se.sjoerd.Graphs.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="graphs">
<enum id="se.sjoerd.Graphs.general.center-values">
<value nick="Center at maximum Y value" value="0"/>
<value nick="Center at middle X value" value="1"/>
<enum id="se.sjoerd.Graphs.actions.center-values">
<value nick="max-y" value="0"/>
<value nick="middle-x" value="1"/>
</enum>

<enum id="se.sjoerd.Graphs.export-figure.file-formats">
Expand Down Expand Up @@ -45,20 +45,17 @@
</enum>

<schema id="se.sjoerd.Graphs" path="/se/sjoerd/Graphs/">
<child name="general" schema="se.sjoerd.Graphs.general"/>
<child name="actions" schema="se.sjoerd.Graphs.actions"/>
<child name="add-equation" schema="se.sjoerd.Graphs.add-equation"/>
<child name="curve-fitting" schema="se.sjoerd.Graphs.curve-fitting"/>
<child name="export-figure" schema="se.sjoerd.Graphs.export-figure"/>
<child name="figure" schema="se.sjoerd.Graphs.figure"/>
<child name="import-params" schema="se.sjoerd.Graphs.import-params"/>
</schema>

<schema id="se.sjoerd.Graphs.general">
<key name="center" enum="se.sjoerd.Graphs.general.center-values">
<default>"Center at middle X value"</default>
</key>
<key name="hide-unselected" type="b">
<default>false</default>
<schema id="se.sjoerd.Graphs.actions">
<key name="center" enum="se.sjoerd.Graphs.actions.center-values">
<default>"middle-x"</default>
</key>
</schema>

Expand Down Expand Up @@ -102,6 +99,9 @@
<key name="use-custom-style" type="b">
<default>false</default>
</key>
<key name="hide-unselected" type="b">
<default>false</default>
</key>
</schema>

<schema id="se.sjoerd.Graphs.add-equation">
Expand Down
4 changes: 4 additions & 0 deletions data/ui/figure_settings.blp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ template $GraphsFigureSettingsWindow : Adw.Window {
}
}

Adw.SwitchRow hide_unselected {
title: _("Hide Unselected Items");
}

Adw.ActionRow {
title: _("Style");
hexpand: true;
Expand Down
5 changes: 0 additions & 5 deletions data/ui/help_overlay.blp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ ShortcutsWindow help_overlay {
action-name: "win.show-help-overlay";
}

ShortcutsShortcut {
title: C_("shortcut window", "Open Preferences");
accelerator: "<primary>comma";
}

ShortcutsShortcut {
title: C_("shortcut window", "Open Figure Settings");
accelerator: "<primary><alt>comma";
Expand Down
24 changes: 0 additions & 24 deletions data/ui/preferences.blp

This file was deleted.

17 changes: 15 additions & 2 deletions data/ui/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -325,6 +325,7 @@ template $GraphsWindow: Adw.ApplicationWindow {
label: _("Center");
}
tooltip-text: _("Center data");
menu-model: center_menu;
clicked => $perform_operation();
}

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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";
}
}
8 changes: 1 addition & 7 deletions src/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions src/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]


Expand Down Expand Up @@ -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,
)
Expand Down
27 changes: 11 additions & 16 deletions src/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions src/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, (
Expand Down
1 change: 1 addition & 0 deletions src/figure_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/figure_settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions src/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"""
Expand All @@ -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)
Expand Down
27 changes: 0 additions & 27 deletions src/preferences.vala

This file was deleted.

4 changes: 4 additions & 0 deletions src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down