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

« back to all changes in this revision

Viewing changes to kazam/instant.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:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
#       instant.py
 
5
#
 
6
#       Copyright 2012 David Klasinc <bigwhale@lubica.net>
 
7
#
 
8
#       This program is free software; you can redistribute it and/or modify
 
9
#       it under the terms of the GNU General Public License as published by
 
10
#       the Free Software Foundation; either version 3 of the License, or
 
11
#       (at your option) any later version.
 
12
#
 
13
#       This program is distributed in the hope that it will be useful,
 
14
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#       GNU General Public License for more details.
 
17
#
 
18
#       You should have received a copy of the GNU General Public License
 
19
#       along with this program; if not, write to the Free Software
 
20
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
21
#       MA 02110-1301, USA.
 
22
 
 
23
import sys
 
24
import logging
 
25
from gettext import gettext as _
 
26
from gi.repository import Gtk, GObject
 
27
 
 
28
from kazam.utils import *
 
29
from kazam.backend.prefs import *
 
30
from kazam.backend.constants import *
 
31
from kazam.backend.grabber import Grabber
 
32
 
 
33
logger = logging.getLogger("Instant")
 
34
 
 
35
class InstantApp(GObject.GObject):
 
36
 
 
37
    def __init__(self, datadir, dist, debug, mode, preferences=False):
 
38
        GObject.GObject.__init__(self)
 
39
        logger.debug("Setting variables.{0}".format(datadir))
 
40
 
 
41
        self.mode = mode
 
42
        self.take = 0
 
43
 
 
44
        prefs.datadir = datadir
 
45
        prefs.debug = debug
 
46
        prefs.dist = dist
 
47
        prefs.get_sound_files()
 
48
 
 
49
        if preferences:
 
50
            logger.debug("Preferences requested.")
 
51
            from kazam.frontend.preferences import Preferences
 
52
            from kazam.pulseaudio.pulseaudio import pulseaudio_q
 
53
            prefs.pa_q = pulseaudio_q()
 
54
            prefs.pa_q.start()
 
55
            prefs.get_audio_sources()
 
56
 
 
57
            self.preferences_window = Preferences()
 
58
            self.preferences_window.connect("prefs-quit", self.cb_prefs_quit)
 
59
            self.preferences_window.open()
 
60
 
 
61
        else:
 
62
            self.old_path = None
 
63
 
 
64
            if HW.combined_screen:
 
65
                self.video_source = HW.combined_screen
 
66
            else:
 
67
                screen = HW.get_current_screen()
 
68
                self.video_source = HW.screens[screen]
 
69
 
 
70
            self.grabber = Grabber()
 
71
            self.grabber.connect("flush-done", self.cb_flush_done)
 
72
            self.grabber.connect("save-done", self.cb_save_done)
 
73
 
 
74
            if self.mode == MODE_AREA:
 
75
                logger.debug("Area ON.")
 
76
                from kazam.frontend.window_area import AreaWindow
 
77
                self.area_window = AreaWindow()
 
78
                self.area_window.connect("area-selected", self.cb_area_selected)
 
79
                self.area_window.connect("area-canceled", self.cb_area_canceled)
 
80
                self.area_window.window.show_all()
 
81
            elif self.mode == MODE_ALL:
 
82
                self.grabber.setup_sources(self.video_source, None, None)
 
83
                logger.debug("Grabbing screen")
 
84
                self.grabber.grab()
 
85
            elif self.mode == MODE_ACTIVE:
 
86
                self.grabber.setup_sources(self.video_source, None, None, active=True)
 
87
                logger.debug("Grabbing screen")
 
88
                self.grabber.grab()
 
89
            elif self.mode == MODE_GOD:
 
90
                logger.debug("Grabbing in god mode.")
 
91
                self.grabber.setup_sources(self.video_source, None, None, god=True)
 
92
                self.grabber.grab()
 
93
                self.grabber.setup_sources(self.video_source, None, None, active=True, god=True)
 
94
                self.grabber.grab()
 
95
            else:
 
96
                sys.exit(0)
 
97
 
 
98
    def cb_area_selected(self, widget):
 
99
        logger.debug("Area selected: SX: {0}, SY: {1}, EX: {2}, EY: {3}".format(
 
100
            self.area_window.startx,
 
101
            self.area_window.starty,
 
102
            self.area_window.endx,
 
103
            self.area_window.endy))
 
104
        prefs.area = (self.area_window.startx,
 
105
                      self.area_window.starty,
 
106
                      self.area_window.endx,
 
107
                      self.area_window.endy,
 
108
                      self.area_window.width,
 
109
                      self.area_window.height)
 
110
        self.grabber.setup_sources(self.video_source, prefs.area, None)
 
111
        logger.debug("Grabbing screen")
 
112
        self.grabber.grab()
 
113
 
 
114
    def cb_area_canceled(self, widget):
 
115
        Gtk.main_quit()
 
116
        sys.exit(0)
 
117
 
 
118
    def cb_flush_done(self, widget):
 
119
        if prefs.autosave_picture or self.mode == MODE_GOD:
 
120
            fname = get_next_filename(prefs.picture_dest, prefs.autosave_picture_file, ".png")
 
121
            self.grabber.autosave(fname)
 
122
        else:
 
123
            self.grabber.save_capture(None)
 
124
 
 
125
    def cb_save_done(self, widget, result):
 
126
        logger.debug("Save Done, result: {0}".format(result))
 
127
        self.old_path = result
 
128
 
 
129
        if self.take == 1 or self.mode != MODE_GOD:
 
130
            Gtk.main_quit()
 
131
            sys.exit(0)
 
132
 
 
133
        self.take =+ 1
 
134
 
 
135
 
 
136
    def cb_prefs_quit(self, widget):
 
137
        logger.debug("Saving settings.")
 
138
        prefs.pa_q.end()
 
139
        prefs.save_config()
 
140
        Gtk.main_quit()
 
141
        sys.exit(0)
 
142