~kerry.hatcher/oggconvert/trunk

« back to all changes in this revision

Viewing changes to OggConvert/ocv_util.py

  • Committer: Tristan Brindle
  • Date: 2007-11-19 00:03:16 UTC
  • Revision ID: tristan@jetengine-20071119000316-9bte141jw0ucdft2
Lots of little changes to bring OggConvert mostly inline with 
OggConvert++ (except for the new media checker)

Changes:

* ocv_gtk.py split into ocv_main.py and ocv_in_progress.py
* ocv_gst.py split into ocv_transcoder.py and ocv_media_checker.py
* Lots of tidying up of messy functions in ocv_main
* The media checker is now callback-based. It still blocks the UI, but 
at least it doesn't *look* like it blocks the UI any more ;-). It's 
still using the discoverer at the moment, but that will change
* Brought A. Bram Neijt's OggConvert icon into the source tree and use 
it as the main icon for the app.
* The URL in the About dialogue is now clickable, opening a new browser 
tab. I know how important this is.
* Minor change to the way the time remaining is displayed.
* Audio options are greyed-out when a video-only file is selected, and 
vice-versa.
* Use the extension ".ogv" for Ogg video files (both Theora and Dirac), 
in accordance with the new Xiph.org guidelines. Fixes bug #160054.

Still to do:

* Port the OggConvert++ media checker to Python
* Get the transcoder to send out "paused" and "playing" signals which 
the GUI can listen for.
* Investigate whether we can support Gnome-VFS for input/output without 
depending on it (which I don't want to do)
* Bring in all the translations for Launchpad.
* Release 0.3.0
* Party like it's 1999.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
#
3
1
#
4
2
# OggConvert -- Converts media files to Free formats
5
3
# (c) 2007 Tristan Brindle <tcbrindle at gmail dot com>
24
22
import os.path
25
23
from gettext import gettext as _
26
24
import ocv_info
 
25
import webbrowser
 
26
 
 
27
 
 
28
 
27
29
 
28
30
def timeremaining(elapsed, percent):
29
31
    """Returns a string with the remaining time for an operation.        
31
33
       percent: percentage of the operation completed so far"""
32
34
       
33
35
    if percent == 0:
34
 
        return _("unknown time")
 
36
        return _("unknown time ")
35
37
    else:
36
38
        secs_rem = int((100-percent) * elapsed/float(percent))
37
39
        time_rem = hourminsec(secs_rem)
38
 
        #I'm sure there are much smarter ways to do this...
39
 
        if time_rem[0] == 1:
40
 
            h_string = _("1 hour")
 
40
        output = ""
 
41
        
 
42
        # Add hours
 
43
        if time_rem[0]==0:
 
44
            pass
 
45
        elif time_rem[0] == 1:
 
46
            output = output + _("1 hour") + " "
41
47
        else:
42
 
            h_string = _("%i hours") %time_rem[0]
 
48
            output += _("%i hours") %time_rem[0]
43
49
            
44
 
        if time_rem[1] == 1:
45
 
            m_string = _("1 minute")
46
 
        else:
47
 
            m_string = _("%i minutes") %time_rem[1]
48
 
        
49
 
        if time_rem[2] == 2:
50
 
            s_string = _("1 second")
51
 
        else:
52
 
            s_string = _("%i seconds") %time_rem[2]
53
 
        
54
 
        if secs_rem > 3600:
55
 
            return "%s %s" %(h_string, m_string)
56
 
        elif secs_rem > 180:
57
 
            return "%s" %(m_string)
58
 
        elif secs_rem > 59:
59
 
            return "%s %s" %(m_string, s_string)
60
 
        else:
61
 
            return "%s" %(s_string)
 
50
        # Add minutes
 
51
        if time_rem[1] == 0:
 
52
            pass
 
53
        elif time_rem[1] == 1:
 
54
            output = output + _("1 minute") + " " 
 
55
        else:
 
56
            output = output + _("%i minutes") %time_rem[1] + " "
 
57
        
 
58
        # Only add seconds if there are less than three minutes to go
 
59
        if secs_rem <179:
 
60
            if time_rem[2] == 0:
 
61
                pass
 
62
            elif time_rem[2] == 1:
 
63
                output = output + _("1 second") + " " 
 
64
            else:
 
65
                output = output + _("%i seconds") %time_rem[2] + " "
 
66
        
 
67
        return output
62
68
            
63
69
 
64
70
def hourminsec(time):
150
156
    
151
157
    dialogue.set_name("OggConvert")
152
158
    dialogue.set_authors(ocv_info.authors)
 
159
    dialogue.set_artists(ocv_info.artists)
153
160
    dialogue.set_version(ocv_info.version)
154
161
    dialogue.set_copyright(ocv_info.copyright)
155
162
    dialogue.set_website(ocv_info.website)
158
165
    
159
166
    dialogue.run()
160
167
    dialogue.destroy()
161
 
    
 
168
 
 
169
def show_url(dialog, link, userdata):
 
170
    webbrowser.open(link)
 
171
 
 
172
# I know this is a bit of strange place to do this, but...
 
173
gtk.about_dialog_set_url_hook(show_url, None)
 
174