summaryrefslogtreecommitdiff
path: root/qt-recordmydesktop/src/rmdMonitor.py
blob: 4df7eab0d132ded99b4d05dfc5bc585167b27769 (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
#/******************************************************************************
#*                       qt-recordMyDesktop                                    *
#*******************************************************************************
#*                                                                             *
#*           Copyright (C) 2007  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             *
#******************************************************************************/


from PyQt4 import QtGui,QtCore
import locale, gettext
import rmdConfig
def _(s):
    return QtCore.QString.fromUtf8(gettext.gettext(s))

gettext.textdomain('qt-recordMyDesktop')
gettext.bindtextdomain('qt-recordMyDesktop',rmdConfig.locale_install_dir)
import popen2
import os,fcntl,signal

class rmdMonitor(object):
    labeString=_("Please wait while your recording is being encoded\nWARNING!!!\nIf you press Cancel or close this window,\nthis proccess cannot be resumed!")

    counter_fraction=0.0

    def destroy_and_kill(self,Event=None):
        self.timed_id.stop()
        self.stop_encoding()
    def destroy(self,Event=None):
        self.window.close()
        self.parent.show()
    def update_counter(self):
        strstdout=""
        try:
            strstdout=self.stdout.read()
            if strstdout =='':
                self.destroy()
        except:
            return True
        try:
            string=strstdout.replace("[","").replace("%] ","").replace("\n","").split("\r")
            self.counter_fraction=max(self.counter_fraction,int(string.pop()))
            if self.counter_fraction>100:
                self.counter_fraction=100
            self.progressbar.setValue(self.counter_fraction)
            self.progressbar.update()
        except:
            pass

        return True
    def stop_encoding(self,Event=None):
        try:
            os.kill(self.rmdPid,signal.SIGINT)
        except:
            pass
    def __init__(self,out_stream,childPid,parent):
        self.parent=parent
        flags = fcntl.fcntl(out_stream, fcntl.F_GETFL)
        fcntl.fcntl(out_stream, fcntl.F_SETFL, flags | os.O_NONBLOCK)
        self.rmdPid=childPid


        self.window = QtGui.QMainWindow()
        self.window.closeEvent=self.destroy_and_kill

        self.window.setWindowTitle("recordMyDesktop-encoder")

        self.frame=QtGui.QFrame()
        self.label=QtGui.QLabel(self.labeString)

        self.label.setAlignment(QtCore.Qt.AlignHCenter)

        self.progressbar=QtGui.QProgressBar()
        self.counter_fraction=0
        self.progressbar.setValue(self.counter_fraction)
        self.stopbutton=QtGui.QPushButton("Cancel",self.window)
        self.stopbutton.connect(self.stopbutton,QtCore.SIGNAL("clicked()"),
                                self.stop_encoding)
        self.box=QtGui.QVBoxLayout()
        self.box.addWidget(self.label,0)
        self.box.addWidget(self.progressbar,0)
        self.box.addWidget(self.stopbutton,0)


        self.stopbutton.show()
        self.frame.setLayout(self.box)
        self.window.setCentralWidget(self.frame)
        self.label.show()
        self.progressbar.show()
        self.window.show()
        self.stdout=out_stream
        self.timed_id=QtCore.QTimer(None)
        self.timed_id.connect(self.timed_id,QtCore.SIGNAL("timeout()"),
                                self.update_counter)
        self.timed_id.start(100)
© All Rights Reserved