-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalculator.py
executable file
·51 lines (40 loc) · 1.67 KB
/
calculator.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
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from numbers import NumbersGrid
from display import Display
from operators import OperatorsGrid
from actions import Actions
from system import CalculatorSystem
class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title='Calculator')
self.set_resizable(False)
#creates box which handles all childs
self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.add(self.box)
self.buttons_box = Gtk.Box()
self.operators_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
#objects to be added to main box
self.numbers_grid = NumbersGrid()
self.display = Display()
self.calc_system = CalculatorSystem(self.display)
self.operators_grid = OperatorsGrid(self.display, self.calc_system)
self.actions = Actions(self.display, self.calc_system)
#add objects to box
self.box.add(self.display)
self.box.add(self.buttons_box)
self.buttons_box.pack_start(self.numbers_grid, False, True, 0)
self.buttons_box.pack_start(self.operators_box, False, True, 0)
self.operators_box.pack_start(self.actions, False, True, 0)
self.operators_box.add(self.operators_grid)
#connect numbers buttons to display
self.numbers_grid.connect_to_display(self.display)
self.connect('key-release-event', self.on_key_release)
def on_key_release(self, widget, event):
self.display.on_key_release(self.display, event)
win = MainWindow()
win.connect('delete-event', Gtk.main_quit)
win.show_all()
Gtk.main()