-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.py
61 lines (52 loc) · 2.13 KB
/
MainWindow.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
import Tkinter as Tk
import tkFileDialog
from PIL import ImageTk
from Drawer import Drawer
WIDTH = 800
HEIGHT = 800
class MainWindow(Tk.Tk):
def __init__(self):
Tk.Tk.__init__(self)
self.toppanel = None
self.botpanel = None
self.canvas = None
self.filter = None
self.combobox = None
self.img = None
self.startX = None
self.startY = None
self.drawer = None
self.initialize()
def initialize(self):
self.title = "CGP2"
self.toppanel = Tk.Frame(self)
self.toppanel.pack(side=Tk.TOP)
self.botpanel = Tk.Frame(self)
self.botpanel.pack()
self.canvas = Tk.Canvas(self.botpanel, width=WIDTH, height=HEIGHT, bg='white')
self.img = Tk.PhotoImage(width=WIDTH, height=HEIGHT)
self.canvas.create_image((0, 0), image=self.img, anchor="nw")
self.canvas.bind('<ButtonPress-1>', self.onStart)
self.canvas.bind('<ButtonRelease-1>', self.onEnd)
self.canvas.pack(fill=Tk.BOTH, expand=1)
combooptions = ["Symmetric bresenham", "Midpoint circle algorithm", "Xiaolin Wu Line", "Xiaolin Wu Circle"]
self.filter = Tk.StringVar(self)
self.filter.set(combooptions[0])
self.combobox = apply(Tk.OptionMenu, (self.toppanel, self.filter)+tuple(combooptions))
self.combobox.pack(side=Tk.LEFT)
self.drawer = Drawer(self.img)
self.mainloop()
def onStart(self, event):
self.startX = event.x
self.startY = event.y
def onEnd(self, event):
if(self.filter.get() == "Symmetric bresenham"):
self.drawer.drawsymbresenham(self.startX, self.startY, event.x, event.y)
elif (self.filter.get() == "Midpoint circle algorithm"):
self.drawer.circle(self.startX, self.startY, event.x, event.y)
elif (self.filter.get() == "Xiaolin Wu Line"):
self.drawer.xaolinwuline(self.startX, self.startY, event.x, event.y)
elif (self.filter.get() == "Xiaolin Wu Circle"):
self.drawer.xaolinwuciricle(self.startX, self.startY, event.x, event.y)
if __name__ == "__main__":
mw = MainWindow()