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
):
60 gtk
.MessageDialog(message_format
="All conversions succeded :)").show()
61 self
.progresswindow
.destroy()
64 last_add_folder_str
= ""
65 last_convert_folder_str
= ""
67 def _enable_or_disable_convertbutton(self
):
68 if len(self
.file_list
) > 0 and len(self
.outdirentry
.get_text()) > 0:
69 self
.convertbutton
.set_sensitive(True)
71 self
.convertbutton
.set_sensitive(False)
73 def on_treeview_click_row(self
, data
):
74 self
.removebutton
.set_sensitive(True)
76 def on_removebutton_clicked(self
, data
):
77 selection
= self
.tree_view
.get_selection()
78 (model
, index
) = selection
.get_selected_rows()
80 itmtoremove
= self
.tree_store
.get(self
.tree_store
.iter_nth_child(None, i
[0]), 0)[0]
81 self
.file_list
.remove(itmtoremove
)
82 self
.tree_store
.clear()
83 for f
in self
.file_list
:
84 self
.tree_store
.append(None, [f
])
85 self
.tree_view
.expand_all()
86 self
.removebutton
.set_sensitive(False)
88 self
._enable
_or
_disable
_convertbutton
()
90 def on_addbutton_clicked(self
, data
):
91 chooser
= gtk
.FileChooserDialog(title
=None,action
=gtk
.FILE_CHOOSER_ACTION_OPEN
,
92 buttons
=(gtk
.STOCK_CANCEL
,gtk
.RESPONSE_CANCEL
,gtk
.STOCK_OPEN
,gtk
.RESPONSE_OK
))
93 chooser
.set_select_multiple(True)
94 if self
.last_add_folder_str
:
95 chooser
.set_current_folder(self
.last_add_folder_str
)
97 ffilter
= gtk
.FileFilter()
98 ffilter
.set_name("Videos")
99 ffilter
.add_mime_type("video/*")
100 chooser
.add_filter(ffilter
)
102 response
= chooser
.run()
103 if response
== gtk
.RESPONSE_OK
:
104 self
.last_add_folder_str
= chooser
.get_current_folder()
106 for f
in chooser
.get_filenames():
107 if f
not in self
.file_list
:
108 self
.file_list
.append(f
)
109 self
.tree_store
.clear()
110 for f
in self
.file_list
:
111 self
.tree_store
.append(None, [f
])
112 self
.tree_view
.expand_all()
113 self
.removebutton
.set_sensitive(False)
115 self
._enable
_or
_disable
_convertbutton
()
119 def on_outdirbrowsebutton_clicked(self
, data
):
120 chooser
= gtk
.FileChooserDialog(title
=None,action
=gtk
.FILE_CHOOSER_ACTION_SELECT_FOLDER
,
121 buttons
=(gtk
.STOCK_CANCEL
,gtk
.RESPONSE_CANCEL
,gtk
.STOCK_OPEN
,gtk
.RESPONSE_OK
))
123 if self
.last_convert_folder_str
:
124 chooser
.set_current_folder(self
.last_convert_folder_str
)
125 response
= chooser
.run()
126 if response
== gtk
.RESPONSE_OK
:
127 self
.last_convert_folder_str
= chooser
.get_current_folder()
128 self
.outdirentry
.set_text(chooser
.get_filename())
129 self
._enable
_or
_disable
_convertbutton
()
132 def on_convertbutton_clicked(self
, data
):
133 command
= self
.commands
[self
.combobox
.get_active_text()]
134 outdir
= self
.outdirentry
.get_text()
136 CommandExecuter(GtkCommandExecuterView(), command
, self
.file_list
, outdir
)
138 def __init__(self
, commands
):
140 if 0 == len(commands
):
141 dialog
= gtk
.MessageDialog(None, gtk
.DIALOG_MODAL | gtk
.DIALOG_DESTROY_WITH_PARENT
,gtk
.MESSAGE_ERROR
, gtk
.BUTTONS_OK
)
142 dialog
.set_markup("None of the programs needed for the conversions specified in commands.xml were found. Cannot continue")
148 self
.commands
= commands
150 self
.widgets
= gtk
.glade
.XML("mainwin.glade")
152 self
.tree_store
= gtk
.TreeStore(gobject
.TYPE_STRING
)
154 self
.tree_view
= self
.widgets
.get_widget("fileview")
155 self
.combobox
= self
.widgets
.get_widget("commandcombo")
156 self
.outdirentry
= self
.widgets
.get_widget("outdirentry")
157 self
.removebutton
= self
.widgets
.get_widget("removebutton")
158 self
.convertbutton
= self
.widgets
.get_widget("convertbutton")
159 self
.window
= self
.widgets
.get_widget("window1")
161 self
.tree_view
.set_model(self
.tree_store
)
162 r
= gtk
.CellRendererText()
163 p_column
= gtk
.TreeViewColumn("", r
)
164 p_column
.add_attribute(r
,"text",0)
165 selection
= self
.tree_view
.get_selection()
166 selection
.set_mode(gtk
.SELECTION_MULTIPLE
)
167 selection
.connect("changed", self
.on_treeview_click_row
)
169 self
.tree_view
.insert_column(p_column
,0)
170 self
.tree_view
.set_rules_hint(True)
172 self
.widgets
.get_widget("addbutton").connect("clicked", self
.on_addbutton_clicked
)
173 self
.removebutton
.connect("clicked", self
.on_removebutton_clicked
)
174 self
.widgets
.get_widget("outdirbrowsebutton").connect("clicked", self
.on_outdirbrowsebutton_clicked
)
176 self
.convertbutton
.connect("clicked", self
.on_convertbutton_clicked
)
178 self
.combobox
.set_model(gtk
.ListStore(str))
179 cell
= gtk
.CellRendererText()
180 self
.combobox
.pack_start(cell
, True)
181 self
.combobox
.add_attribute(cell
, 'text', 0)
184 self
.combobox
.append_text(c
.get_name())
185 self
.combobox
.set_active(0)
187 self
.window
.connect("delete-event", gtk
.main_quit
)
188 self
.window
.show_all()
190 gtk
.gdk
.threads_enter()
192 gtk
.gdk
.threads_leave()