@@ -43,6 +43,10 @@ def __init__(self, portal_id, bus, pos_x, pos_y, width, height, manager):
43
43
# Make configuration better
44
44
self .color_1 = 0
45
45
self .color_2 = 0
46
+ self .color_1f = 0x202020
47
+ self .color_2f = 0x202020
48
+ self ._flashing = False
49
+ self ._use_flash_color = False
46
50
self .accent_width = 64
47
51
48
52
left , right , top , bottom = manager .get_chrome_size (pos_x , pos_y , width , height )
@@ -69,23 +73,29 @@ def set_portal_size(self, pos_x, pos_y, width, height):
69
73
self .move_resize (left , top , right - left , bottom - top , self ._is_active )
70
74
71
75
def _on_paint (self , hwnd , hdc , width , height ):
72
- self ._draw_rect (hdc , 0 , 0 , width , height , self .color_1 )
76
+ c1 = self .color_1
77
+ c2 = self .color_2
78
+ if self ._use_flash_color :
79
+ c1 = self .color_1f
80
+ c2 = self .color_2f
81
+ self ._log_debug ("Using colors #{0} #{1}" .format (hex (c1 ), hex (c2 )))
82
+ self ._draw_rect (hdc , 0 , 0 , width , height , c1 )
73
83
if width >= self .accent_width * 3 :
74
84
if height >= self .accent_width * 3 :
75
85
# 4 corners of color
76
- self ._draw_rect (hdc , 0 , 0 , self .accent_width , self .accent_width , self . color_2 )
77
- self ._draw_rect (hdc , width - self .accent_width , 0 , self .accent_width , self .accent_width , self . color_2 )
78
- self ._draw_rect (hdc , 0 , height - self .accent_width , self .accent_width , self .accent_width , self . color_2 )
86
+ self ._draw_rect (hdc , 0 , 0 , self .accent_width , self .accent_width , c2 )
87
+ self ._draw_rect (hdc , width - self .accent_width , 0 , self .accent_width , self .accent_width , c2 )
88
+ self ._draw_rect (hdc , 0 , height - self .accent_width , self .accent_width , self .accent_width , c2 )
79
89
self ._draw_rect (hdc , width - self .accent_width , height - self .accent_width , self .accent_width ,
80
- self .accent_width , self . color_2 )
90
+ self .accent_width , c2 )
81
91
else :
82
92
# Vertical bars of color
83
- self ._draw_rect (hdc , 0 , 0 , self .accent_width , height , self . color_2 )
84
- self ._draw_rect (hdc , width - self .accent_width , 0 , self .accent_width , height , self . color_2 )
93
+ self ._draw_rect (hdc , 0 , 0 , self .accent_width , height , c2 )
94
+ self ._draw_rect (hdc , width - self .accent_width , 0 , self .accent_width , height , c2 )
85
95
elif height >= self .accent_width * 3 :
86
96
# Horizontal bars of color
87
- self ._draw_rect (hdc , 0 , 0 , width , self .accent_width , self . color_2 )
88
- self ._draw_rect (hdc , 0 , height - self .accent_width , width , self .accent_width , self . color_2 )
97
+ self ._draw_rect (hdc , 0 , 0 , width , self .accent_width , c2 )
98
+ self ._draw_rect (hdc , 0 , height - self .accent_width , width , self .accent_width , c2 )
89
99
90
100
# noinspection PyUnusedLocal
91
101
def _on_portal_removed (self , event_id , target_id , event_obj ):
@@ -108,21 +118,19 @@ def _on_border_size_change(self, event_id, target_id, event_obj):
108
118
109
119
# noinspection PyUnusedLocal
110
120
def _on_portal_flashing (self , event_id , target_id , event_obj ):
111
- self ._log_verbose ("Flashing portal chrome {0}" .format (self .cid ))
112
- color_c1 = self .color_1
113
- color_c2 = self .color_2
114
- color_f1 = _brighten_color (self .color_1 )
115
- color_f2 = _brighten_color (self .color_2 )
121
+ self ._log_debug ("Flashing portal chrome {0}" .format (self .cid ))
116
122
117
123
def flash ():
118
124
# Just flash once. Windows will send a message if another flash is required.
119
- self .color_1 = color_f1
120
- self .color_2 = color_f2
125
+ if self ._flashing :
126
+ return
127
+ self ._flashing = True
128
+ self ._use_flash_color = True
121
129
self .draw ()
122
130
time .sleep (self ._manager .flash_time )
123
- self .color_1 = color_c1
124
- self .color_2 = color_c2
131
+ self ._use_flash_color = False
125
132
self .draw ()
133
+ self ._flashing = False
126
134
127
135
threading .Thread (
128
136
target = flash ,
@@ -143,6 +151,8 @@ def _on_portal_activated(self, event_id, target_id, event_obj):
143
151
height = portal_size ['height' ]
144
152
145
153
self .color_1 , self .color_2 = self ._manager .active_colors
154
+ self .color_1f = _brighten_color (self .color_1 )
155
+ self .color_2f = _brighten_color (self .color_2 )
146
156
self .set_portal_size (pos_x , pos_y , width , height )
147
157
self .draw ()
148
158
@@ -160,6 +170,8 @@ def _on_portal_deactivated(self, event_id, target_id, event_obj):
160
170
height = portal_size ['height' ]
161
171
162
172
self .color_1 , self .color_2 = self ._manager .inactive_colors
173
+ self .color_1f = _brighten_color (self .color_1 )
174
+ self .color_2f = _brighten_color (self .color_2 )
163
175
self .set_portal_size (pos_x , pos_y , width , height )
164
176
self .draw ()
165
177
@@ -169,7 +181,7 @@ def _brighten_color(c):
169
181
r = (c >> 16 ) & 0xff
170
182
g = (c >> 8 ) & 0xff
171
183
b = c & 0xff
172
- return ((max (0xff , r << 1 ) << 16 ) & 0xff0000 ) | ((max (0xff , g << 1 ) << 8 ) & 0xff00 ) | (max (0xff , b << 1 ) & 0xff )
184
+ return ((min (0xff , r << 1 ) << 16 ) & 0xff0000 ) | ((min (0xff , g << 1 ) << 8 ) & 0xff00 ) | (min (0xff , b << 1 ) & 0xff )
173
185
174
186
175
187
def _darken_color (c ):
@@ -199,8 +211,8 @@ def __init__(self, bus, config):
199
211
self ._inactive_color2 = 0x404040
200
212
self ._position = 'bottom'
201
213
self ._width = 10
202
- self .flash_time = 1.2
203
- self .flash_count = 3
214
+ self .flash_time = 0.8
215
+ self .flash_count = 3 # FIXME remove
204
216
self .update_border ()
205
217
206
218
@property
@@ -287,5 +299,7 @@ def _on_portal_resized(self, event_id, target_id, event_obj):
287
299
gui = _PortalGuiWindow (target_id , self ._bus , pos_x , pos_y , width , height , self )
288
300
gui .color_1 = self ._inactive_color1
289
301
gui .color_2 = self ._inactive_color2
302
+ gui .color_1f = _brighten_color (self ._inactive_color1 )
303
+ gui .color_2f = _brighten_color (self ._inactive_color2 )
290
304
# TODO setup flash
291
305
self .__portal_map [target_id ]['gui' ] = gui
0 commit comments