6
from DVDInfo import GetDVDInfo
8
from Classes import Log, DVD, Title
10
class TitleSelectDialogue:
12
def __init__(self, dvd_info):
14
self.dvd_info = dvd_info
16
# Note to whomever is reading: what I want to do here is pretty simple.
17
# It's just a table of data that I want to display as such.
18
# So why does gtk.TreeView make it so bloody complicated?
20
# A convenience method that lets you easily attach a liststore to a treeview
23
self.wTree = gtk.glade.XML("Baserip.glade","TitleDialogue")
24
self.window = self.wTree.get_widget("TitleDialogue")
26
# Create treeview widget and add it to the dialogue
27
self.treeview = self.wTree.get_widget("title_dialogue_treeview")
28
self.selection = self.treeview.get_selection()
30
# Create a ListStore to hold the title data
31
self.liststore = gtk.ListStore(str, str, str, str)
34
self.treeview.set_model(self.liststore)
37
name_col = gtk.TreeViewColumn("Title", gtk.CellRendererText(), text = 0)
38
name_col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
39
name_col.set_fixed_width(180)
40
aspect_col = gtk.TreeViewColumn("Aspect", gtk.CellRendererText(), text = 1)
41
size_col = gtk.TreeViewColumn("Size", gtk.CellRendererText(), text = 2)
42
dur_col = gtk.TreeViewColumn("Duration", gtk.CellRendererText(), text=3)
44
self.treeview.append_column(name_col)
45
self.treeview.append_column(aspect_col)
46
self.treeview.append_column(size_col)
47
self.treeview.append_column(dur_col)
51
self.__fill_liststore()
53
# Select the previous title, or the longest title otherwise
54
if Global.TITLE_SELECTED:
55
self.selection.select_iter(self.__get_iter_from_title(Global.decode_options.title))
57
self.selection.select_iter(self.__get_iter_from_title(self.dvd_info.longest_title))
61
response = self.window.run()
65
# Translate the selected row into a DVD title:
66
treeiter = self.selection.get_selected()[1]
67
Global.decode_options.title = self.__get_title_from_iter(treeiter)
68
Global.TITLE_SELECTED = True
73
def __fill_liststore(self):
76
# We'll only list titles that are a minute or longer, so we need to link
77
# the list position with the title number as it is on the disc
80
for title in self.dvd_info.title:
81
if title.length >= 60:
82
# I like that thing Thoggen does of adding "Main Feature" to the
83
# longest title, so let's copy it...
85
name = 'Title %i' %title.number
87
if title.number == self.dvd_info.longest_title:
88
name += ' -- Main Feature'
90
self.liststore.append([name,
92
"[%ix%i]" %(title.width, title.height),
93
hourminsec(title.length)])
94
self.titles_ref.append(title.number)
97
def __get_iter_from_title(self, titlenum):
98
rownum = self.titles_ref.index(titlenum)
99
return self.liststore.get_iter_from_string(str(rownum))
101
def __get_title_from_iter(self, treeiter):
102
rownum = int(self.liststore.get_string_from_iter(treeiter))
103
return self.titles_ref[rownum]
105
def hourminsec(position):
106
seconds = position ## duration in seconds
107
minutes = seconds // 60
108
seconds = seconds % 60
110
minutes = minutes % 60
112
return '%i:%02i' %(int(minutes),int(seconds))
114
return '%i:%02i:%02i' %(int(hours),int(minutes),int(seconds))