Skip to content

Commit

Permalink
Merge pull request #582 from Sjoerd1993/small-improvements
Browse files Browse the repository at this point in the history
small improvements
  • Loading branch information
sstendahl authored Nov 16, 2023
2 parents 9f1ee26 + 7544bf5 commit 1014ab1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 26 deletions.
5 changes: 0 additions & 5 deletions data/ui/figure_settings.blp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,9 @@ template $GraphsFigureSettingsWindow : Adw.Window {

Adw.PreferencesGroup {
title: _("Axis Limits");
Adw.ActionRow no_data_message {
title: _("No Data");
subtitle: _("Add data to the figure to set axis limits");
}
Box {
orientation: vertical;
spacing: 12;
visible: bind no_data_message.visible inverted;
Box left_limits {
orientation: horizontal;
spacing: 6;
Expand Down
2 changes: 1 addition & 1 deletion src/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ def on_response(_dialog, response):

def delete_selected_action(_action, _target, self):
items = [item for item in self.get_data() if item.get_selected()]
names = ", ".join([item.get_name() for item in items])
names = ", ".join(item.get_name() for item in items)
self.get_data().delete_items(items)
self.get_window().add_toast_string(_("Deleted {}").format(names))
18 changes: 8 additions & 10 deletions src/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,18 @@ def add_items(self, items: misc.ItemList) -> None:
used_colors = []

def _append_used_color(color):
used_colors.append(color)
# If we've got all colors once, remove those from used_colors so we
# can loop around
if set(used_colors) == set(color_cycle):
if len(set(used_colors)) == len(color_cycle):
for color in color_cycle:
used_colors.remove(color)

for item_ in self:
_append_used_color(item_.get_color())

def _is_default(prop):
return figure_settings.get_property(prop) == \
settings.get_child("figure").get_string(prop)

for item_ in self:
color = item_.get_color()
if color in color_cycle:
_append_used_color(color)
for new_item in items:
names = self.get_names()
if new_item.get_name() in names:
Expand All @@ -213,7 +211,7 @@ def _is_default(prop):
index = names.index(new_item.get_name())
existing_item = self[index]
self._current_batch.append(
(2, (index, existing_item.to_dict(item_))),
(2, (index, item.to_dict(existing_item))),
)
new_item.set_uuid(existing_item.get_uuid())

Expand Down Expand Up @@ -246,8 +244,8 @@ def _is_default(prop):
if new_item.get_color() == "":
for color in color_cycle:
if color not in used_colors:
new_item.set_color(color)
_append_used_color(color)
new_item.set_color(color)
break

self._add_item(new_item)
Expand Down Expand Up @@ -489,7 +487,7 @@ def load_from_project_dict(self, project_dict: dict[str, Any]) -> None:
for key, value in project_dict["figure-settings"].items():
if figure_settings.get_property(key) != value:
figure_settings.set_property(key, value)
self.set_items([item.new_from_dict(d) for d in project_dict["data"]])
self.set_items(item.new_from_dict(d) for d in project_dict["data"])

self._set_data_copy()
self._history_states = project_dict["history-states"]
Expand Down
12 changes: 5 additions & 7 deletions src/figure_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class FigureSettingsWindow(Adw.Window):
min_top = Gtk.Template.Child()
max_top = Gtk.Template.Child()

no_data_message = Gtk.Template.Child()
style_overview = Gtk.Template.Child()
navigation_view = Gtk.Template.Child()
grid_view = Gtk.Template.Child()
Expand Down Expand Up @@ -83,9 +82,6 @@ def __init__(self, application, highlighted=None):

ui.bind_values_to_object(figure_settings, self, ignorelist=ignorelist)
self.set_axes_entries()
self.no_data_message.set_visible(
self.get_application().get_data().is_empty(),
)
if highlighted is not None:
getattr(self, highlighted).grab_focus()

Expand Down Expand Up @@ -132,11 +128,13 @@ def on_select(self, model, _pos, _n_items):
figure_settings.set_use_custom_style(True)

def set_axes_entries(self):
used_axes = [[direction, False] for direction in _DIRECTIONS]
used_axes = [False, False, False, False]
for item in self.get_application().get_data():
for i in item.get_xposition() * 2, 1 + item.get_yposition() * 2:
used_axes[i][1] = True
for (direction, visible) in used_axes:
used_axes[i] = True
if not any(used_axes):
used_axes = [True, True, False, False]
for (direction, visible) in zip(_DIRECTIONS, used_axes):
if visible:
for s in ("min_", "max_"):
entry = getattr(self, s + direction)
Expand Down
3 changes: 1 addition & 2 deletions src/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def multiply_y(_item, xdata, ydata, multiplier):

def normalize(_item, xdata, ydata):
"""Normalize all selected data"""
new_ydata = [value / max(ydata) for value in ydata]
return xdata, new_ydata, False, False
return xdata, [value / max(ydata) for value in ydata], False, False


def smoothen(_item, xdata, ydata):
Expand Down
2 changes: 1 addition & 1 deletion src/style_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def generate_preview(style: RcParams) -> Gio.File:
axis.spines.bottom.set_visible(True)
axis.spines.left.set_visible(True)
if not style["axes.spines.top"]:
axis.tick_params(which="both", **{"top": False, "right": False})
axis.tick_params(which="both", top=False, right=False)
axis.plot(_PREVIEW_XDATA, _PREVIEW_YDATA1)
axis.plot(_PREVIEW_XDATA, _PREVIEW_YDATA2)
axis.set_xlabel(_("X Label"))
Expand Down

0 comments on commit 1014ab1

Please sign in to comment.