[gnome-calculator] Adds Keyboard Mode
- From: Arth Patel <arthpatel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Adds Keyboard Mode
- Date: Mon, 22 Dec 2014 18:42:42 +0000 (UTC)
commit 9effde58a70835ac2e35c75bee56069299e0bd1b
Author: elitalobo <loboelita gmail com>
Date: Mon Aug 18 11:42:06 2014 +0530
Adds Keyboard Mode
Signed-off-by: PioneerAxon <arth svnit gmail com>
data/menu.ui | 5 +++
data/org.gnome.calculator.gschema.xml | 1 +
src/math-buttons.vala | 3 +-
src/math-display.vala | 3 +-
src/math-history.vala | 2 +
src/math-window.vala | 53 ++++++++++++++++++++++++++++----
6 files changed, 58 insertions(+), 9 deletions(-)
---
diff --git a/data/menu.ui b/data/menu.ui
index 821cc65..8a7a501 100644
--- a/data/menu.ui
+++ b/data/menu.ui
@@ -47,6 +47,11 @@
<attribute name="action">win.mode</attribute>
<attribute name="target">programming</attribute>
</item>
+ <item>
+ <attribute name="label" translatable="yes">Keyboard Mode</attribute>
+ <attribute name="action">win.mode</attribute>
+ <attribute name="target">keyboard</attribute>
+ </item>
</section>
</menu>
</interface>
diff --git a/data/org.gnome.calculator.gschema.xml b/data/org.gnome.calculator.gschema.xml
index 2a21b4e..45f95ab 100644
--- a/data/org.gnome.calculator.gschema.xml
+++ b/data/org.gnome.calculator.gschema.xml
@@ -11,6 +11,7 @@
<value value="1" nick="advanced"/>
<value value="2" nick="financial"/>
<value value="3" nick="programming"/>
+ <value value="4" nick="keyboard"/>
</enum>
<enum id="org.gnome.calculator.AngleUnit">
<value value="0" nick="radians"/>
diff --git a/src/math-buttons.vala b/src/math-buttons.vala
index 3c49726..088b591 100644
--- a/src/math-buttons.vala
+++ b/src/math-buttons.vala
@@ -13,7 +13,8 @@ public enum ButtonMode
BASIC,
ADVANCED,
FINANCIAL,
- PROGRAMMING
+ PROGRAMMING,
+ KEYBOARD
}
public class MathButtons : Gtk.Box
diff --git a/src/math-display.vala b/src/math-display.vala
index 863f817..6d44d98 100644
--- a/src/math-display.vala
+++ b/src/math-display.vala
@@ -44,12 +44,13 @@ public class MathDisplay : Gtk.Viewport
font_desc.set_size (16 * Pango.SCALE);
source_view.override_font (font_desc);
source_view.set_name ("displayitem");
+ source_view.set_size_request (20, 20);
source_view.get_accessible ().set_role (Atk.Role.EDITBAR);
//FIXME:<property name="AtkObject::accessible-description" translatable="yes" comments="Accessible
description for the area in which results are displayed">Result Region</property>
source_view.key_press_event.connect (key_press_cb);
create_autocompletion ();
- main_box.pack_start (scrolled_window, true, true, 0);
+ main_box.pack_start (scrolled_window, false, false, 0);
scrolled_window.add (source_view); /* Adds ScrolledWindow to source_view for displaying long
equations */
scrolled_window.show ();
diff --git a/src/math-history.vala b/src/math-history.vala
index 3d24680..9e7999a 100644
--- a/src/math-history.vala
+++ b/src/math-history.vala
@@ -29,6 +29,8 @@ public class HistoryView : Gtk.Box
scroll_window.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
scroll_window.set_placement (Gtk.CornerType.TOP_LEFT);
scroll_window.add (listbox);
+ scroll_window.set_vexpand (true);
+ listbox.set_vexpand (true);
scroll_window.set_size_request (100, 100);
scroll_window.size_allocate.connect (scroll_bottom);
main_box.add (scroll_window);
diff --git a/src/math-window.vala b/src/math-window.vala
index 4ba7b07..eb4743c 100644
--- a/src/math-window.vala
+++ b/src/math-window.vala
@@ -16,15 +16,15 @@ public class MathWindow : Gtk.ApplicationWindow
private MathDisplay _display;
public MathDisplay display { get { return _display; } }
-
+ private MathConverter converter;
private MathButtons _buttons;
public MathButtons buttons { get { return _buttons; } }
private bool right_aligned;
-
+ private bool remove_buttons;
private Gtk.MenuButton menu_button;
private Gtk.HeaderBar headerbar;
-
+ private Gtk.Box vbox;
private Gtk.Label mode_label;
private const ActionEntry[] window_entries =
@@ -45,7 +45,9 @@ public class MathWindow : Gtk.ApplicationWindow
role = "gnome-calculator";
resizable = false;
-
+ converter = new MathConverter (_equation);
+ converter.set_category (null);
+ converter.set_conversion (equation.source_units, equation.target_units);
add_action_entries (window_entries, this);
var builder = new Gtk.Builder ();
@@ -88,15 +90,17 @@ public class MathWindow : Gtk.ApplicationWindow
add (main_vbox);
main_vbox.show ();
- var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
+ vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
vbox.border_width = 6;
+ vbox.set_vexpand (true);
+ vbox.pack_start (converter, false, true, 0);
main_vbox.pack_start (vbox, true, true, 0);
vbox.show ();
var scrolled_window = new Gtk.ScrolledWindow (null, null);
scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER);
scrolled_window.set_shadow_type (Gtk.ShadowType.IN);
- vbox.pack_start (scrolled_window, false, false, 0);
+ vbox.pack_start (scrolled_window, false, true, 0);
scrolled_window.get_hadjustment ().changed.connect (scroll_changed_cb);
scrolled_window.get_hadjustment ().value_changed.connect (scroll_value_changed_cb);
right_aligned = true;
@@ -108,7 +112,20 @@ public class MathWindow : Gtk.ApplicationWindow
display.show ();
_buttons = new MathButtons (equation);
- vbox.pack_start (buttons, true, true, 0);
+
+ if (_buttons.mode != ButtonMode.KEYBOARD) /* Checks if the calculator is in Keyboard mode or not */
+ {
+ vbox.pack_start (buttons, true, true, 0); /* Packs buttons if not in keyboard mode. */
+ remove_buttons = false;
+ converter.set_visible (false);
+ }
+ else
+ {
+ remove_buttons = true;
+ converter.set_visible (true); /* Unpacks buttons if in keyboard mode */
+ resizable = true;
+ }
+
buttons.show ();
buttons.notify["mode"].connect (mode_changed_cb);
mode_changed_cb ();
@@ -140,6 +157,26 @@ public class MathWindow : Gtk.ApplicationWindow
mode_label.label = _("Programming Mode");
action.set_state (new Variant.string ("programming"));
break;
+
+ case ButtonMode.KEYBOARD:
+ mode_label.label = _("Keyboard Mode");
+ action.set_state (new Variant.string ("keyboard"));
+ break;
+ }
+
+ if (remove_buttons == true && buttons.mode != ButtonMode.KEYBOARD)
+ {
+ vbox.pack_start (buttons, true, true, 0); /* Packs buttons when calculator is switched from
keyboard mode to any other mode */
+ remove_buttons = false;
+ converter.set_visible (false);
+ resizable = false;
+ }
+ else if (remove_buttons == false && buttons.mode == ButtonMode.KEYBOARD)
+ {
+ vbox.remove (vbox.get_children ().nth_data (2)); /* Unpacks buttons when switched to keyboard
mode */
+ remove_buttons = true;
+ converter.set_visible (true); /* Converter above the display window is set to visible. */
+ resizable = true;
}
}
@@ -242,6 +279,8 @@ public class MathWindow : Gtk.ApplicationWindow
mode = ButtonMode.FINANCIAL;
else if (mode_str == "programming")
mode = ButtonMode.PROGRAMMING;
+ else if (mode_str == "keyboard")
+ mode = ButtonMode.KEYBOARD;
else assert_not_reached ();
buttons.mode = mode;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]