Skip to content

Commit 1b53252

Browse files
committed
Connect some number and function buttons, better format binary result
1 parent d380b60 commit 1b53252

File tree

7 files changed

+57
-14
lines changed

7 files changed

+57
-14
lines changed

data/ui/programmer_display.blp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ template $PebblesProgrammerDisplay: $PebblesDisplay {
135135
Label hex_number_label {
136136
label: bind template.hex_number_value;
137137
xalign: 0;
138+
margin-top: 3;
138139

139140
styles [
140141
"monospace"
@@ -149,6 +150,7 @@ template $PebblesProgrammerDisplay: $PebblesDisplay {
149150
Label dec_number_label {
150151
label: bind template.dec_number_value;
151152
xalign: 0;
153+
margin-top: 3;
152154

153155
styles [
154156
"monospace"
@@ -163,6 +165,7 @@ template $PebblesProgrammerDisplay: $PebblesDisplay {
163165
Label oct_number_label {
164166
label: bind template.oct_number_value;
165167
xalign: 0;
168+
margin-top: 3;
166169

167170
styles [
168171
"monospace"
@@ -183,6 +186,7 @@ template $PebblesProgrammerDisplay: $PebblesDisplay {
183186
single-line-mode: false;
184187
xalign: 0;
185188
yalign: 0;
189+
margin-top: 3;
186190

187191
styles [
188192
"monospace"

data/ui/programmer_view.blp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ template $PebblesProgrammerView: $PebblesView {
8989
}
9090

9191
$PebblesButton lsh_rsh_button {
92-
name: "lsh";
92+
name: "l";
9393
label_text: "Lsh";
9494
tooltip_desc: _("Left Shift");
9595
focus-on-click: false;
@@ -232,6 +232,8 @@ template $PebblesProgrammerView: $PebblesView {
232232
row: 1;
233233
column: 4;
234234
}
235+
236+
clicked => $on_click_function();
235237
}
236238

237239
$PebblesButton four_button {
@@ -319,6 +321,8 @@ template $PebblesProgrammerView: $PebblesView {
319321
row: 2;
320322
column: 4;
321323
}
324+
325+
clicked => $on_click_function();
322326
}
323327

324328
$PebblesButton one_button {
@@ -406,6 +410,8 @@ template $PebblesProgrammerView: $PebblesView {
406410
row: 3;
407411
column: 4;
408412
}
413+
414+
clicked => $on_click_function();
409415
}
410416

411417
$PebblesButton zero_button {
@@ -470,6 +476,8 @@ template $PebblesProgrammerView: $PebblesView {
470476
row: 4;
471477
column: 3;
472478
}
479+
480+
clicked => $on_click_function();
473481
}
474482

475483
$PebblesButton result_button_p {
@@ -616,6 +624,7 @@ template $PebblesProgrammerView: $PebblesView {
616624
}
617625

618626
$PebblesButton or_button {
627+
name: "o";
619628
label_text: "Or";
620629
tooltip_desc: _("Bitwise OR (TRUE for any input being TRUE)");
621630
accel_markup: "O";
@@ -632,7 +641,7 @@ template $PebblesProgrammerView: $PebblesView {
632641
column: 2;
633642
}
634643

635-
// clicked => $on_click_function();
644+
clicked => $on_click_function();
636645
}
637646

638647
$PebblesButton memory_minus_button {
@@ -709,7 +718,7 @@ template $PebblesProgrammerView: $PebblesView {
709718
column: 2;
710719
}
711720

712-
// clicked => $on_click_function();
721+
clicked => $on_click_function();
713722
}
714723

715724
$PebblesButton memory_recall_button {
@@ -786,7 +795,7 @@ template $PebblesProgrammerView: $PebblesView {
786795
column: 2;
787796
}
788797

789-
// clicked => $on_click_function();
798+
clicked => $on_click_function();
790799
}
791800

792801
$PebblesButton memory_clear_button {

src/Common.vala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,18 @@ namespace Pebbles {
203203
public static string get_local_separator_symbol () {
204204
return Posix.nl_langinfo (Posix.NLItem.THOUSEP);
205205
}
206+
207+
public static string remove_leading_zeroes (string text) {
208+
if (text == "0") {
209+
return "0";
210+
}
211+
int n = -1;
212+
for (int i = 0; i < text.length; i++) {
213+
if (text.get_char(i) != '0') {
214+
n = i;
215+
break;
216+
}
217+
}
218+
return text.substring(n);
219+
}
206220
}

src/components/EntryFormatter.vala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ namespace Pebbles {
7373
"×": {"default": " × ", "len_gain": 2},
7474
"*": {"default": " × ", "len_gain": 2},
7575
"÷": {"default": " ÷ ", "len_gain": 2},
76-
"/": {"default": " ÷ ", "len_gain": 2}
76+
"/": {"default": " ÷ ", "len_gain": 2},
77+
",": {"default": " lsh ", "len_gain": 4},
78+
".": {"default": " rsh ", "len_gain": 4},
79+
"<": {"default": " rsh ", "len_gain": 4},
80+
">": {"default": " rsh ", "len_gain": 4},
81+
"l": {"default": " lsh ", "len_gain": 4},
82+
"L": {"default": " rsh ", "len_gain": 4}
7783
}
7884
""";
7985

src/core/programmer_calculator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ProgrammersCalculator():
3434
['x', 'p', 'n', '|']
3535
]
3636

37+
3738
def __init__(self, memory: ContextualMemory):
3839
self.memory = memory
3940
self.stored_tokens: list[_ProgToken] = [
@@ -160,8 +161,6 @@ def convert_number_system(self,
160161
return converted
161162

162163

163-
164-
165164
@staticmethod
166165
def convert_signed_binary_to_decimal(binary: str) -> int:
167166
"""

src/shell/views/ProgrammerView.vala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ namespace Pebbles {
209209
}
210210

211211
[GtkCallback]
212-
protected void on_click_button () {
213-
212+
protected void on_click_button (Gtk.Button btn) {
213+
display.write (btn.name);
214214
}
215215

216216
[GtkCallback]
217-
protected void on_click_function () {
218-
217+
protected void on_click_function (Gtk.Button btn) {
218+
display.write (shift_button.active ? btn.name.up () : btn.name);
219219
}
220220

221221
public void open_bit_grid () {

src/shell/widgets/displays/ProgrammerDisplay.vala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ namespace Pebbles {
7979
);
8080
main_entry.set_position (-1);
8181
entry_formatter.disabled = false;
82-
main_label.set_text (window.on_programmer_convert_token (main_label.get_text (), _number_system, value, settings.global_word_length));
82+
var answer_text = window.on_programmer_convert_token (main_label.get_text (), _number_system, value, settings.global_word_length);
83+
if (value == BINARY) {
84+
answer_text = remove_leading_zeroes (answer_text);
85+
}
86+
87+
main_label.set_text (answer_text);
8388
}
8489

8590
_number_system = value;
@@ -197,7 +202,7 @@ namespace Pebbles {
197202
if (result != "E") {
198203
add_css_class ("fade");
199204
Timeout.add (100, () => {
200-
main_label.set_text (result);
205+
main_label.set_text (remove_leading_zeroes (result));
201206
remove_css_class ("fade");
202207
return false;
203208
});
@@ -216,6 +221,12 @@ namespace Pebbles {
216221
main_entry.set_position (-1);
217222
}
218223

224+
public void write (string str) {
225+
int position = main_entry.get_position ();
226+
main_entry.do_insert_text (str, str.length, ref position);
227+
main_entry.set_position (position);
228+
}
229+
219230
private void display_all_number_systems () {
220231
var parser = new Json.Parser ();
221232
try {
@@ -256,7 +267,7 @@ namespace Pebbles {
256267
protected bool input_handler (string full_expression, int input_length, string input_char) {
257268
display_all_number_systems ();
258269

259-
if (!entry_formatter.is_rule_present (input_char)) {
270+
if (input_char != "" && !entry_formatter.is_rule_present (input_char)) {
260271
if (settings.number_system == NumberSystem.BINARY && not_binary (input_char)) {
261272
return true;
262273
}

0 commit comments

Comments
 (0)