forked from meizhitu/100programhomework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
100-23-literal-8.py
61 lines (50 loc) · 1.95 KB
/
100-23-literal-8.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
__author__ = 'rui'
#coding=utf-8
import pygtk
pygtk.require("2.0")
import gtk
openWindowCount = 0
class PostItWindow:
def __init__(self):
self.gladeFile = "res/postit.glade"
self.builder = gtk.Builder()
self.builder.add_from_file(self.gladeFile)
self.mainWindow = self.builder.get_object('postItWindow')
self.tvInput = self.builder.get_object('tvInput')
self.btnEdit = self.builder.get_object('buttonEdit')
self.btnColor = self.builder.get_object('colorbutton')
self.builder.connect_signals(self)
if self.mainWindow:
self.mainWindow.connect('destroy', self.destroy)
self.mainWindow.set_title("即时贴")
self.mainWindow.show_all()
def destroy(self, widget, data=None):
global openWindowCount
openWindowCount -= 1
if openWindowCount == 0:
gtk.main_quit()
def on_buttonDo_clicked(self, *args):
w = PostItWindow()
global openWindowCount
openWindowCount += 1
def on_colorbutton_color_set(self, *args):
color = self.btnColor.get_color()
self.btnEdit.modify_bg(gtk.STATE_NORMAL, color)
print ('You have selected the color:%d %d %d' % (color.red, color.green, color.blue))
def on_tvInput_key_press_event(self, widget, event):
ctrl = event.state & gtk.gdk.CONTROL_MASK
alt = event.state & gtk.gdk.MOD1_MASK
shift = event.state & gtk.gdk.SHIFT_MASK
if event.keyval == 65293 and ctrl:
self.tvInput.set_size_request(1, 1)
text_buffer = self.tvInput.get_buffer()
result = text_buffer.get_text(text_buffer.get_start_iter(), text_buffer.get_end_iter())
self.btnEdit.set_label(result)
return True
return False
def on_buttonEdit_clicked(self, *args):
self.tvInput.set_size_request(220, 220)
if __name__ == "__main__":
w = PostItWindow()
openWindowCount += 1
gtk.main()