~kokoto-java/kazam/depencie-and-stuff

« back to all changes in this revision

Viewing changes to kazam/app.py

  • Committer: David Klasinc
  • Date: 2012-11-11 19:36:05 UTC
  • mfrom: (193.2.82 unstable)
  • Revision ID: bigwhale@lubica.net-20121111193605-vh3fxglxwfhyh8ne
Merged from unstable branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import shutil
27
27
import gettext
28
28
import logging
29
 
import time
30
29
 
31
30
from subprocess import Popen
32
31
from gi.repository import Gtk, Gdk, GObject
36
35
from kazam.backend.prefs import *
37
36
from kazam.backend.constants import *
38
37
from kazam.backend.grabber import Grabber
39
 
from kazam.backend.config import KazamConfig
40
38
from kazam.frontend.main_menu import MainMenu
41
39
from kazam.frontend.window_area import AreaWindow
42
 
from kazam.backend.gstreamer_gi import Screencast
 
40
from kazam.backend.gstreamer import Screencast
43
41
from kazam.frontend.preferences import Preferences
44
42
from kazam.frontend.about_dialog import AboutDialog
45
43
from kazam.frontend.indicator import KazamIndicator
99
97
        self.icons.append_search_path(os.path.join(prefs.datadir,"icons", "48x48", "apps"))
100
98
        self.icons.append_search_path(os.path.join(prefs.datadir,"icons", "16x16", "apps"))
101
99
 
 
100
        try:
 
101
            from gi.repository import Unity, Dbusmenu
 
102
            launcher = Unity.LauncherEntry.get_for_desktop_id("kazam.desktop")
 
103
            ql = Dbusmenu.Menuitem.new()
 
104
            ql_item1 = Dbusmenu.Menuitem.new()
 
105
            ql_item1.property_set(Dbusmenu.MENUITEM_PROP_LABEL, _("Record screencast"))
 
106
            ql_item1.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True)
 
107
            ql_item1.connect("item-activated", self.cb_ql_screencast)
 
108
            ql.child_append(ql_item1)
 
109
            ql_item2 = Dbusmenu.Menuitem.new()
 
110
            ql_item2.property_set(Dbusmenu.MENUITEM_PROP_LABEL, _("Take screenshot"))
 
111
            ql_item2.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True)
 
112
            ql_item2.connect("item-activated", self.cb_ql_screenshot)
 
113
            ql.child_append(ql_item2)
 
114
            ql_item3 = Dbusmenu.Menuitem.new()
 
115
            ql_item3.property_set(Dbusmenu.MENUITEM_PROP_LABEL, _("Preferences"))
 
116
            ql_item3.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True)
 
117
            ql_item3.connect("item-activated", self.cb_ql_preferences)
 
118
            ql.child_append(ql_item3)
 
119
            launcher.set_property("quicklist", ql)
 
120
        except ImportError:
 
121
            logger.warning("Unity and Dbusmenu not found. Skipping launcher integration.")
 
122
 
102
123
        # Initialize all the variables
103
124
 
104
125
        self.main_x = 0
107
128
        self.tempfile = ""
108
129
        self.recorder = None
109
130
        self.area_window = None
110
 
        self.old_path = None
 
131
        self.old_vid_path = None
 
132
        self.old_pic_path = None
111
133
        self.in_countdown = False
112
134
        self.recording_paused = False
113
135
        self.recording = False
121
143
 
122
144
        self.mainmenu = MainMenu()
123
145
 
124
 
        #
125
 
        # Setup config
126
 
        #
127
 
        self.config = KazamConfig()
128
 
 
129
 
        self.read_config()
130
 
 
131
146
        logger.debug("Connecting indicator signals.")
132
147
        logger.debug("Starting in silent mode: {0}".format(prefs.silent))
133
148
        self.indicator = KazamIndicator(prefs.silent)
294
309
                self.last_mode.set_active(True)
295
310
            self.indicator.menuitem_start.set_label(_("Take screenshot"))
296
311
 
297
 
 
298
312
    #
299
313
    # Record mode toggles
300
314
    #
342
356
                self.select_window.window.destroy()
343
357
                self.select_window = None
344
358
 
 
359
 
 
360
    #
 
361
    # Unity quick list callbacks
 
362
    #
 
363
 
 
364
    def cb_ql_screencast(self, menu, data):
 
365
        logger.debug("Screencast quicklist activated.")
 
366
        self.btn_cast.set_active(True)
 
367
        self.run_counter()
 
368
 
 
369
    def cb_ql_screenshot(self, menu, data):
 
370
        logger.debug("Screenshot quicklist activated.")
 
371
        self.btn_shot.set_active(True)
 
372
        self.run_counter()
 
373
 
 
374
    def cb_ql_preferences(self, menu, data):
 
375
        logger.debug("Preferences quicklist activated.")
 
376
        self.cb_preferences_request(None)
 
377
 
345
378
    def cb_record_area_clicked(self, widget):
346
379
        if self.area_window:
347
380
            logger.debug("Area mode clicked.")
