Skip to content

Commit

Permalink
Fix some input stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhadeepJasu committed Jan 4, 2025
1 parent d27e814 commit c498f38
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MESSAGES CONTROL]
disable=import-error
17 changes: 17 additions & 0 deletions com.github.subhadeepjasu.pebbles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
app-id: com.github.subhadeepjasu.pebbles
runtime: io.elementary.Platform
runtime-version: '8'
sdk: io.elementary.Sdk
command: com.github.subhadeepjasu.pebbles
finish-args:
- '--share=ipc'
- '--socket=fallback-x11'
- '--socket=wayland'
- '--share=network'
- '--metadata=X-DConf=migrate-path=/com/github/subhadeepjasu/pebbles'
modules:
- name: pebbles
buildsystem: meson
sources:
- type: dir
path: .
2 changes: 1 addition & 1 deletion data/ui/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ template $PebblesWindow: Adw.ApplicationWindow {
orientation: horizontal;

$PebblesStyledButton angle_mode {
label_text: _("DEG");
label_text: "DEG";
tooltip_desc: _("Switch angle mode");
accel_markup: "F8";
width-request: 64;
Expand Down
67 changes: 29 additions & 38 deletions src/shell/ScientificDisplay.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,14 @@ namespace Pebbles {
return false;
}, Priority.LOW);

// TODO: Do token check before inserting any character
main_entry.get_delegate ().insert_text.connect_after ((ch, length) => {
var text = main_entry.text;
Idle.add (() => {
if (main_entry.text.has_prefix ("0") && main_entry.text != null) {
if (main_entry.text_length > 1) {
main_entry.text = main_entry.text.slice (1, main_entry.text_length);
main_entry.set_position ((int) main_entry.text_length);
}
}

if (main_entry.text.contains ("*")) {
Idle.add (() => {
main_entry.text = main_entry.text.replace ("*", " × ");
main_entry.set_position ((int) main_entry.text_length);
return false;
});
}

if (main_entry.text.contains ("/")) {
Idle.add (() => {
main_entry.text = main_entry.text.replace ("/", " ÷ ");
main_entry.set_position ((int) main_entry.text_length);
return false;
});
if (text.length > 1 && text.has_prefix ("0")) {
main_entry.text = text.substring (1);
main_entry.set_position (1);
return false;
}

if (length > 1) {
Expand All @@ -100,24 +85,30 @@ namespace Pebbles {

settings = Pebbles.Settings.get_default ();
settings.changed["global-angle-unit"].connect ((key) => {
switch (settings.global_angle_unit) {
case DEG:
deg_label.opacity = 1;
rad_label.opacity = 0.2;
grad_label.opacity = 0.2;
break;
case RAD:
deg_label.opacity = 0.2;
rad_label.opacity = 1;
grad_label.opacity = 0.2;
break;
case GRAD:
deg_label.opacity = 0.2;
rad_label.opacity = 0.2;
grad_label.opacity = 1;
break;
}
set_angle_unit (settings.global_angle_unit);
});

set_angle_unit (settings.global_angle_unit);
}

public void set_angle_unit (GlobalAngleUnit unit) {
switch (unit) {
case DEG:
deg_label.opacity = 1;
rad_label.opacity = 0.2;
grad_label.opacity = 0.2;
break;
case RAD:
deg_label.opacity = 0.2;
rad_label.opacity = 1;
grad_label.opacity = 0.2;
break;
case GRAD:
deg_label.opacity = 0.2;
rad_label.opacity = 0.2;
grad_label.opacity = 1;
break;
}
}

[GtkCallback]
Expand Down
15 changes: 15 additions & 0 deletions src/shell/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace Pebbles {
setup_evaluators ();
setup_key_events ();
setup_memory_events ();
load_settings ();
}

private void setup_theme () {
Expand Down Expand Up @@ -166,6 +167,20 @@ namespace Pebbles {
});
}

private void load_settings () {
switch (settings.global_angle_unit) {
case DEG:
angle_mode.label_text = "DEG";
break;
case RAD:
angle_mode.label_text = "RAD";
break;
case GRAD:
angle_mode.label_text = "GRA";
break;
}
}

protected void on_evaluation_completed (string data) {
Idle.add (() => {
var parser = new Json.Parser ();
Expand Down

0 comments on commit c498f38

Please sign in to comment.