summaryrefslogtreecommitdiff
path: root/gtk-recordmydesktop/rmdTrayIcon.py
blob: 4358b7c9fe281d9f95a24479235050f4ec8d84af (plain)
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
#/*********************************************************************************
#*                         gtk-recordMyDesktop                                    *
#**********************************************************************************
#*                                                                                *
#*             Copyright (C) 2006  John Varouhakis                                *
#*                                                                                *
#*                                                                                *
#*    This program is free software; you can redistribute it and/or modify        *
#*    it under the terms of the GNU General Public License as published by        *
#*    the Free Software Foundation; either version 2 of the License, or           *
#*    (at your option) any later version.                                         *
#*                                                                                *
#*    This program is distributed in the hope that it will be useful,             *
#*    but WITHOUT ANY WARRANTY; without even the implied warranty of              *
#*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
#*    GNU General Public License for more details.                                *
#*                                                                                *
#*    You should have received a copy of the GNU General Public License           *
#*    along with this program; if not, write to the Free Software                 *
#*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   *
#*                                                                                *
#*                                                                                *
#*                                                                                *
#*    For further information contact me at johnvarouhakis@gmail.com              *
#**********************************************************************************/


import pygtk
pygtk.require('2.0')
import gtk

import egg.trayicon
import rmdSelect as isel
import rmdTrayPopup as iTP
import os

#values struct:

#0   fps
#1   mouse
#2   sound on/off
#3   full
#4   path
#5   area
#6   delay
#7   channels
#8   frequency
#9   device
#10  v_quality
#11  s_quality
#12  display
#13  shared memory
#14  drop-frames
#15  shared threshold
#16  quick subsampling


class trayIcon(object):
    values=[15,0,0,1,os.path.join(os.getenv('HOME'),'out.ogg'),[-1,-1,-1,-1],0,
            1,22050,'hw:0,0',63,10,"$DISPLAY",0,1,75,1]
    event_box = gtk.EventBox() 
    state=0#0 stopped,1 recording,2 paused
    rmdPid=None
    optionsOpen=[0]
    
    def __buttonPress__(self,widget,event=None):
        if event.button==1 and self.optionsOpen[0]==0:
            if self.state == 0:
                self.trayIcon.set_from_stock(gtk.STOCK_MEDIA_STOP,gtk.ICON_SIZE_SMALL_TOOLBAR)
                self.state=1
                self.__execRMD__()
            elif self.state== 1:
                self.trayIcon.set_from_stock(gtk.STOCK_MEDIA_RECORD,gtk.ICON_SIZE_SMALL_TOOLBAR)
                self.state=0
                self.__stopRMD__()
            elif self.state == 2 :
                self.trayIcon.set_from_stock(gtk.STOCK_MEDIA_STOP,gtk.ICON_SIZE_SMALL_TOOLBAR)
                self.state=1
                self.__pauseRMD__()
              

        elif event.button == 3:
            if self.state == 0:
                self.tray_popup.show()
            elif self.state == 1:
                self.trayIcon.set_from_stock(gtk.STOCK_MEDIA_PAUSE,gtk.ICON_SIZE_SMALL_TOOLBAR)
                self.state=2
                self.__pauseRMD__()
            elif self.state ==2:
                self.trayIcon.set_from_stock(gtk.STOCK_MEDIA_STOP,gtk.ICON_SIZE_SMALL_TOOLBAR)
                self.state=1
                self.__pauseRMD__()
        
    def __execRMD__(self):

        execargs=["recordmydesktop","-o","%s"%self.values[4],
                  "--no-quick-subsampling",
                  "-fps","%d"%self.values[0]]
        if self.values[2]==1 :
            execargs.append("--nosound")
        if self.values[1] == 0:
            execargs.append("-dummy-cursor")
            execargs.append("white")

        elif self.values[1] == 1:
            execargs.append("-dummy-cursor")
            execargs.append("black")
        else:
            execargs.append("--no-dummy-cursor")
        
        if self.values[3] == 0:
            execargs.append("--full-shots")
            execargs.append("--with-shared")

        self.rmdPid=os.fork()

        if self.rmdPid==0:
            res=os.execvp("recordmydesktop",execargs)
            print res

        
    def __pauseRMD__(self):
        os.system("kill -s USR1 %d"%self.rmdPid)
        
    def __stopRMD__(self):
        os.system("kill -s TERM %d"%self.rmdPid)
        self.rmdPid=None


    def __init__(self):
        
        self.trayIcon=gtk.Image()
        self.trayIcon.set_from_stock(gtk.STOCK_MEDIA_RECORD, gtk.ICON_SIZE_SMALL_TOOLBAR)
        self.event_box.add(self.trayIcon)
        self.tray_container = egg.trayicon.TrayIcon("recordMyDesktop")
        self.tray_container.add(self.event_box)
        self.tray_popup=iTP.TrayPopupMenu(self.values,self.optionsOpen)
        self.event_box.connect("button-press-event", self.__buttonPress__)
        self.tray_container.show_all()
        gtk.main()
© All Rights Reserved