19 FILM_DIRECTORY = '/home/carl/DVD'
23 inhibit_selection_update = False
28 for root, dirs, files in os.walk(FILM_DIRECTORY):
30 if os.path.basename(name) == 'info':
31 films.append(film.Film(os.path.join(root, os.path.dirname(name))))
33 films.sort(key = operator.attrgetter('name'))
35 def update_film_store():
38 global inhibit_selection_update
39 inhibit_selection_update = True
42 film_store.append([f.name])
43 inhibit_selection_update = False
45 def update_screen_store(screen_store, screens):
47 for s in screens.screens:
48 screen_store.append([s.name])
50 def create_film_tree_view(film_store):
51 view = gtk.TreeView(film_store)
52 column = gtk.TreeViewColumn()
53 view.append_column(column)
54 cell = gtk.CellRendererText()
55 column.pack_start(cell)
56 column.add_attribute(cell, 'text', 0)
57 view.get_selection().set_mode(gtk.SELECTION_SINGLE)
60 def create_screen_view(screen_store):
61 view = gtk.TreeView(screen_store)
62 column = gtk.TreeViewColumn()
63 view.append_column(column)
64 cell = gtk.CellRendererText()
65 column.pack_start(cell)
66 column.add_attribute(cell, 'text', 0)
67 view.get_selection().set_mode(gtk.SELECTION_SINGLE)
70 def get_selected_film():
71 (model, iter) = film_tree_view.get_selection().get_selected()
74 if f.name == model.get(iter, 0)[0]:
79 # @return Selected screen name
80 def get_selected_screen():
81 (model, iter) = screen_view.get_selection().get_selected()
82 return model.get(iter, 0)[0]
84 def film_selected(selection):
85 if inhibit_selection_update:
88 film_view.set(get_selected_film())
89 check_for_playability()
91 def screen_selected(selection):
92 check_for_playability()
94 def check_for_playability():
95 f = get_selected_film()
96 if screens.get_format(get_selected_screen(), f.ratio) is not None:
97 play_button.set_label("Play")
98 play_button.set_sensitive(True)
100 play_button.set_label("Cannot play: no setting for %s on screen %s" % (ratio.find(f.ratio).name(), get_selected_screen()))
101 play_button.set_sensitive(False)
103 def update_status(s):
104 global current_player
105 if current_player is None:
106 s.set_text("Not playing")
109 position = current_player.time_pos
112 position_hms = util.s_to_hms(position)
114 length = current_player.length
118 remaining = length - position
119 remaining_hms = util.s_to_hms(remaining)
120 s.set_text("Playing: %d:%02d:%02d, %d:%02d:%02d remaining" % (position_hms[0], position_hms[1], position_hms[2], remaining_hms[0], remaining_hms[1], remaining_hms[2]))
124 global current_player
125 f = get_selected_film()
126 current_player = player.get_player(f, screens.get_format(get_selected_screen(), f.ratio))
127 print current_player.args
130 global current_player
131 if current_player is not None:
132 current_player.stop()
133 current_player = None
135 def add_film_clicked(b):
137 c = gtk.FileChooserDialog("New Film", main_window, gtk.FILE_CHOOSER_ACTION_CREATE_FOLDER, (("Add", gtk.RESPONSE_OK)))
138 c.set_current_folder(FILM_DIRECTORY)
139 if c.run() == gtk.RESPONSE_OK:
141 f.data = c.get_filename()
142 f.name = os.path.basename(c.get_filename())
148 for i in range(0, len(films)):
149 if films[i].name == f.name:
150 film_tree_view.get_selection().select_path((i, ))
152 main_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
153 main_window.set_title("DVD-o-matic")
154 main_window.maximize()
156 main_hbox = gtk.HBox()
157 main_hbox.set_spacing(12)
158 main_hbox.set_border_width(12)
159 main_window.add(main_hbox)
162 film_view = film_view.FilmView(main_window)
163 screens = screens.Screens("screens")
165 left_vbox = gtk.VBox()
166 left_vbox.set_spacing(12)
167 main_hbox.pack_start(left_vbox, False, False)
168 right_vbox = gtk.VBox()
169 right_vbox.set_spacing(12)
170 main_hbox.pack_start(right_vbox)
172 film_store = gtk.ListStore(gobject.TYPE_STRING)
175 film_tree_view = create_film_tree_view(film_store)
176 left_vbox.pack_start(film_tree_view, True, True)
177 film_tree_view.get_selection().select_path((0, ))
178 film_tree_view.get_selection().connect("changed", film_selected)
180 add_film_button = gtk.Button(stock = gtk.STOCK_ADD)
181 left_vbox.pack_start(add_film_button, False, False)
182 add_film_button.connect("clicked", add_film_clicked)
184 screen_store = gtk.ListStore(gobject.TYPE_STRING)
185 update_screen_store(screen_store, screens)
187 screen_view = create_screen_view(screen_store)
188 left_vbox.pack_start(screen_view, False, False)
189 screen_view.get_selection().select_path((0, ))
190 screen_view.get_selection().connect("changed", screen_selected)
192 right_vbox.pack_start(film_view, False, False)
193 film_view.set(films[0])
195 play_button = gtk.Button("Play")
196 right_vbox.pack_start(play_button)
197 play_button.connect("clicked", play_clicked)
199 stop_button = gtk.Button("Stop")
200 right_vbox.pack_start(stop_button)
201 stop_button.connect("clicked", stop_clicked)
204 right_vbox.pack_start(status, False, False)
205 glib.timeout_add_seconds(1, update_status, status)
207 check_for_playability()
208 main_window.show_all()