-
Notifications
You must be signed in to change notification settings - Fork 0
/
guiexample.py
136 lines (115 loc) · 4.49 KB
/
guiexample.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
130
131
132
133
134
135
136
import Tkinter
from Tkinter import Tk, BOTH, Label
from ttk import Frame, Button, Style
from PIL import Image, ImageTk
import zmqreply
import pygame
import threading
import musicplayer
import time
import Queue
class Example(Frame):
def __init__(self, parent, queue, musicplayer):
Frame.__init__(self, parent)
self.parent = parent
self.weight = 500
self.height = 400
self.queue = queue
self.musicplayer = musicplayer
self.pictures = ["hd_1.jpg", "hd_2.jpg", "hd_3.jpg", "hd_4.jpg", "hd_5.jpg"];
self.centerWindow()
self.initUI()
'''
self.showPic = 1
self.playSlides()
'''
def initUI(self):
self.parent.title("Example")
self.pack(fill=BOTH, expand = 1)
self.style = Style()
self.style.theme_use("default")
frame = Frame(self, relief=Tkinter.RAISED, borderwidth=1)
frame.pack(fill=BOTH, expand=1)
okButton = Button(self, text = "OK")
okButton.place(x = self.width - 200, y = self.height - 100)
quitButton = Button(self.parent, text = "QUIT")
quitButton.place(x = self.width - 100, y = self.height - 100)
scale = 0.75
self.wow_pic = Image.open("hd_1.jpg")
self.wow_pic = self.wow_pic.resize((int(self.width*scale), int(self.height*scale)))
self.wow_pic_tk = ImageTk.PhotoImage(self.wow_pic)
self.label_wow_pic = Label(self, image = self.wow_pic_tk)
self.label_wow_pic.image = self.wow_pic_tk
self.label_wow_pic.place(x = 10, y = 10)
info_x = int(self.width*scale) + 20
label_text_area = Tkinter.Label(self, text = "Message received:")
label_text_area.place(x = info_x, y = 10)
self.text_area = Tkinter.Text(self, height = 10, width = 40)
self.text_area.place(x = info_x, y = 30)
def centerWindow(self):
self.width = self.parent.winfo_screenwidth()
self.height = self.parent.winfo_screenheight()
self.queue.put("Width: " + str(self.width) + " Height: " + str(self.height))
self.parent.geometry('%dx%d+%d+%d' % (self.width, self.height, 0, 0))
def insertText(self, str):
self.text_area.insert(Tkinter.INSERT, "\n" + str)
def showPicture(self, img_name):
self.label_wow_pic.destroy()
scale = 0.75
self.wow_pic = Image.open(img_name)
self.wow_pic = self.wow_pic.resize((int(self.width*scale), int(self.height*scale)))
self.wow_pic_tk = ImageTk.PhotoImage(self.wow_pic)
self.label_wow_pic = Label(self, image = self.wow_pic_tk)
self.label_wow_pic.image = self.wow_pic_tk
self.label_wow_pic.place(x = 10, y = 10)
def playMusic(self):
pygame.mixer.init()
pygame.mixer.music.load("1.mp3")
pygame.mixer.music.play()
def pauseMusic(self):
self.musicthread = threading.Thread(target = self.musicplayer.play)
self.musicthread.start()
def playSlides(self):
self.showPic = 1
self.currentSlideNo = 0;
self.showSlidesThread = threading.Thread(target = self.playSlidesClock)
self.showSlidesThread.start()
def playSlidesClock(self):
#self.queue.put("next_picture");
while True:
if(self.showPic == 0):
break;
self.queue.put("next_picture");
time.sleep(5);
def nextSlide(self):
self.currentSlideNo = (self.currentSlideNo + 1) % len(self.pictures)
self.showPicture(self.pictures[self.currentSlideNo])
def processIncoming(self):
while self.queue.qsize():
try:
msg = self.queue.get(0)
print "From queue, get msg:", msg
if(msg == "show_text"):
self.insertText("I need to show a text")
elif(msg == "show_picture"):
self.showPic = 1
self.playSlides()
elif(msg == "play_music"):
self.playMusic()
elif(msg == "pause_music"):
self.pauseMusic()
elif(msg == "next_picture"):
self.nextSlide()
else:
self.insertText(msg)
except:
pass
def main():
queue = Queue.Queue()
parent = Tk()
musicplayer1 = musicplayer.MusicPlayer()
gui = Example(parent, queue, musicplayer1)
#client.endApplication()
parent.mainloop()
if __name__ == '__main__':
main()