1 # Pyvconv - A simple frontend for ffmpeg/mencoder
2 # Copyright (C) 2008, Kristian Rumberg (kristianrumberg@gmail.com)
4 # Permission to use, copy, modify, and/or distribute this software for any
5 # purpose with or without fee is hereby granted, provided that the above
6 # copyright notice and this permission notice appear in all copies.
8 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 from command_executer
import CommandExecuterView
23 from command_executer
import CommandExecuter
25 class GtkCommandExecuterView(CommandExecuterView
):
27 def on_abortbutton_clicked(self
, data
):
30 self
.progresswindow
.destroy()
33 CommandExecuterView
.__init
__(self
)
34 self
.widgets
= gtk
.glade
.XML("progresswin.glade")
35 self
.progresswindow
= self
.widgets
.get_widget("progresswindow")
36 self
.progresslabel
= self
.widgets
.get_widget("progresslabel")
37 self
.abortbutton
= self
.widgets
.get_widget("abortbutton")
38 self
.abortbutton
.connect("clicked", self
.on_abortbutton_clicked
)
39 self
.progresswindow
.show_all()
43 def recieve_executor(self
, executor
):
44 self
.executor
= executor
46 def starting_conversion(self
, infile
, index
, total
, outfile
):
47 gtk
.gdk
.threads_enter()
48 self
.progresswindow
.set_title("Converting " + os
.path
.basename(infile
) + " (" + str(index
) + "/" + str(total
) + ")")
49 gtk
.gdk
.threads_leave()
51 def update_progress(self
, logline
):
52 gtk
.gdk
.threads_enter()
53 self
.progresslabel
.set_text(logline
)
54 gtk
.gdk
.threads_leave()
56 gtk
.MessageDialog(message_format
="There was an error during the conversion", type=gtk
.MESSAGE_ERROR
).show()
57 self
.progresswindow
.destroy()
59 def finished_all(self
):
61 gtk
.MessageDialog(message_format
="All conversions succeded :)").show()
62 self
.progresswindow
.destroy()
65 def _enable_or_disable_convertbutton(self
):
66 if len(self
.file_list
) > 0 and len(self
.outdirentry
.get_text()) > 0:
67 self
.convertbutton
.set_sensitive(True)
69 self
.convertbutton
.set_sensitive(False)
71 def on_treeview_click_row(self
, data
):
72 self
.removebutton
.set_sensitive(True)
74 def on_removebutton_clicked(self
, data
):
75 selection
= self
.tree_view
.get_selection()
76 (model
, index
) = selection
.get_selected_rows()
78 itmtoremove
= self
.tree_store
.get(self
.tree_store
.iter_nth_child(None, i
[0]), 0)[0]
79 self
.file_list
.remove(itmtoremove
)
80 self
.tree_store
.clear()
81 for f
in self
.file_list
:
82 self
.tree_store
.append(None, [f
])
83 self
.tree_view
.expand_all()
84 self
.removebutton
.set_sensitive(False)
86 self
._enable
_or
_disable
_convertbutton
()
88 def on_addbutton_clicked(self
, data
):
89 chooser
= gtk
.FileChooserDialog(title
=None,action
=gtk
.FILE_CHOOSER_ACTION_OPEN
,
90 buttons
=(gtk
.STOCK_CANCEL
,gtk
.RESPONSE_CANCEL
,gtk
.STOCK_OPEN
,gtk
.RESPONSE_OK
))
91 chooser
.set_select_multiple(True)
93 ffilter
= gtk
.FileFilter()
94 ffilter
.set_name("Videos")
95 ffilter
.add_mime_type("video/*")
96 chooser
.add_filter(ffilter
)
98 response
= chooser
.run()
99 if response
== gtk
.RESPONSE_OK
:
100 for f
in chooser
.get_filenames():
101 if f
not in self
.file_list
:
102 self
.file_list
.append(f
)
103 self
.tree_store
.clear()
104 for f
in self
.file_list
:
105 self
.tree_store
.append(None, [f
])
106 self
.tree_view
.expand_all()
107 self
.removebutton
.set_sensitive(False)
109 self
._enable
_or
_disable
_convertbutton
()
113 def on_outdirbrowsebutton_clicked(self
, data
):
114 chooser
= gtk
.FileChooserDialog(title
=None,action
=gtk
.FILE_CHOOSER_ACTION_SELECT_FOLDER
,
115 buttons
=(gtk
.STOCK_CANCEL
,gtk
.RESPONSE_CANCEL
,gtk
.STOCK_OPEN
,gtk
.RESPONSE_OK
))
117 response
= chooser
.run()
118 if response
== gtk
.RESPONSE_OK
:
119 self
.outdirentry
.set_text(chooser
.get_filename())
120 self
._enable
_or
_disable
_convertbutton
()
123 def on_convertbutton_clicked(self
, data
):
124 command
= self
.commands
[self
.combobox
.get_active_text()]
125 outdir
= self
.outdirentry
.get_text()
127 CommandExecuter(GtkCommandExecuterView(), command
, self
.file_list
, outdir
)
129 def __init__(self
, commands
):
131 if 0 == len(commands
):
132 dialog
= gtk
.MessageDialog(None, gtk
.DIALOG_MODAL | gtk
.DIALOG_DESTROY_WITH_PARENT
,gtk
.MESSAGE_ERROR
, gtk
.BUTTONS_OK
)
133 dialog
.set_markup("None of the programs needed for the conversions specified in commands.xml were found. Cannot continue")
139 self
.commands
= commands
141 self
.widgets
= gtk
.glade
.XML("mainwin.glade")
143 self
.tree_store
= gtk
.TreeStore(gobject
.TYPE_STRING
)
145 self
.tree_view
= self
.widgets
.get_widget("fileview")
146 self
.combobox
= self
.widgets
.get_widget("commandcombo")
147 self
.outdirentry
= self
.widgets
.get_widget("outdirentry")
148 self
.removebutton
= self
.widgets
.get_widget("removebutton")
149 self
.convertbutton
= self
.widgets
.get_widget("convertbutton")
150 self
.window
= self
.widgets
.get_widget("window1")
152 self
.tree_view
.set_model(self
.tree_store
)
153 r
= gtk
.CellRendererText()
154 p_column
= gtk
.TreeViewColumn("", r
)
155 p_column
.add_attribute(r
,"text",0)
156 selection
= self
.tree_view
.get_selection()
157 selection
.set_mode(gtk
.SELECTION_MULTIPLE
)
158 selection
.connect("changed", self
.on_treeview_click_row
)
160 self
.tree_view
.insert_column(p_column
,0)
161 self
.tree_view
.set_rules_hint(True)
163 self
.widgets
.get_widget("addbutton").connect("clicked", self
.on_addbutton_clicked
)
164 self
.removebutton
.connect("clicked", self
.on_removebutton_clicked
)
165 self
.widgets
.get_widget("outdirbrowsebutton").connect("clicked", self
.on_outdirbrowsebutton_clicked
)
167 self
.convertbutton
.connect("clicked", self
.on_convertbutton_clicked
)
169 self
.combobox
.set_model(gtk
.ListStore(str))
170 cell
= gtk
.CellRendererText()
171 self
.combobox
.pack_start(cell
, True)
172 self
.combobox
.add_attribute(cell
, 'text', 0)
175 self
.combobox
.append_text(c
.get_name())
176 self
.combobox
.set_active(0)
178 self
.window
.connect("delete-event", gtk
.main_quit
)
179 self
.window
.show_all()
181 gtk
.gdk
.threads_enter()
183 gtk
.gdk
.threads_leave()