377
410
        prefs.xid = self.select_window.xid
378
411
        prefs.xid_geometry = self.select_window.geometry
379
412
        logger.debug("Window selected: {0} - {1}".format(self.select_window.win_name, prefs.xid))
 
413
        logger.debug("Window geometry: {0}".format(self.select_window.geometry))
380
414
        self.window.set_sensitive(True)
381
415
 
382
416
    def cb_window_canceled(self, widget):
387
421
    def cb_screen_size_changed(self, screen):
388
422
        logger.debug("Screen size changed.")
389
423
        HW.get_screens()
 
424
        #
 
425
        # I combined screen was set to none, turn off the button for all screens
 
426
        #
 
427
        if HW.combined_screen:
 
428
            self.btn_allscreens.set_sensitive(True)
 
429
        else:
 
430
            self.btn_allscreens.set_sensitive(False)
 
431
 
390
432
 
391
433
    def cb_configure_event(self, widget, event):
392
434
        if event.type == Gdk.EventType.CONFIGURE:
393
 
            self.main_x = event.x
394
 
            self.main_y = event.y
 
435
            prefs.main_x = event.x
 
436
            prefs.main_y = event.y
395
437
 
396
438
    def cb_quit_request(self, indicator):
397
439
        logger.debug("Quit requested.")
398
 
        (self.main_x, self.main_y) = self.window.get_position()
 
440
        (prefs.main_x, prefs.main_y) = self.window.get_position()
399
441
        try:
400
442
            os.remove(self.recorder.tempfile)
401
443
            os.remove("{0}.mux".format(self.recorder.tempfile))
404
446
        except AttributeError:
405
447
            pass
406
448
 
407
 
        self.save_config()
 
449
        prefs.save_config()
408
450
 
409
451
        if prefs.sound:
410
452
            prefs.pa_q.end()
421
463
            logger.debug("Show requested, raising window.")
422
464
            self.window.show_all()
423
465
            self.window.present()
424
 
            self.window.move(self.main_x, self.main_y)
 
466
            self.window.move(prefs.main_x, prefs.main_y)
425
467
        else:
426
468
            self.window.hide()
427
469
 
428
470
    def cb_close_clicked(self, indicator):
429
 
        (self.main_x, self.main_y) = self.window.get_position()
 
471
        (prefs.main_x, prefs.main_y) = self.window.get_position()
430
472
        self.window.hide()
431
473
 
432
474
    def cb_about_request(self, activated):
493
535
            self.done_recording = DoneRecording(self.icons,
494
536
                                            self.tempfile,
495
537
                                            prefs.codec,
496
 
                                            self.old_path)
 
538
                                            self.old_vid_path)
497
539
            logger.debug("Done Recording initialized.")
498
540
            self.done_recording.connect("save-done", self.cb_save_done)
499
541
            self.done_recording.connect("save-cancel", self.cb_save_cancel)
516
558
                fname = get_next_filename(prefs.picture_dest, prefs.autosave_picture_file, ".png")
517
559
                self.grabber.autosave(fname)
518
560
            else:
519
 
                self.grabber.save_capture(self.old_path)
 
561
                self.grabber.save_capture(self.old_pic_path)
520
562
 
521
563
 
522
564
    def cb_pause_request(self, widget):
531
573
 
532
574
    def cb_save_done(self, widget, result):
533
575
        logger.debug("Save Done, result: {0}".format(result))
534
 
        self.old_path = result
 
576
        if self.main_mode == MODE_SCREENCAST:
 
577
            self.old_vid_path = result
 
578
        else:
 
579
            self.old_pic_path = result
 
580
 
535
581
        self.window.set_sensitive(True)
536
582
        self.window.show_all()
537
583
        self.window.present()
538
 
        self.window.move(self.main_x, self.main_y)
 
584
        self.window.move(prefs.main_x, prefs.main_y)
539
585
 
540
586
    def cb_save_cancel(self, widget):
541
587
        try:
550
596
        self.window.set_sensitive(True)
551
597
        self.window.show_all()
552
598
        self.window.present()
553
 
        self.window.move(self.main_x, self.main_y)
 
599
        self.window.move(prefs.main_x, prefs.main_y)
554
600
 
555
601
    def cb_help_about(self, widget):
556
602
        AboutDialog(self.icons)
584
630
        prefs.capture_cursor_pic = widget.get_active()
585
631
        logger.debug("Capture cursor_pic: {0}.".format(prefs.capture_cursor_pic))
586
632
 
 
633
    def cb_check_borders_pic(self, widget):
 
634
        prefs.capture_borders_pic = widget.get_active()
 
635
        logger.debug("Capture borders_pic: {0}.".format(prefs.capture_borders_pic))
 
636
 
587
637
    def cb_check_speakers(self, widget):
588
638
        prefs.capture_speakers = widget.get_active()
589
639
        logger.debug("Capture speakers: {0}.".format(prefs.capture_speakers))
606
656
        #
607
657
        (main_x, main_y) = self.window.get_position()
608
658
        if main_x and main_y:
609
 
            self.main_x = main_x
