-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.py
95 lines (79 loc) · 2.64 KB
/
window.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
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import pygtk
pygtk.require('2.0')
import gtk, gobject, cairo
class Screen(gtk.DrawingArea):
__gsignals__ = { "expose-event": "override" }
def __init__(self):
gtk.DrawingArea.__init__(self)
self.widgets = []
def add(self, widget, x, y, w, h):
widget.__x = x
widget.__y = y
widget.__w = w
widget.__h = h
self.widgets.append(widget)
def remove(self, widget):
self.widgets.remove(widget)
def do_expose_event(self, event):
cr = self.window.cairo_create()
cr.rectangle(event.area.x, event.area.y,
event.area.width, event.area.height)
cr.clip()
self.draw(cr, *self.window.get_size())
def draw(self, cr, width, height):
cr.set_source_rgb(1.0, 1.0, 1.0)
cr.rectangle(0, 0, width, height)
cr.fill()
cr.translate(0, height)
cr.scale(width/1.0, -height/1.0)
cr.scale(9.0/16.0, 1.0)
for widget in self.widgets:
cr.save()
cr.translate(widget.__x, widget.__y)
cr.scale(widget.__w/1.0, widget.__h/1.0)
widget.draw(cr, widget.__w, widget.__h)
cr.restore()
class Window:
def __init__(self, quit=None, width=1280, height=720, resizable=True, fullscreen=False):
self.quit = quit
self.window = gtk.Window()
if fullscreen:
self.window.fullscreen()
elif width and height:
self.window.set_resizable(resizable)
self.window.set_geometry_hints(min_width=width, min_height=height)
if self.quit:
self.window.connect("delete-event", quit)
self.screen = Screen()
self.screen.show()
self.window.add(self.screen)
self.window.present()
def add(self, widget, x, y, w, h):
self.screen.add(widget, x, y, w, h)
def remove(self, widget):
self.screen.remove(widget)
def redraw(self):
self.window.queue_draw()
while gtk.events_pending():
gtk.main_iteration(block=False)
return True
def run(self):
gtk.main()