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

Set translate/modify entry css #702

Merged
merged 1 commit into from
Jan 3, 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
2 changes: 2 additions & 0 deletions data/se.sjoerd.Graphs.appdata.xml.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
<li>Importing column data is now more robust, supporting expressions as data points</li>
<li>Pinch and ctrl+scroll to zoom gestures are now supported on the canvas</li>
<li>The canvas can now be panned using two fingers on a touch screen, as well as with the middle mouse button</li>
<li>Toasts now show an "Open Location" button when saving data, bringing you to the saved file location</li>
<li>Translate/multiply entries now get a red CSS when input value is invalid, while the corresponding button is disabled</li>
</ul>
<p>Changed behaviour:</p>
<ul>
Expand Down
2 changes: 2 additions & 0 deletions data/whats_new
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<li>Importing column data is now more robust, supporting expressions as data points</li>
<li>Pinch and ctrl+scroll to zoom gestures are now supported on the canvas</li>
<li>The canvas can now be panned using two fingers on a touch screen, as well as with the middle mouse button</li>
<li>Toasts now show an "Open Location" button when saving data, bringing you to the saved file location</li>
<li>Translate/multiply entries now get a red CSS when input value is invalid, while the corresponding button is disabled</li>
</ul>
<p>Changed behaviour:</p>
<ul>
Expand Down
24 changes: 23 additions & 1 deletion src/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from gi.repository import GLib, GObject, Gio, Graphs, Gtk

from graphs import actions, file_import, file_io, migrate, styles, ui
from graphs import (actions, file_import, file_io, migrate, styles, ui,
utilities)
from graphs.data import Data

from matplotlib import font_manager
Expand Down Expand Up @@ -221,6 +222,14 @@ def do_activate(self):
stack_switcher.set_hexpand("true")
window.get_stack_switcher_box().prepend(stack_switcher)
window.set_title(self.props.name)
actions = ["multiply_x", "multiply_y", "translate_x",
"translate_y"]
entries = [getattr(window, f"get_{action}_entry")()
for action in actions]
buttons = [getattr(window, f"get_{action}_button")()
for action in actions]
for entry, button in zip(entries, buttons):
entry.connect("notify::text", self.set_entry_css, button)
self.set_window(window)
controller = Gtk.EventControllerKey.new()
controller.connect("key-pressed", self.on_key_press_event)
Expand All @@ -234,3 +243,16 @@ def do_activate(self):
"notify::items", ui.enable_axes_actions, self)
ui.enable_axes_actions(self, None, self)
window.present()

def set_entry_css(self, entry, _string, button):
try:
value = utilities.string_to_float(entry.get_text())
if value is None and entry.get_text() != "":
entry.add_css_class("error")
button.set_sensitive(False)
return
entry.remove_css_class("error")
button.set_sensitive(True)
except (ValueError, TypeError):
entry.add_css_class("error")
button.set_sensitive(False)
2 changes: 1 addition & 1 deletion src/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def _redraw(self, *_args):
# Set tick where requested, as long as that axis is not occupied
# and visible
if (params[f"xtick.{directions[0]}"]
or params[f"ytick.{directions[1]}"]) :
or params[f"ytick.{directions[1]}"]):
axis.tick_params(which=ticks, **{
direction: (draw_frame and not visible_axes[i]
or direction in directions)
Expand Down
12 changes: 12 additions & 0 deletions src/window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ namespace Graphs {
[GtkChild]
public unowned Entry multiply_y_entry { get; }

[GtkChild]
public unowned Button translate_x_button { get; }

[GtkChild]
public unowned Button translate_y_button { get; }

[GtkChild]
public unowned Button multiply_x_button { get; }

[GtkChild]
public unowned Button multiply_y_button { get; }

[GtkChild]
public unowned ListBox item_list { get; }

Expand Down