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.
21 from command_executer
import CommandExecuterView
22 from command_executer
import CommandExecuter
24 class GtkCommandExecuterView(CommandExecuterView
):
26 def on_abortbutton_clicked(self
, data
):
29 self
.progresswindow
.destroy()
32 CommandExecuterView
.__init
__(self
)
33 self
.widgets
= gtk
.glade
.XML("progresswin.glade")
34 self
.progresswindow
= self
.widgets
.get_widget("progresswindow")
35 self
.progresslabel
= self
.widgets
.get_widget("progresslabel")
36 self
.abortbutton
= self
.widgets
.get_widget("abortbutton")
37 self
.abortbutton
.connect("clicked", self
.on_abortbutton_clicked
)
38 self
.progresswindow
.show_all()
42 def recieve_executor(self
, executor
):
43 self
.executor
= executor
45 def starting_conversion(self
, infile
, index
, total
, outfile
):
46 self
.progresswindow
.set_title("Converting " + os
.path
.basename(infile
) + " (" + str(index
) + "/" + str(total
) + ")")
48 def update_progress(self
, logline
):
49 self
.progresslabel
.set_text(logline
)
52 gtk
.MessageDialog(message_format
="There was an error during the conversion", type=gtk
.MESSAGE_ERROR
).show()
53 self
.progresswindow
.destroy()
55 def finished_all(self
):
57 gtk
.MessageDialog(message_format
="All conversions succeded :)").show()
58 self
.progresswindow
.destroy()
61 def _enable_or_disable_convertbutton(self
):
62 if len(self
.file_list
) > 0 and len(self
.outdirentry
.get_text()) > 0:
63 self
.convertbutton
.set_sensitive(True)
65 self
.convertbutton
.set_sensitive(False)
67 def on_treeview_click_row(self
, data
):
68 self
.removebutton
.set_sensitive(True)
70 def on_removebutton_clicked(self
, data
):
71 selection
= self
.tree_view
.get_selection()
72 (model
, index
) = selection
.get_selected_rows()
74 itmtoremove
= self
.tree_store
.get(self
.tree_store
.iter_nth_child(None, i
[0]), 0)[0]
75 self
.file_list
.remove(itmtoremove
)
76 self
.tree_store
.clear()
77 for f
in self
.file_list
:
78 self
.tree_store
.append(None, [f
])
79 self
.tree_view
.expand_all()
80 self
.removebutton
.set_sensitive(False)
82 self
._enable
_or
_disable
_convertbutton
()
84 def on_addbutton_clicked(self
, data
):
85 chooser
= gtk
.FileChooserDialog(title
=None,action
=gtk
.FILE_CHOOSER_ACTION_OPEN
,
86 buttons
=(gtk
.STOCK_CANCEL
,gtk
.RESPONSE_CANCEL
,gtk
.STOCK_OPEN
,gtk
.RESPONSE_OK
))
87 chooser
.set_select_multiple(True)
89 ffilter
= gtk
.FileFilter()
90 ffilter
.set_name("Videos")
91 ffilter
.add_mime_type("video/*")
92 chooser
.add_filter(ffilter
)
94 response
= chooser
.run()
95 if response
== gtk
.RESPONSE_OK
:
96 for f
in chooser
.get_filenames():
97 if f
not in self
.file_list
:
98 self
.file_list
.append(f
)
99 self
.tree_store
.clear()
100 for f
in self
.file_list
:
101 self
.tree_store
.append(None, [f
])
102 self
.tree_view
.expand_all()
103 self
.removebutton
.set_sensitive(False)
105 self
._enable
_or
_disable
_convertbutton
()
109 def on_outdirbrowsebutton_clicked(self
, data
):
110 chooser
= gtk
.FileChooserDialog(title
=None,action
=gtk
.FILE_CHOOSER_ACTION_SELECT_FOLDER
,
111 buttons
=(gtk
.STOCK_CANCEL
,gtk
.RESPONSE_CANCEL
,gtk
.STOCK_OPEN
,gtk
.RESPONSE_OK
))
113 response
= chooser
.run()
114 if response
== gtk
.RESPONSE_OK
:
115 self
.outdirentry
.set_text(chooser
.get_filename())
116 self
._enable
_or
_disable
_convertbutton
()
119 def on_convertbutton_clicked(self
, data
):
120 command
= self
.commands
[self
.combobox
.get_active_text()]
121 outdir
= self
.outdirentry
.get_text()
123 CommandExecuter(GtkCommandExecuterView(), command
, self
.file_list
, outdir
)
125 def __init__(self
, commands
):
127 self
.commands
= commands
129 self
.widgets
= gtk
.glade
.XML("mainwin.glade")
131 self
.tree_store
= gtk
.TreeStore(gobject
.TYPE_STRING
)
133 self
.tree_view
= self
.widgets
.get_widget("fileview")
134 self
.combobox
= self
.widgets
.get_widget("commandcombo")
135 self
.outdirentry
= self
.widgets
.get_widget("outdirentry")
136 self
.removebutton
= self
.widgets
.get_widget("removebutton")
137 self
.convertbutton
= self
.widgets
.get_widget("convertbutton")
138 self
.window
= self
.widgets
.get_widget("window1")
140 self
.tree_view
.set_model(self
.tree_store
)
141 r
= gtk
.CellRendererText()
142 p_column
= gtk
.TreeViewColumn("", r
)
143 p_column
.add_attribute(r
,"text",0)
144 selection
= self
.tree_view
.get_selection()
145 selection
.set_mode(gtk
.SELECTION_MULTIPLE
)
146 selection
.connect("changed", self
.on_treeview_click_row
)
148 self
.tree_view
.insert_column(p_column
,0)
149 self
.tree_view
.set_rules_hint(True)
151 self
.widgets
.get_widget("addbutton").connect("clicked", self
.on_addbutton_clicked
)
152 self
.removebutton
.connect("clicked", self
.on_removebutton_clicked
)
153 self
.widgets
.get_widget("outdirbrowsebutton").connect("clicked", self
.on_outdirbrowsebutton_clicked
)
155 self
.convertbutton
.connect("clicked", self
.on_convertbutton_clicked
)
157 self
.combobox
.set_model(gtk
.ListStore(str))
158 cell
= gtk
.CellRendererText()
159 self
.combobox
.pack_start(cell
, True)
160 self
.combobox
.add_attribute(cell
, 'text', 0)
163 self
.combobox
.append_text(c
.get_name())
164 self
.combobox
.set_active(0)
166 self
.window
.connect("delete-event", gtk
.main_quit
)
167 self
.window
.show_all()