~tinarussell/tinasplash/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python
# Code by Tina

import pygtk
import gtk
import gtk.gdk
import gtk.glade
import gnome.ui
import tinasplash_rw as rw # "rw" = "read/write"
gnome.program_init("TinaSplash", "0.02")

class GUI:
    def __init__(self):
        """Activate the interface"""
        # Load the Glade file
        self.wTree = gtk.glade.XML(rw.myPath + "tinasplash.glade")
        
        # Define widgets
        self.mainWindow = self.wTree.get_widget("mainWindow")
        self.aboutWindow = self.wTree.get_widget("aboutWindow")
        self.previewImage = self.wTree.get_widget("previewImage")
        self.bootSplashView = self.wTree.get_widget("treeview-boot")
        self.bootSplashList = gtk.ListStore(str, str)
        self.bootSplashView.set_model(self.bootSplashList)
        
        # Set up the list
        renderer1 = gtk.CellRendererText()
        renderer2 = gtk.CellRendererText()
        column1 = gtk.TreeViewColumn("ID ", renderer1, text=0)
            #This "ID" column is kind of arbitrary... it's there because all
            #the examples I saw used two columns, and when I finally got this 
            #thing working I was using two columns, even though I only needed
            #one. Though I doubt having one more column than I needed helped
            #anything, I'm afraid to change it now that it works. So, I have
            #two columns, and one is invisible.
        column2 = gtk.TreeViewColumn("Images ", renderer2, text=1)
        column1.set_resizable(True)
        column1.set_visible(False)
        column2.set_resizable(True)
        self.bootSplashView.append_column(column1)
        self.bootSplashView.append_column(column2)
        
        #Fill the list with relevant data
        ci = [] # "ci" = "column iter"
        splashList = rw.getFileList(rw.splashPath, "xpm.gz")
        i = 0
        splashesPending = len(splashList)
        while len(splashList) > 0:
            self.bootSplashList.append()
            ci.append(self.bootSplashList.get_iter(i))
            relPath = splashList.pop(0)
            self.bootSplashList.set_value(ci[i], 0, relPath)
            self.bootSplashList.set_value(ci[i], 1, rw.os.path.basename(relPath))
            i += 1
        
        # Map signal events
        events = {"asplode":self.closeUpShop, "showAbout":self.showAbout, \
        "closeAbout":self.closeAbout, "cursorHasChanged":self.cursorHasChanged}
        self.wTree.signal_autoconnect(events)
        
        # Show main window
        self.mainWindow.show()
    
    def closeUpShop(self, spam):
        #Clear temporary files and exit.
        rw.clearTmp()
        gtk.main_quit(self, spam)
    
    def showAbout(self, spam):
        self.aboutWindow.show()
    
    def closeAbout(self, spam):
        self.aboutWindow.destroy()
    
    def cursorHasChanged(self, spam):
        """There's no signal for when a specific row in a treeView has been
        clicked on, but there is one for when the cursor has changed or been
        set, though it does not pass on the specific row as a parameter. So,
        when the cursor is moved or set, this function is called, which then
        checks for the cursor's position and changes the splashimage and
        preview accordingly."""
        #Detect cursor location.
        cursorPos = self.bootSplashView.get_cursor()
        relIter = self.bootSplashList.get_iter(cursorPos[0][0])
        
        #Find image location, extract from gzip, and display as preview.
        previewPath = self.bootSplashList.get_value(relIter, 0)
        tmpPath = rw.gzipExtractToTmp(previewPath)
        self.previewImage.set_from_file(tmpPath)
        
        #Replace splash image in menu.lst.
        rw.replaceSplash(previewPath)

if __name__ == "__main__":
    app = GUI()
    gtk.main()