~tristan-brindle/baserip/trunk

« back to all changes in this revision

Viewing changes to Baserip/TitleSelect.py

  • Committer: Tristan Brindle
  • Date: 2006-12-20 03:30:52 UTC
  • Revision ID: tristan.brindle@gmail.com-20061220033052-524b9e99d6d507d3
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import pygtk
 
4
import gtk
 
5
import gtk.glade
 
6
from DVDInfo import GetDVDInfo
 
7
import Global
 
8
from Classes import Log, DVD, Title
 
9
 
 
10
class TitleSelectDialogue:
 
11
 
 
12
    def __init__(self, dvd_info):
 
13
        
 
14
        self.dvd_info = dvd_info
 
15
        
 
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?
 
19
        #
 
20
        # A convenience method that lets you easily attach a liststore to a treeview 
 
21
        # would be great...
 
22
        
 
23
        self.wTree = gtk.glade.XML("Baserip.glade","TitleDialogue")
 
24
        self.window = self.wTree.get_widget("TitleDialogue")
 
25
        
 
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()
 
29
        
 
30
        # Create a ListStore to hold the title data
 
31
        self.liststore = gtk.ListStore(str, str, str, str)
 
32
                                       
 
33
                
 
34
        self.treeview.set_model(self.liststore)
 
35
 
 
36
    
 
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)    
 
43
            
 
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)
 
48
        
 
49
        
 
50
        # Get data
 
51
        self.__fill_liststore()
 
52
        
 
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))
 
56
        else:
 
57
            self.selection.select_iter(self.__get_iter_from_title(self.dvd_info.longest_title))
 
58
        
 
59
        
 
60
        self.treeview.show()
 
61
        response = self.window.run()
 
62
        self.window.hide()
 
63
        
 
64
        if response == 1:
 
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
 
69
            
 
70
            
 
71
            
 
72
        
 
73
    def __fill_liststore(self):
 
74
        
 
75
        
 
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
 
78
        self.titles_ref = []
 
79
            
 
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...
 
84
                
 
85
                name = 'Title %i' %title.number
 
86
                
 
87
                if title.number == self.dvd_info.longest_title:
 
88
                    name += ' -- Main Feature'
 
89
                
 
90
                self.liststore.append([name, 
 
91
                                       '[%s]' %title.aspect, 
 
92
                                       "[%ix%i]" %(title.width, title.height), 
 
93
                                       hourminsec(title.length)])
 
94
                self.titles_ref.append(title.number)
 
95
 
 
96
 
 
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))
 
100
        
 
101
    def __get_title_from_iter(self, treeiter):
 
102
        rownum = int(self.liststore.get_string_from_iter(treeiter))
 
103
        return self.titles_ref[rownum]
 
104
 
 
105
def hourminsec(position):
 
106
    seconds = position ## duration in seconds
 
107
    minutes = seconds // 60
 
108
    seconds = seconds % 60
 
109
    hours = minutes //60
 
110
    minutes = minutes % 60      
 
111
    if hours == 0:
 
112
        return '%i:%02i' %(int(minutes),int(seconds))
 
113
    else:
 
114
        return '%i:%02i:%02i' %(int(hours),int(minutes),int(seconds)) 
 
115