4
# OggConvert -- Converts media files to Free formats
5
# (c) 2007 Tristan Brindle <tcbrindle at gmail dot com>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU Lesser General Public
9
# License as published by the Free Software Foundation; either
10
# version 2.1 of the License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# Lesser General Public License for more details.
17
# You should have received a copy of the GNU Lesser General Public
18
# License along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
def timeremaining(elapsed, percent):
28
"""Returns a string with the remaining time for an operation.
29
elapsed: elapsed time for the operation so far (in seconds)
30
percent: percentage of the operation completed so far"""
35
secs_rem = int((100-percent) * elapsed/float(percent))
36
time_rem = hourminsec(secs_rem)
37
#I'm sure there are much smarter ways to do this...
41
h_string = "%i hours" %time_rem[0]
46
m_string = "%i minutes" %time_rem[1]
51
s_string = "%i seconds" %time_rem[2]
54
return "%s %s" %(h_string, m_string)
56
return "%s" %(m_string)
58
return "%s %s" %(m_string, s_string)
60
return "%s" %(s_string)
64
"""Converts a given time in seconds to an (hours,minutes,seconds) tuple"""
66
minutes = seconds // 60
67
seconds = seconds % 60
69
minutes = minutes % 60
70
return (hours, minutes, seconds)
72
def confirm_overwrite(path, window=None):
74
Displays a dialogue asking the user to confirm they wish to overwrite the
75
file given in path. Return True if they wish to overwrite, False otherwise.
76
The option argument window specifies a GtkWindow to use as a transient.
77
(And yes, the text is copied word-for-word from Nautilus...)
79
dialogue = gtk.MessageDialog(window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
81
"A file named \"%s\" already exists. Do you want to replace it?" %os.path.basename(path))
83
dirname = os.path.basename(os.path.dirname(path)) # Urgh!
84
dialogue.format_secondary_text("The file already exists in \"%s\". Replacing it will overwrite its contents." %dirname)
86
dialogue.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, "_Replace", gtk.RESPONSE_OK)
87
response = dialogue.run()
89
if response ==gtk.RESPONSE_OK: return True
92
def dirac_warning(window=None):
94
Displays a warning box asking the user to make sure they realise Dirac is
96
Returns True if the user chooses to continue, False otherwise
99
dialogue = gtk.MessageDialog(window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
100
gtk.BUTTONS_NONE, "Dirac encoding still experimental")
102
dialogue.format_secondary_text("The Dirac encoder is still experimental. \
103
Files you convert with this version may not be viewable with future versions \
106
dialogue.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, "Contin_ue", gtk.RESPONSE_OK)
107
response = dialogue.run()
109
if response==gtk.RESPONSE_OK: return True
112
def stall_warning(window=None):
114
Displays a box warning the user that encoding has stalled, and they should
118
dialogue = gtk.MessageDialog(window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
119
gtk.BUTTONS_CLOSE, "Encoding seems to have stalled")
121
# Three sentences. Too much?
122
dialogue.format_secondary_text("If encoding was nearly complete, then it probably finished successfully. At other times, it means there has was problem with the encoder. In either case, it is recommended you cancel the encoding process and check the output file.")
126
def cancel_check(window=None):
128
Pops up a dialogue box asking if the user is sure they want to stop encoding
129
Returns True if to stop, False otherwise
131
dialogue = gtk.MessageDialog(window, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION,
132
gtk.BUTTONS_NONE, "Encoding is not complete")
134
dialogue.format_secondary_text("Are you sure you wish to cancel?")
136
dialogue.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, "Contin_ue", gtk.RESPONSE_OK)
138
response = dialogue.run()
140
if response==gtk.RESPONSE_CANCEL: return True
143
def about_dialogue(window=None):
145
Pops up a standard GTK About dialogue. Grabs all the info from ocv_info
147
dialogue = gtk.AboutDialog()
148
dialogue.set_transient_for(window)
150
dialogue.set_name("OggConvert")
151
dialogue.set_authors(ocv_info.authors)
152
dialogue.set_version(ocv_info.version)
153
dialogue.set_copyright(ocv_info.copyright)
154
dialogue.set_website(ocv_info.website)
155
dialogue.set_license(ocv_info.licence) # Learn to spell, GTK!