minor class renaming
[pyvconv.git] / gui.py
blob922365490deea3e5d2a2202bf04190725eb24de0
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.
16 import os
17 import gtk
18 import gobject
19 import gtk.glade
21 from command_executer import CommandExecuterView
22 from command_executer import CommandExecuter
24 class ConsoleCommandExecuterView(CommandExecuterView):
25 def __init__(self):
26 CommandExecuterView.__init__(self)
27 print "About to convert a list of files"
29 def starting_conversion(self, infile, index, total, outfile):
30 print "Began converting " + infile + " to " + outfile
32 def update_progress(self, logline):
33 print logline
35 def finished_conversion(self, infile, outfile):
36 print "Done converting " + infile + " to " + outfile
38 def finished_all(self):
39 print "All convertings done"
41 class GtkCommandExecuterView(CommandExecuterView):
43 def on_abortbutton_clicked(self, data):
44 print "Not implemented yet"
46 def __init__(self):
47 CommandExecuterView.__init__(self)
48 self.widgets = gtk.glade.XML("progresswin.glade")
49 self.progresswindow = self.widgets.get_widget("progresswindow")
50 self.progresslabel = self.widgets.get_widget("progresslabel")
51 self.abortbutton = self.widgets.get_widget("abortbutton")
52 self.abortbutton.connect("clicked", self.on_abortbutton_clicked)
53 self.progresswindow.show_all()
55 def starting_conversion(self, infile, index, total, outfile):
56 self.progresswindow.set_title("Converting " + os.path.basename(infile) + " (" + str(index) + "/" + str(total) + ")")
58 def update_progress(self, logline):
59 self.progresslabel.set_text(logline)
61 def finished_conversion(self, infile, outfile):
62 pass
64 def finished_all(self):
65 pass
67 class MyGui:
68 def _enable_or_disable_convertbutton(self):
69 if len(self.file_list) > 0 and len(self.widgets.get_widget("outdirentry").get_text()) > 0:
70 self.widgets.get_widget("convertbutton").set_sensitive(True)
71 else:
72 self.widgets.get_widget("convertbutton").set_sensitive(False)
74 def on_treeview_click_row(self, data):
75 self.widgets.get_widget("removebutton").set_sensitive(True)
77 def on_removebutton_clicked(self, data):
78 selection = self.tree_view.get_selection()
79 (model, index) = selection.get_selected_rows()
80 for i in index:
81 itmtoremove = self.tree_store.get(self.tree_store.iter_nth_child(None, i[0]), 0)[0]
82 self.file_list.remove(itmtoremove)
83 self.tree_store.clear()
84 for f in self.file_list:
85 self.tree_store.append(None, [f])
86 self.tree_view.expand_all()
87 self.widgets.get_widget("removebutton").set_sensitive(False)
89 self._enable_or_disable_convertbutton()
91 def on_addbutton_clicked(self, data):
92 chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN,
93 buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
94 chooser.set_select_multiple(True)
96 filter = gtk.FileFilter()
97 filter.set_name("Videos")
98 filter.add_mime_type("video/*")
99 chooser.add_filter(filter)
101 response = chooser.run()
102 if response == gtk.RESPONSE_OK:
103 for f in chooser.get_filenames():
104 if f not in self.file_list:
105 self.file_list.append(f)
106 self.tree_store.clear()
107 for f in self.file_list:
108 self.tree_store.append(None, [f])
109 self.tree_view.expand_all()
110 self.widgets.get_widget("removebutton").set_sensitive(False)
112 self._enable_or_disable_convertbutton()
114 elif response == gtk.RESPONSE_CANCEL:
115 pass
116 chooser.destroy()
118 def on_outdirbrowsebutton_clicked(self, data):
119 chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
120 buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
122 response = chooser.run()
123 if response == gtk.RESPONSE_OK:
124 self.widgets.get_widget("outdirentry").set_text(chooser.get_filename())
125 self._enable_or_disable_convertbutton()
126 chooser.destroy()
128 def on_convertbutton_clicked(self, data):
129 command = self.commands[self.combobox.get_active_text()]
130 outdir = self.widgets.get_widget("outdirentry").get_text()
132 self.widgets.get_widget("convertbutton").set_sensitive(False)
133 CommandExecuter(GtkCommandExecuterView(), command, self.file_list, outdir)
135 def __init__(self, commands):
136 self.widgets = gtk.glade.XML("mainwin.glade")
138 self.tree_store = gtk.TreeStore(gobject.TYPE_STRING)
140 self.tree_view = self.widgets.get_widget("fileview")
141 self.tree_view.set_model(self.tree_store)
142 r = gtk.CellRendererText()
143 p_column = gtk.TreeViewColumn("", r)
144 p_column.add_attribute(r,"text",0)
145 selection = self.tree_view.get_selection()
146 selection.set_mode(gtk.SELECTION_MULTIPLE)
147 selection.connect("changed", self.on_treeview_click_row)
149 #self.iter = self.tree_store.append(None,["List of files to be converted"]) #Add package name
151 #tree_store.append(iter,["test.avi"])
152 self.file_list = []
154 self.tree_view.insert_column(p_column,0)
155 self.tree_view.set_rules_hint(True)
157 self.widgets.get_widget("addbutton").connect("clicked", self.on_addbutton_clicked)
158 self.widgets.get_widget("removebutton").connect("clicked", self.on_removebutton_clicked)
159 self.widgets.get_widget("outdirbrowsebutton").connect("clicked", self.on_outdirbrowsebutton_clicked)
161 self.commands = commands
162 self.widgets.get_widget("convertbutton").connect("clicked", self.on_convertbutton_clicked)
164 self.combobox = self.widgets.get_widget("commandcombo")
165 self.combobox.set_model(gtk.ListStore(str))
166 cell = gtk.CellRendererText()
167 self.combobox.pack_start(cell, True)
168 self.combobox.add_attribute(cell, 'text', 0)
170 for c in commands:
171 self.combobox.append_text(c.get_name())
172 self.combobox.set_active(0)
174 self.widgets.get_widget("window1").connect("delete-event", gtk.main_quit)
176 self.widgets.get_widget("window1").show_all()
178 gtk.main()