Skip to content

Commit 771dd6f

Browse files
committed
Fixed multiple things and integrated programmer mode with history module
1 parent 33b8b84 commit 771dd6f

15 files changed

+122
-87
lines changed

data/ui/calculus_view.blp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ template $PebblesCalculusView: $PebblesView {
5252
$PebblesButton all_clear_button {
5353
label_text: _("AC");
5454
tooltip_desc: _("All Clear");
55-
accel_markup: "Delete";
55+
accel_markup: "<Shift>BackSpace";
5656
focus-on-click: false;
57-
key: "delete";
57+
key: "<Shift>BackSpace";
5858

5959
styles [
6060
"destructive-action",

data/ui/programmer_display.blp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ template $PebblesProgrammerDisplay: $PebblesDisplay {
246246
}
247247

248248
Label main_label {
249+
label: "0";
250+
249251
styles [
250252
"lcd-label"
251253
]

data/ui/programmer_view.blp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ template $PebblesProgrammerView: $PebblesView {
5757
$PebblesButton all_clear_button {
5858
label_text: _("AC");
5959
tooltip_desc: _("All Clear");
60-
accel_markup: "Delete";
60+
accel_markup: "<Shift>BackSpace";
6161
focus-on-click: false;
62-
key: "delete";
62+
key: "<Shift>BackSpace";
6363

6464
styles [
6565
"destructive-action",
@@ -85,7 +85,7 @@ template $PebblesProgrammerView: $PebblesView {
8585
column: 1;
8686
}
8787

88-
// clicked => $on_backspace();
88+
clicked => $on_backspace();
8989
}
9090

9191
$PebblesButton lsh_rsh_button {

data/ui/scientific_view.blp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ template $PebblesScientificView: $PebblesView {
5252
$PebblesButton all_clear_button {
5353
label_text: _("AC");
5454
tooltip_desc: _("All Clear");
55-
accel_markup: "Delete";
55+
accel_markup: "<Shift>BackSpace";
5656
focus-on-click: false;
57-
key: "delete";
57+
key: "<Shift>BackSpace";
5858

5959
styles [
6060
"destructive-action",

data/ui/statistics_view.blp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ template $PebblesStatisticsView: $PebblesView {
5252
$PebblesButton all_clear_button {
5353
label_text: _("AC");
5454
tooltip_desc: _("All Clear");
55-
accel_markup: "Delete";
55+
accel_markup: "<Shift>BackSpace";
5656
focus-on-click: false;
57-
key: "delete";
57+
key: "<Shift>BackSpace";
5858

5959
styles [
6060
"destructive-action",

src/ControlsScheme.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace Pebbles {
3939
_("Close Dialog"), "Escape"
4040
},
4141
{
42-
_("All Clear"), "Delete"
42+
_("All Clear"), "<Shift>BackSpace"
4343
},
4444
{
4545
_("Copy Result"), "<Ctrl>C"

src/core/memory.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,12 @@ def get_views(self, format_func:callable, context=Pebbles.Context.SCIENTIFIC):
247247
cursor = conn.cursor()
248248
cursor.execute(ContextualMemory.HISTORY_VIEW_QUERY, (context,))
249249
history_entries = cursor.fetchall()
250-
views = [Pebbles.HistoryModel.new_for_view(id, context, inp, format_func(res))
251-
for id, inp, res in history_entries]
250+
if format_func is not None:
251+
views = [Pebbles.HistoryModel.new_for_view(id, context, inp, format_func(res))
252+
for id, inp, res in history_entries]
253+
else:
254+
views = [Pebbles.HistoryModel.new_for_view(id, context, inp, res)
255+
for id, inp, res in history_entries]
252256
conn.close()
253257
return views
254258

src/core/programmer_calculator.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def represent_binary_by_word_length (self,
197197
required_bit_length = 64
198198

199199
if len(binary_value) > required_bit_length:
200-
new_binary = binary_value[- (required_bit_length + 1) :]
200+
new_binary = binary_value[-required_bit_length:]
201201
else:
202202
pre_zeros = "0" * (required_bit_length - len(binary_value))
203203
new_binary = pre_zeros + binary_value
@@ -597,12 +597,15 @@ def evaluate(self, number_system: Pebbles.NumberSystem, wrd_length: Pebbles.Glob
597597
formatted_answer = self.bool_array_to_string(answer, wrd_length, number_system)
598598

599599
if gen_hist:
600+
token_list = [token.token for token in self.stored_tokens]
601+
expression = " ".join(token_list)
600602
self.memory.push_history(
601603
self.MODE,
602-
self.input_dict['input'],
603-
str(answer.token),
604-
{'metadata_1': number_system,
605-
'metadata_2': wrd_length
604+
expression,
605+
formatted_answer,
606+
{
607+
'metadata_1': number_system,
608+
'metadata_2': wrd_length
606609
}
607610
)
608611
result_json = json.dumps({'mode': self.MODE, 'result': formatted_answer})
@@ -668,7 +671,6 @@ def operand_pop():
668671
return operand_pop()
669672

670673

671-
672674
class _ProgToken:
673675
def __init__(self, token:str, token_type:int, number_system:Pebbles.NumberSystem):
674676
self.token = token

src/core/scientific_calculator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ def _handle_special_variables (self, token, operand_stack):
169169
operand_stack.append(self.substitutions['M'])
170170
else:
171171
operand_stack.append(float(token))
172+
173+
172174
@staticmethod
173-
def format(result: any):
175+
def format(result: any) -> str:
174176
"""
175177
Format scientific result.
176178
"""

src/shell/MainWindow.vala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ namespace Pebbles {
127127

128128
public signal bool on_key_down (string? context, uint keyval);
129129
public signal void on_key_up (string? context, uint keyval);
130+
public signal void on_all_clear (string? context);
130131
public signal void on_history_view (string context);
131132
public signal string on_history_copy (int id);
132133
public signal string on_history_insert (int id);
@@ -539,6 +540,10 @@ namespace Pebbles {
539540
set_shift_on (!lock_on);
540541
}
541542

543+
if (keyval == Gdk.Key.BackSpace && (modifier & Gdk.ModifierType.SHIFT_MASK) != 0) {
544+
on_all_clear (view_stack.visible_child_name);
545+
}
546+
542547
if ((
543548
modifier &
544549
(

0 commit comments

Comments
 (0)