610
 
            self.main_y = main_y
 
659
            prefs.main_x = main_x
 
660
            prefs.main_y = main_y
611
661
 
612
662
        self.indicator.recording = True
613
663
        self.indicator.menuitem_start.set_sensitive(False)
679
729
        except Exception as e:
680
730
            logger.exception("EXCEPTION: Setlocale failed, no language support.")
681
731
 
682
 
    def read_config (self):
683
 
        prefs.audio_source = self.config.getint("main", "audio_source")
684
 
        prefs.audio2_source = self.config.getint("main", "audio2_source")
685
 
        logger.debug("Restoring Audio source state: {0} {1}".format(
686
 
            prefs.audio_source,
687
 
            prefs.audio2_source))
688
 
 
689
 
        self.main_x = self.config.getint("main", "last_x")
690
 
        self.main_y = self.config.getint("main", "last_y")
691
 
 
692
 
        prefs.codec = self.config.getint("main", "codec")
693
 
 
694
 
        prefs.countdown_timer = self.config.getfloat("main", "counter")
695
 
        prefs.framerate = self.config.getfloat("main", "framerate")
696
 
 
697
 
        prefs.capture_cursor = self.config.getboolean("main", "capture_cursor")
698
 
        prefs.capture_microphone = self.config.getboolean("main", "capture_microphone")
699
 
        prefs.capture_speakers = self.config.getboolean("main", "capture_speakers")
700
 
 
701
 
        prefs.capture_cursor_pic = self.config.getboolean("main", "capture_cursor_pic")
702
 
 
703
 
        prefs.countdown_splash = self.config.getboolean("main", "countdown_splash")
704
 
 
705
 
        prefs.autosave_video = self.config.getboolean("main", "autosave_video")
706
 
        prefs.autosave_video_file = self.config.get("main", "autosave_video_file")
707
 
 
708
 
        prefs.autosave_picture = self.config.getboolean("main", "autosave_picture")
709
 
        prefs.autosave_picture_file = self.config.get("main", "autosave_picture_file")
710
 
 
711
 
        prefs.shutter_sound = self.config.getboolean("main", "shutter_sound")
712
 
        prefs.shutter_type = self.config.getint("main", "shutter_type")
713
732
 
714
733
    def restore_UI (self):
715
 
 
716
 
        self.window.move(self.main_x, self.main_y)
 
734
        self.window.move(prefs.main_x, prefs.main_y)
717
735
        self.chk_cursor.set_active(prefs.capture_cursor)
718
736
        self.chk_speakers.set_active(prefs.capture_speakers)
719
737
        self.chk_microphone.set_active(prefs.capture_microphone)
720
 
 
721
738
        self.chk_cursor_pic.set_active(prefs.capture_cursor_pic)
722
 
 
 
739
        self.chk_borders_pic.set_active(prefs.capture_borders_pic)
723
740
        self.spinbutton_delay.set_value(prefs.countdown_timer)
724
741
 
725
 
    def save_config(self):
726
 
        logger.debug("Saving state.")
727
 
 
728
 
        self.config.set("main", "capture_cursor", prefs.capture_cursor)
729
 
        self.config.set("main", "capture_speakers", prefs.capture_speakers)
730
 
        self.config.set("main", "capture_microphone", prefs.capture_microphone)
731
 
 
732
 
        self.config.set("main", "capture_cursor_pic", prefs.capture_cursor_pic)
733
 
 
734
 
        self.config.set("main", "last_x", self.main_x)
735
 
        self.config.set("main", "last_y", self.main_y)
736
 
 
737
 
        if prefs.sound:
738
 
            logger.debug("Saving Audio source state: {0} {1}".format(
739
 
                                                                     prefs.audio_source,
740
 
                                                                     prefs.audio2_source))
741
 
 
742
 
            self.config.set("main", "audio_source", prefs.audio_source)
743
 
            self.config.set("main", "audio2_source", prefs.audio2_source)
744
 
 
745
 
        self.config.set("main", "countdown_splash", prefs.countdown_splash)
746
 
        self.config.set("main", "counter", prefs.countdown_timer)
747
 
        self.config.set("main", "codec", prefs.codec)
748
 
        self.config.set("main", "framerate", prefs.framerate)
749
 
        self.config.set("main", "autosave_video", prefs.autosave_video)
750
 
        self.config.set("main", "autosave_video_file", prefs.autosave_video_file)
751
 
        self.config.set("main", "autosave_picture", prefs.autosave_picture)
752
 
        self.config.set("main", "autosave_picture_file", prefs.autosave_picture_file)
753
 
        self.config.set("main", "shutter_sound", prefs.shutter_sound)
754
 
        self.config.set("main", "shutter_type", prefs.shutter_type)
755
 
 
756
 
        self.config.write()
 
742
        #
 
743
        # Turn off the combined screen icon if we don't have more than one screen.
 
744
        #
 
745
        if HW.combined_screen:
 
746
            self.btn_allscreens.set_sensitive(True)
 
747
        else:
 
748
            self.btn_allscreens.set_sensitive(False)