-
Notifications
You must be signed in to change notification settings - Fork 14
/
abacus.py
executable file
·129 lines (101 loc) · 3.64 KB
/
abacus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2010-14, Walter Bender
# This file is part of the Abacus Activity.
# The Abacus Activity is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# The Abacus Activity is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with the Abacus Activity. If not, see <http://www.gnu.org/licenses/>.
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
from gettext import gettext as _
from abacus_window import Abacus
class AbacusMain:
ABACI = {
'b': 'binary',
'c': 'suanpan',
'f': 'fraction',
'h': 'hexadecimal',
'j': 'soroban',
'm': 'nepohualtzintzin',
'r': 'schety',
'd': 'decimal',
'C': 'caacupe',
'R': 'cuisenaire'
}
def __init__(self):
self.r = 0
self.tw = None
self.win = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
self.x = 50
self.y = 50
self.width = 800
self.height = 550
self.win.set_default_size(self.width, self.height)
self.win.move(self.x, self.y)
self.win.maximize()
self.win.set_title(_('Abacus'))
self.win.connect('delete_event', lambda w, e: Gtk.main_quit())
menu = Gtk.Menu()
for k, v in self.ABACI.items():
menu_items = Gtk.MenuItem.new_with_label(v)
menu.append(menu_items)
menu_items.connect('activate', self._switch_abacus_cb, k)
menu_items = Gtk.MenuItem.new_with_label(_('Reset'))
menu.append(menu_items)
menu_items.connect('activate', self._reset)
menu_items = Gtk.MenuItem.new_with_label(_('Quit'))
menu.append(menu_items)
menu_items.connect('activate', self.destroy)
menu_items.show()
root_menu = Gtk.MenuItem.new_with_label('Tools')
root_menu.show()
root_menu.set_submenu(menu)
vbox = Gtk.VBox()
self.win.add(vbox)
vbox.show()
menu_bar = Gtk.MenuBar()
vbox.pack_start(menu_bar, False, False, 2)
menu_bar.append(root_menu)
menu_bar.show_all()
canvas = Gtk.DrawingArea()
width = Gdk.Screen.width()
height = Gdk.Screen.height()
canvas.set_size_request(width, height)
vbox.pack_end(canvas, True, True, 0)
self.win.show()
self.abacus = Abacus(canvas)
canvas.show()
self.abacus.win = self.win
self.abacus.activity = self
self.abacus.init()
def set_title(self, title):
self.win.set_title(title)
return
def _switch_abacus_cb(self, widget, user):
value = int(float(self.abacus.mode.value()))
self.abacus.select_abacus(self.ABACI[user])
self.abacus.mode.set_value_from_number(value)
self.abacus.mode.label(self.abacus.generate_label())
return True
def _reset(self, event, data=None):
''' Reset beads to initial position '''
self.abacus.mode.reset_abacus()
self.abacus.mode.label(self.abacus.generate_label())
return
def destroy(self, event, data=None):
''' Callback for destroy event. '''
Gtk.main_quit()
def main():
Gtk.main()
return 0
if __name__ == '__main__':
AbacusMain()
main()