-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.py
2452 lines (1910 loc) · 88.3 KB
/
ui.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Copyright (c) 2008, Media Modifications Ltd.
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
import gtk
from gtk import gdk
from gtk import keysyms
import gobject
import cairo
import os
import pygst
pygst.require('0.10')
import gst
import gst.interfaces
import math
import shutil
import time
import pango
import hippo
import logging
logger = logging.getLogger('record:ui.py')
#from sugar.graphics.toolcombobox import ToolComboBox
#from sugar.graphics.tray import HTray
from sugar.graphics.toolbutton import ToolButton
from sugar import profile
from sugar import util
from sugar.activity import activity
from sugar.graphics import style
from instance import Instance
from constants import Constants, istrMinutes, istrSeconds
from color import Color
from p5 import P5
from p5_button import P5Button
from p5_button import Polygon
from p5_button import Button
import glive
from glive import LiveVideoWindow
from glivex import SlowLiveVideoWindow
from gplay import PlayVideoWindow
from recorded import Recorded
from button import RecdButton
import utils
import record
import aplay
from tray import HTray
from toolbarcombobox import ToolComboBox
class UI:
dim_THUMB_WIDTH = 108
dim_THUMB_HEIGHT = 81
dim_INSET = 10
dim_PIPW = 160
dim_PIPH = 120 #pipBorder
dim_PIP_BORDER = 4
dim_PGDW = dim_PIPW + (dim_PIP_BORDER*2)
dim_PGDH = dim_PIPH + (dim_PIP_BORDER*2)
dim_CONTROLBAR_HT = 55
def __init__( self, pca ):
self.ca = pca
self.ACTIVE = False
self.LAUNCHING = True
self.ca.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
self.ca.connect("visibility-notify-event", self._visibleNotifyCb)
self.inset = self.__class__.dim_INSET
self.pgdh = self.__class__.dim_PGDH
self.pgdw = self.__class__.dim_PGDW
self.thumbTrayHt = 150 #todo: get sugar constant here
self.thumbSvgW = 124
self.thumbSvgH = 124
self.maxw = 49
self.maxh = 49
self.controlBarHt = 60
self.recordButtWd = 55
self.pipw = self.__class__.dim_PIPW
self.piph = self.__class__.dim_PIPH
#ui modes
# True when we're in full-screen mode, False otherwise
self.FULLSCREEN = False
# True when we're showing live video feed in the primary screen
# area, False otherwise (even when we are still showing live video
# in a p-i-p)
self.LIVEMODE = True
self.LAST_MODE = -1
self.LAST_FULLSCREEN = False
self.LAST_LIVE = True
self.LAST_MESHING = False
self.LAST_RECD_INFO = False
self.LAST_TRANSCODING = False
self.TRANSCODING = False
self.MESHING = False
# RECD_INFO_ON is True when the 'info' for a recording is being
# display on-screen (who recorded it, tags, etc), and False otherwise.
self.RECD_INFO_ON = False
self.UPDATE_DURATION_ID = 0
self.UPDATE_TIMER_ID = 0
self.COUNTINGDOWN = False
#init
self.mapped = False
self.centered = False
self.setup = False
#prep for when to show
self.shownRecd = None
#this includes the default sharing tab
self.toolbox = activity.ActivityToolbox(self.ca)
self.ca.set_toolbox(self.toolbox)
if glive.camera_presents:
self.photoToolbar = PhotoToolbar()
self.photoToolbar.set_sensitive( False )
self.toolbox.add_toolbar( Constants.istrPhoto, self.photoToolbar )
self.videoToolbar = VideoToolbar()
self.videoToolbar.set_sensitive( False )
self.toolbox.add_toolbar( Constants.istrVideo, self.videoToolbar )
self.tbars = { Constants.MODE_PHOTO: 1,
Constants.MODE_VIDEO: 2,
Constants.MODE_AUDIO: 3 }
else:
self.photoToolbar = None
self.videoToolbar = None
self.tbars = { Constants.MODE_AUDIO: 1 }
self.ca.m.MODE = Constants.MODE_AUDIO
self.audioToolbar = AudioToolbar()
self.audioToolbar.set_sensitive( False )
self.toolbox.add_toolbar( Constants.istrAudio, self.audioToolbar )
self.toolbox.set_current_toolbar(self.tbars[self.ca.m.MODE])
self.toolbox.remove(self.toolbox._separator)
#taken directly from toolbox.py b/c I don't know how to mod the hongry hippo
separator = hippo.Canvas()
box = hippo.CanvasBox(
border_color=Constants.colorBlack.get_int(),
background_color=Constants.colorBlack.get_int(),
box_height=style.TOOLBOX_SEPARATOR_HEIGHT,
border_bottom=style.LINE_WIDTH)
separator.set_root(box)
self.toolbox.pack_start(separator, False)
self.toolbox.separator = separator
self.TOOLBOX_SIZE_ALLOCATE_ID = self.toolbox.connect_after("size-allocate", self._toolboxSizeAllocateCb)
self.toolbox._notebook.set_property("can-focus", False)
self.toolbox.connect("current-toolbar-changed", self._toolbarChangeCb)
self.toolbox.show_all()
def serialize(self):
data = {}
if self.photoToolbar:
data['photo_timer'] = self.photoToolbar.timerCb.combo.get_active()
if self.videoToolbar:
data['video_timer'] = self.videoToolbar.timerCb.combo.get_active()
data['video_duration'] = self.videoToolbar.durCb.combo.get_active()
data['video_quality'] = self.videoToolbar.quality.combo.get_active()
data['audio_timer'] = self.audioToolbar.timerCb.combo.get_active()
data['audio_duration'] = self.audioToolbar.durCb.combo.get_active()
return data
def deserialize(self, data):
if self.photoToolbar:
self.photoToolbar.timerCb.combo.set_active(
data.get('photo_timer', 0))
if self.videoToolbar:
self.videoToolbar.timerCb.combo.set_active(
data.get('video_timer', 0))
self.videoToolbar.durCb.combo.set_active(
data.get('video_duration', 0))
self.videoToolbar.quality.combo.set_active(
data.get('video_quality', 0))
self.audioToolbar.timerCb.combo.set_active(data.get('audio_timer', 0))
self.audioToolbar.durCb.combo.set_active(data.get('audio_duration'))
def _toolboxSizeAllocateCb( self, widget, event ):
self.toolbox.disconnect( self.TOOLBOX_SIZE_ALLOCATE_ID)
toolboxHt = self.toolbox.size_request()[1]
self.vh = gtk.gdk.screen_height()-(self.thumbTrayHt+toolboxHt+self.controlBarHt)
self.vw = int(self.vh/.75)
self.letterBoxW = (gtk.gdk.screen_width() - self.vw)/2
self.letterBoxVW = (self.vw/2)-(self.inset*2)
self.letterBoxVH = int(self.letterBoxVW*.75)
self.setUpWindows()
#now that we know how big the toolbox is, we can layout more
gobject.idle_add( self.layout )
def layout( self ):
self.mainBox = gtk.VBox()
self.ca.set_canvas(self.mainBox)
topBox = gtk.HBox()
self.mainBox.pack_start(topBox, expand=True)
leftFill = gtk.VBox()
leftFill.set_size_request( self.letterBoxW, -1 )
self.leftFillBox = gtk.EventBox( )
self.leftFillBox.modify_bg( gtk.STATE_NORMAL, Constants.colorBlack.gColor )
leftFill.add( self.leftFillBox )
topBox.pack_start( leftFill, expand=True )
centerVBox = gtk.VBox()
centerVBox.modify_bg(gtk.STATE_NORMAL, Constants.colorBlack.gColor)
topBox.pack_start( centerVBox, expand=True )
self.centerBox = gtk.EventBox()
self.centerBox.set_size_request(self.vw, -1)
self.centerBox.modify_bg(gtk.STATE_NORMAL, Constants.colorBlack.gColor)
centerVBox.pack_start( self.centerBox, expand=True )
centerSizer = gtk.VBox()
centerSizer.set_size_request(self.vw, -1)
centerSizer.modify_bg(gtk.STATE_NORMAL, Constants.colorBlack.gColor)
self.centerBox.add(centerSizer)
self.bottomCenter = gtk.EventBox()
self.bottomCenter.modify_bg(gtk.STATE_NORMAL, Constants.colorBlack.gColor)
self.bottomCenter.set_size_request(self.vw, self.controlBarHt)
centerVBox.pack_start( self.bottomCenter, expand=False )
#into the center box we can put this guy...
self.backgdCanvasBox = gtk.VBox()
self.backgdCanvasBox.modify_bg(gtk.STATE_NORMAL, Constants.colorBlack.gColor)
self.backgdCanvasBox.set_size_request(self.vw, -1)
self.backgdCanvas = PhotoCanvas()
self.backgdCanvas.set_size_request(self.vw, self.vh)
self.backgdCanvasBox.pack_start( self.backgdCanvas, expand=False )
#or this guy...
self.infoBox = gtk.EventBox()
self.infoBox.modify_bg( gtk.STATE_NORMAL, Constants.colorButton.gColor )
iinfoBox = gtk.VBox(spacing=self.inset)
self.infoBox.add( iinfoBox )
iinfoBox.set_size_request(self.vw, -1)
iinfoBox.set_border_width(self.inset)
rightFill = gtk.VBox()
rightFill.set_size_request( self.letterBoxW, -1 )
rightFillBox = gtk.EventBox()
rightFillBox.modify_bg( gtk.STATE_NORMAL, Constants.colorBlack.gColor )
rightFill.add( rightFillBox )
topBox.pack_start( rightFill, expand=True )
#info box innards:
self.infoBoxTop = gtk.HBox()
iinfoBox.pack_start( self.infoBoxTop, expand=True )
self.infoBoxTopLeft = gtk.VBox(spacing=self.inset)
self.infoBoxTop.pack_start( self.infoBoxTopLeft )
self.infoBoxTopRight = gtk.VBox()
self.infoBoxTopRight.set_size_request(self.letterBoxVW, -1)
self.infoBoxTop.pack_start( self.infoBoxTopRight )
self.namePanel = gtk.HBox()
leftInfBalance = gtk.VBox()
self.nameLabel = gtk.Label("<b><span foreground='white'>"+Constants.istrTitle+"</span></b>")
self.nameLabel.set_use_markup( True )
self.namePanel.pack_start( self.nameLabel, expand=False, padding=self.inset )
self.nameLabel.set_alignment(0, .5)
self.nameTextfield = gtk.Entry(140)
self.nameTextfield.modify_bg( gtk.STATE_INSENSITIVE, Constants.colorBlack.gColor )
self.nameTextfield.connect('changed', self._nameTextfieldEditedCb )
self.nameTextfield.set_alignment(0)
self.nameTextfield.set_size_request( -1, self.controlBarHt-(self.inset*2) )
self.namePanel.pack_start(self.nameTextfield)
self.photographerPanel = gtk.VBox(spacing=self.inset)
self.infoBoxTopLeft.pack_start(self.photographerPanel, expand=False)
photographerLabel = gtk.Label("<b>" + Constants.istrRecorder + "</b>")
photographerLabel.set_use_markup( True )
self.photographerPanel.pack_start(photographerLabel, expand=False)
photographerLabel.set_alignment(0, .5)
photoNamePanel = gtk.HBox(spacing=self.inset)
self.photographerPanel.pack_start(photoNamePanel)
self.photoXoPanel = xoPanel()
photoNamePanel.pack_start( self.photoXoPanel, expand=False )
self.photoXoPanel.set_size_request( 40, 40 )
self.photographerNameLabel = gtk.Label("")
self.photographerNameLabel.set_alignment(0, .5)
photoNamePanel.pack_start(self.photographerNameLabel)
self.datePanel = gtk.HBox(spacing=self.inset)
self.infoBoxTopLeft.pack_start(self.datePanel, expand=False)
dateLabel = gtk.Label("<b>"+Constants.istrDate+"</b>")
dateLabel.set_use_markup(True)
self.datePanel.pack_start(dateLabel, expand=False)
self.dateDateLabel = gtk.Label("")
self.dateDateLabel.set_alignment(0, .5)
self.datePanel.pack_start(self.dateDateLabel)
self.tagsPanel = gtk.VBox(spacing=self.inset)
tagsLabel = gtk.Label("<b>"+Constants.istrTags+"</b>")
tagsLabel.set_use_markup(True)
tagsLabel.set_alignment(0, .5)
self.tagsPanel.pack_start(tagsLabel, expand=False)
self.tagsBuffer = gtk.TextBuffer()
self.tagsBuffer.connect('changed', self._tagsBufferEditedCb)
self.tagsField = gtk.TextView(self.tagsBuffer)
self.tagsField.set_size_request( 100, 100 )
self.tagsPanel.pack_start(self.tagsField, expand=True)
self.infoBoxTopLeft.pack_start(self.tagsPanel, expand=True)
infoBotBox = gtk.HBox()
infoBotBox.set_size_request( -1, self.pgdh+self.inset )
iinfoBox.pack_start(infoBotBox, expand=False)
thumbnailsEventBox = gtk.EventBox()
thumbnailsEventBox.set_size_request( -1, self.thumbTrayHt )
thumbnailsBox = gtk.HBox( )
thumbnailsEventBox.add( thumbnailsBox )
self.thumbTray = HTray()
self.thumbTray.set_size_request( -1, self.thumbTrayHt )
self.mainBox.pack_end( self.thumbTray, expand=False )
self.thumbTray.show()
self.CENTER_SIZE_ALLOCATE_ID = self.centerBox.connect_after("size-allocate", self._centerSizeAllocateCb)
self.ca.show_all()
def _centerSizeAllocateCb( self, widget, event ):
#initial setup of the panels
self.centerBox.disconnect(self.CENTER_SIZE_ALLOCATE_ID)
self.centerBoxPos = self.centerBox.translate_coordinates( self.ca, 0, 0 )
centerKid = self.centerBox.get_child()
if (centerKid != None):
self.centerBox.remove( centerKid )
self.centered = True
self.setUp()
def _mapEventCb( self, widget, event ):
#when your parent window is ready, turn on the feed of live video
self.liveVideoWindow.disconnect(self.MAP_EVENT_ID)
self.mapped = True
self.setUp()
def setUp( self ):
if (self.mapped and self.centered and not self.setup):
self.setup = True
#set correct window sizes
self.setUpWindowsSizes()
#listen for ctrl+c & game key buttons
self.ca.connect('key-press-event', self._keyPressEventCb)
#overlay widgets can go away after they've been on screen for a while
self.HIDE_WIDGET_TIMEOUT_ID = 0
self.hiddenWidgets = False
self.resetWidgetFadeTimer()
self.showLiveVideoTags()
if self.photoToolbar:
self.photoToolbar.set_sensitive( True )
if self.videoToolbar:
self.videoToolbar.set_sensitive( True )
self.audioToolbar.set_sensitive( True )
#initialize the app with the default thumbs
self.ca.m.setupMode( self.ca.m.MODE, True )
gobject.idle_add( self.finalSetUp )
def finalSetUp( self ):
self.LAUNCHING = False
self.ACTIVE = self.ca.get_property( "visible" )
self.updateVideoComponents()
if (self.ACTIVE):
self.ca.glive.play()
def setUpWindows( self ):
#image windows
self.windowStack = []
#live video windows
self.livePhotoWindow = gtk.Window()
self.livePhotoWindow.modify_bg( gtk.STATE_NORMAL, Constants.colorBlack.gColor )
self.livePhotoWindow.modify_bg( gtk.STATE_INSENSITIVE, Constants.colorBlack.gColor )
self.addToWindowStack( self.livePhotoWindow, self.ca )
self.livePhotoCanvas = PhotoCanvas()
self.livePhotoWindow.add(self.livePhotoCanvas)
self.livePhotoWindow.connect("button_release_event", self._mediaClickedForPlayback)
self.livePhotoWindow.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
self.livePhotoWindow.connect("visibility-notify-event", self._visibleNotifyCb)
#video playback windows
self.playOggWindow = PlayVideoWindow(Constants.colorBlack.gColor)
self.addToWindowStack( self.playOggWindow, self.windowStack[len(self.windowStack)-1] )
#self.playOggWindow.set_gplay(self.ca.gplay)
self.ca.gplay.window = self.playOggWindow
self.playOggWindow.set_events(gtk.gdk.BUTTON_RELEASE_MASK)
self.playOggWindow.connect("button_release_event", self._mediaClickedForPlayback)
self.playOggWindow.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
self.playOggWindow.connect("visibility-notify-event", self._visibleNotifyCb)
#border behind
self.pipBgdWindow = gtk.Window()
self.pipBgdWindow.modify_bg( gtk.STATE_NORMAL, Constants.colorWhite.gColor )
self.pipBgdWindow.modify_bg( gtk.STATE_INSENSITIVE, Constants.colorWhite.gColor )
self.addToWindowStack( self.pipBgdWindow, self.windowStack[len(self.windowStack)-1] )
self.liveVideoWindow = LiveVideoWindow(Constants.colorBlack.gColor)
self.addToWindowStack( self.liveVideoWindow, self.windowStack[len(self.windowStack)-1] )
self.liveVideoWindow.set_glive(self.ca.glive)
self.liveVideoWindow.set_events(gtk.gdk.BUTTON_RELEASE_MASK)
self.liveVideoWindow.connect("button_release_event", self._liveButtonReleaseCb)
self.liveVideoWindow.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
self.liveVideoWindow.connect("visibility-notify-event", self._visibleNotifyCb)
self.slowLiveVideoWindow = SlowLiveVideoWindow(Constants.colorBlack.gColor)
self.addToWindowStack( self.slowLiveVideoWindow, self.windowStack[len(self.windowStack)-1] )
self.slowLiveVideoWindow.set_glivex(self.ca.glivex)
self.slowLiveVideoWindow.set_events(gtk.gdk.BUTTON_RELEASE_MASK)
self.slowLiveVideoWindow.connect("button_release_event", self._liveButtonReleaseCb)
self.slowLiveVideoWindow.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
self.slowLiveVideoWindow.connect("visibility-notify-event", self._visibleNotifyCb)
self.recordWindow = RecordWindow(self)
self.addToWindowStack( self.recordWindow, self.windowStack[len(self.windowStack)-1] )
self.progressWindow = ProgressWindow(self)
self.addToWindowStack( self.progressWindow, self.windowStack[len(self.windowStack)-1] )
self.maxWindow = gtk.Window()
self.maxWindow.modify_bg( gtk.STATE_NORMAL, Constants.colorBlack.gColor )
self.maxWindow.modify_bg( gtk.STATE_INSENSITIVE, Constants.colorBlack.gColor )
maxButton = MaxButton(self)
self.maxWindow.add( maxButton )
self.addToWindowStack( self.maxWindow, self.windowStack[len(self.windowStack)-1] )
self.scrubWindow = ScrubberWindow(self)
self.addToWindowStack( self.scrubWindow, self.windowStack[len(self.windowStack)-1] )
self.infWindow = gtk.Window()
self.infWindow.modify_bg( gtk.STATE_NORMAL, Constants.colorBlack.gColor )
self.infWindow.modify_bg( gtk.STATE_INSENSITIVE, Constants.colorBlack.gColor )
infButton= InfButton(self)
self.infWindow.add(infButton)
self.addToWindowStack( self.infWindow, self.windowStack[len(self.windowStack)-1] )
self.hideAllWindows()
self.MAP_EVENT_ID = self.liveVideoWindow.connect_after("map-event", self._mapEventCb)
for i in range (0, len(self.windowStack)):
# self.windowStack[i].add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
# self.windowStack[i].connect("visibility-notify-event", self._visibleNotifyCb)
self.windowStack[i].show_all()
def _visibleNotifyCb( self, widget, event ):
if (self.LAUNCHING):
return
temp_ACTIVE = True
if (event.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED):
if (not self.FULLSCREEN):
if (widget == self.ca):
temp_ACTIVE = False
else:
if (self.ca.m.MODE == Constants.MODE_PHOTO):
if (not self.LIVEMODE and widget == self.livePhotoWindow):
temp_ACTIVE = False
if ( self.LIVEMODE and widget == self.liveVideoWindow):
temp_ACTIVE = False
if (self.ca.m.MODE == Constants.MODE_VIDEO):
if (not self.LIVEMODE and widget == self.playOggWindow):
temp_ACTIVE = False
if ( self.LIVEMODE and widget == self.liveVideoWindow):
temp_ACTIVE = False
if (temp_ACTIVE != self.ACTIVE):
self.ACTIVE = temp_ACTIVE
if (self.ACTIVE):
self.ca.restartPipes()
else:
self.ca.stopPipes()
def setUpWindowsSizes( self ):
pipDim = self.getPipDim(False)
eyeDim = self.getEyeDim(False)
imgDim = self.getImgDim( False )
pgdDim = self.getPgdDim( False )
maxDim = self.getMaxDim( False )
prgDim = self.getPrgDim( False )
infDim = self.getInfDim( False )
self.livePhotoWindow.resize( imgDim[0], imgDim[1] )
self.pipBgdWindow.resize( pgdDim[0], pgdDim[1] )
self.liveVideoWindow.resize( imgDim[0], imgDim[1] )
self.playOggWindow.resize( imgDim[0], imgDim[1] )
self.recordWindow.resize( eyeDim[0], eyeDim[1] )
self.maxWindow.resize( maxDim[0], maxDim[1] )
self.progressWindow.resize( prgDim[0], prgDim[1] )
self.infWindow.resize( infDim[0], infDim[1] )
def _toolbarChangeCb( self, tbox, num ):
if (num != 0) and (self.ca.m.RECORDING or self.ca.m.UPDATING):
self.toolbox.set_current_toolbar(self.tbars[self.ca.m.MODE])
else:
mode = [mode for mode, i in self.tbars.items() if i == num]
if not mode:
return
if (mode[0] == Constants.MODE_PHOTO) and \
(self.ca.m.MODE != Constants.MODE_PHOTO):
self.ca.m.doPhotoMode()
elif(mode[0] == Constants.MODE_VIDEO) and \
(self.ca.m.MODE != Constants.MODE_VIDEO):
self.ca.m.doVideoMode()
elif(mode[0] == Constants.MODE_AUDIO) and \
(self.ca.m.MODE != Constants.MODE_AUDIO):
self.ca.m.doAudioMode()
def addToWindowStack( self, win, parent ):
self.windowStack.append( win )
win.set_transient_for( parent )
win.set_type_hint( gtk.gdk.WINDOW_TYPE_HINT_DIALOG )
win.set_decorated( False )
win.set_focus_on_map( False )
win.set_property("accept-focus", False)
win.props.destroy_with_parent = True
def resetWidgetFadeTimer( self ):
#only show the clutter when the mouse moves
self.mx = -1
self.my = -1
self.hideWidgetsTimer = time.time()
if (self.hiddenWidgets):
self.showWidgets()
self.hiddenWidgets = False
#remove, then add
self.doMouseListener( False )
if (self.HIDE_WIDGET_TIMEOUT_ID != 0):
gobject.source_remove( self.HIDE_WIDGET_TIMEOUT_ID)
self.HIDE_WIDGET_TIMEOUT_ID = gobject.timeout_add( 500, self._mouseMightaMovedCb )
def doMouseListener( self, listen ):
if (listen):
self.resetWidgetFadeTimer()
else:
if (self.HIDE_WIDGET_TIMEOUT_ID != None):
if (self.HIDE_WIDGET_TIMEOUT_ID != 0):
gobject.source_remove( self.HIDE_WIDGET_TIMEOUT_ID )
def hideWidgets( self ):
self.moveWinOffscreen( self.maxWindow )
self.moveWinOffscreen( self.pipBgdWindow )
self.moveWinOffscreen( self.infWindow )
self.moveWinOffscreen( self.slowLiveVideoWindow )
if (self.FULLSCREEN):
self.moveWinOffscreen( self.recordWindow )
self.moveWinOffscreen( self.progressWindow )
self.moveWinOffscreen( self.scrubWindow )
if (self.ca.m.MODE == Constants.MODE_PHOTO):
if (not self.LIVEMODE):
self.moveWinOffscreen( self.liveVideoWindow )
elif (self.ca.m.MODE == Constants.MODE_VIDEO):
if (not self.LIVEMODE):
self.moveWinOffscreen( self.liveVideoWindow )
elif (self.ca.m.MODE == Constants.MODE_AUDIO):
if (not self.LIVEMODE):
self.moveWinOffscreen( self.liveVideoWindow )
self.LAST_MODE = -1
def _mouseMightaMovedCb( self ):
x, y = self.ca.get_pointer()
passedTime = 0
if (x != self.mx or y != self.my):
self.hideWidgetsTimer = time.time()
if (self.hiddenWidgets):
self.showWidgets()
self.hiddenWidgets = False
else:
passedTime = time.time() - self.hideWidgetsTimer
if (self.ca.m.RECORDING):
self.hideWidgetsTimer = time.time()
passedTime = 0
if (passedTime >= 3):
if (not self.hiddenWidgets):
if (self.mouseInWidget(x,y)):
self.hideWidgetsTimer = time.time()
elif (self.RECD_INFO_ON):
self.hideWidgetsTimer = time.time()
elif (self.UPDATE_TIMER_ID != 0):
self.hideWidgetsTimer = time.time()
else:
self.hideWidgets()
self.hiddenWidgets = True
self.mx = x
self.my = y
return True
def mouseInWidget( self, mx, my ):
if (self.ca.m.MODE != Constants.MODE_AUDIO):
if (self.inWidget( mx, my, self.getLoc("max", self.FULLSCREEN), self.getDim("max", self.FULLSCREEN))):
return True
if (not self.LIVEMODE):
if (self.inWidget( mx, my, self.getLoc("pgd", self.FULLSCREEN), self.getDim("pgd", self.FULLSCREEN))):
return True
if (self.inWidget( mx, my, self.getLoc("inb", self.FULLSCREEN), self.getDim("inb", self.FULLSCREEN))):
return True
if (self.inWidget( mx, my, self.getLoc("prg", self.FULLSCREEN), self.getDim("prg", self.FULLSCREEN))):
return True
if (self.inWidget( mx, my, self.getLoc("inf", self.FULLSCREEN), self.getDim("inf", self.FULLSCREEN))):
return True
if (self.LIVEMODE):
if (self.inWidget( mx, my, self.getLoc("eye", self.FULLSCREEN), self.getDim("eye", self.FULLSCREEN))):
return True
return False
def _mediaClickedForPlayback(self, widget, event):
if (not self.LIVEMODE):
if (self.shownRecd != None):
if (self.ca.m.MODE != Constants.MODE_PHOTO):
self.showThumbSelection( self.shownRecd )
def inWidget( self, mx, my, loc, dim ):
if ( (mx > loc[0]) and (my > loc[1]) ):
if ( (mx < loc[0]+dim[0]) and (my < loc[1]+dim[1]) ):
return True
def _nameTextfieldEditedCb(self, widget):
if (self.shownRecd != None):
if (self.nameTextfield.get_text() != self.shownRecd.title):
self.shownRecd.setTitle( self.nameTextfield.get_text() )
def _tagsBufferEditedCb(self, widget):
if (self.shownRecd != None):
txt = self.tagsBuffer.get_text( self.tagsBuffer.get_start_iter(), self.tagsBuffer.get_end_iter() )
if (txt != self.shownRecd.tags):
self.shownRecd.setTags( txt )
def _keyPressEventCb( self, widget, event):
#todo: trac #4144
self.resetWidgetFadeTimer()
#we listen here for CTRL+C events and game keys, and pass on events to gtk.Entry fields
keyname = gtk.gdk.keyval_name(event.keyval)
if (keyname == 'KP_Page_Up'): #O, up
if (self.LIVEMODE):
if (not self.ca.m.UPDATING):
self.doShutter()
else:
if (self.COUNTINGDOWN):
self.doShutter()
else:
if (self.ca.m.MODE == Constants.MODE_PHOTO):
self.resumeLiveVideo()
else:
self.resumePlayLiveVideo()
elif (keyname == 'KP_Page_Down'): #x, down
if (not self.ca.m.UPDATING and not self.ca.m.RECORDING):
self.ca.m.showLastThumb()
elif (keyname == 'KP_Home'): #square, left
if (not self.ca.m.UPDATING and not self.ca.m.RECORDING and not self.LIVEMODE):
self.ca.m.showPrevThumb( self.shownRecd )
elif (keyname == 'KP_End'): #check, right
if (not self.ca.m.UPDATING and not self.ca.m.RECORDING and not self.LIVEMODE):
self.ca.m.showNextThumb( self.shownRecd )
elif (keyname == 'c' and event.state == gtk.gdk.CONTROL_MASK):
if (self.shownRecd != None):
self.copyToClipboard( self.shownRecd )
elif (keyname == 'Escape'):
if (self.FULLSCREEN):
self.FULLSCREEN = False
if (self.RECD_INFO_ON):
self.infoButtonClicked()
else:
self.updateVideoComponents()
elif (keyname == 'i' and event.state == gtk.gdk.CONTROL_MASK):
if (not self.LIVEMODE):
self.infoButtonClicked()
return False
def copyToClipboard( self, recd ):
if (recd.isClipboardCopyable( )):
tmpImgPath = self.doClipboardCopyStart( recd )
gtk.Clipboard().set_with_data( [('text/uri-list', 0, 0)], self._clipboardGetFuncCb, self._clipboardClearFuncCb, tmpImgPath )
return True
def doClipboardCopyStart( self, recd ):
imgPath_s = recd.getMediaFilepath()
if (imgPath_s == None):
record.Record.log.error("doClipboardCopyStart: imgPath_s==None")
return None
tmpImgPath = recd.getMediaFilepath()
tmpImgPath = utils.getUniqueFilepath(tmpImgPath, 0)
shutil.copyfile( imgPath_s, tmpImgPath )
return tmpImgPath
def doClipboardCopyCopy( self, tmpImgPath, selection_data ):
tmpImgUri = "file://" + tmpImgPath
selection_data.set( "text/uri-list", 8, tmpImgUri )
def doClipboardCopyFinish( self, tmpImgPath ):
if (tmpImgPath != None):
if (os.path.exists(tmpImgPath)):
os.remove( tmpImgPath )
tmpImgPath = None
def _clipboardGetFuncCb( self, clipboard, selection_data, info, data):
self.doClipboardCopyCopy( data, selection_data )
def _clipboardClearFuncCb( self, clipboard, data):
self.doClipboardCopyFinish( data )
def showPhoto( self, recd ):
pixbuf = self.getPhotoPixbuf( recd )
if (pixbuf != None):
#self.shownRecd = recd
img = hippo.cairo_surface_from_gdk_pixbuf(pixbuf)
self.livePhotoCanvas.setImage( img )
self.LIVEMODE = False
self.updateVideoComponents()
self.showRecdMeta(recd)
def getPhotoPixbuf( self, recd ):
pixbuf = None
downloading = self.ca.requestMeshDownload(recd)
self.MESHING = downloading
if (not downloading):
self.progressWindow.updateProgress(0, "")
imgPath = recd.getMediaFilepath()
if (not imgPath == None):
if ( os.path.isfile(imgPath) ):
pixbuf = gtk.gdk.pixbuf_new_from_file(imgPath)
if (pixbuf == None):
#maybe it is not downloaded from the mesh yet...
#but we can show the low res thumb in the interim
pixbuf = recd.getThumbPixbuf()
return pixbuf
def showLiveVideoTags( self ):
self.shownRecd = None
self.livePhotoCanvas.setImage( None )
self.nameTextfield.set_text("")
self.tagsBuffer.set_text("")
self.scrubWindow.removeCallbacks()
self.scrubWindow.reset()
self.MESHING = False
self.progressWindow.updateProgress( 0, "" )
self.resetWidgetFadeTimer( )
def updateButtonSensitivities( self ):
switchStuff = ((not self.ca.m.UPDATING) and (not self.ca.m.RECORDING))
if self.photoToolbar:
self.photoToolbar.set_sensitive( switchStuff )
if self.videoToolbar:
self.videoToolbar.set_sensitive( switchStuff )
self.audioToolbar.set_sensitive( switchStuff )
if (not self.COUNTINGDOWN):
if (self.ca.m.UPDATING):
self.ca.ui.setWaitCursor( self.ca.window )
for i in range (0, len(self.windowStack)):
self.ca.ui.setWaitCursor( self.windowStack[i].window )
else:
self.ca.ui.setDefaultCursor( self.ca.window )
for i in range (0, len(self.windowStack)):
self.ca.ui.setDefaultCursor( self.windowStack[i].window )
#display disc is full messages
self.ca.m.updateXoFullStatus()
self.recordWindow.displayDiscFullText(self.ca.m.FULL)
if (self.ca.m.FULL):
self.recordWindow.shutterButton.set_sensitive( False, True)
fullMessage = Constants.istrYourDiskIsFull % {"1":Constants.istrJournal}
self.progressWindow.updateProgress( 1, fullMessage, "gray" )
else:
self.recordWindow.shutterButton.set_sensitive( not self.ca.m.UPDATING, False )
if (self.ca.m.RECORDING):
self.recordWindow.shutterButton.doRecordButton()
else:
self.recordWindow.shutterButton.doNormalButton()
kids = self.thumbTray.get_children()
for i in range (0, len(kids)):
if (self.ca.m.UPDATING or self.ca.m.RECORDING):
if (kids[i].getButtClickedId() != 0):
kids[i].disconnect( kids[i].getButtClickedId() )
kids[i].setButtClickedId(0)
else:
if (kids[i].getButtClickedId() == 0):
BUTT_CLICKED_ID = kids[i].connect( "clicked", self._thumbClicked, kids[i].recd )
kids[i].setButtClickedId(BUTT_CLICKED_ID)
def hideAllWindows( self ):
for i in range (0, len(self.windowStack)):
self.moveWinOffscreen( self.windowStack[i] )
def _liveButtonReleaseCb(self, widget, event):
self.ca.gplay.stop()
self.ca.glivex.stop()
self.ca.glive.play()
self.resumeLiveVideo()
def resumeLiveVideo( self ):
self.livePhotoCanvas.setImage( None )
bottomKid = self.bottomCenter.get_child()
if (bottomKid != None):
self.bottomCenter.remove( bottomKid )
self.RECD_INFO_ON = False
if (not self.LIVEMODE):
self.ca.m.setUpdating(True)
self.ca.gplay.stop()
self.showLiveVideoTags()
self.LIVEMODE = True
self.updateVideoComponents()
self.ca.m.setUpdating(False)
def _playLiveButtonReleaseCb(self, widget, event):
self.resumePlayLiveVideo()
def resumePlayLiveVideo( self ):
self.ca.gplay.stop()
self.RECD_INFO_ON = False
#if you are big on the screen, don't go changing anything, ok?
if (self.LIVEMODE):
return
self.showLiveVideoTags()
self.LIVEMODE = True
self.startLiveVideo( False )
self.updateVideoComponents()
def recordVideo( self ):
self.ca.glive.startRecordingVideo(self.videoToolbar.getQuality())
self.beginRecordingTimer( )
def recordAudio( self ):
self.ca.glive.startRecordingAudio( )
self.beginRecordingTimer( )
def beginRecordingTimer( self ):
self.recTime = time.time()
self.UPDATE_DURATION_ID = gobject.timeout_add( 500, self._updateDurationCb )
def _updateDurationCb( self ):
passedTime = time.time() - self.recTime
duration = 10.0
if (self.ca.m.MODE == Constants.MODE_VIDEO):
duration = self.videoToolbar.getDuration()+0.0
elif (self.ca.m.MODE == Constants.MODE_AUDIO):
duration = self.audioToolbar.getDuration()+0.0
if (passedTime >= duration ):
self.completeCountdown()
self.progressWindow.updateProgress( 1, Constants.istrFinishedRecording )
if (self.ca.m.RECORDING):
gobject.idle_add( self.doShutter )
return False
else:
secsRemaining = duration - passedTime
if (secsRemaining >= 60):
mins = int( secsRemaining/60 )
secs = int( secsRemaining%60 )
timeRemainStr = istrMinutes(mins) + ', ' + istrSeconds(secs)
else:
timeRemainStr = istrSeconds(secsRemaining)
self.progressWindow.updateProgress( passedTime/duration,
Constants.istrRemaining + " " + timeRemainStr )
return True
def completeCountdown( self ):
if (self.UPDATE_DURATION_ID != 0):
gobject.source_remove( self.UPDATE_DURATION_ID )
self.UPDATE_DURATION_ID = 0
def updateModeChange(self):
#this is called when a menubar button is clicked
self.LIVEMODE = True
self.FULLSCREEN = False
self.RECD_INFO_ON = False
self.MESHING = False
self.progressWindow.updateProgress(0, "")
#set up the x & xv x-ition (if need be)
self.ca.gplay.stop()
self.startLiveVideo( True )
bottomKid = self.bottomCenter.get_child()
if (bottomKid != None):