update
[bitbake.git] / bin / commander / provideritem.py
1 #!/usr/bin/env python
2 # -*- coding: iso8859-15 -*-
3
4 from qt import *
5 from appinfo import *
6 from packages import Packages
7
8 class ProviderItem( QListViewItem ): #QCheckListItem
9
10     columns = { "PROVIDES":     0,
11                 "CHECK":        1,
12                 "unpack":2, "patch":3, "configure":4, "compile":5, "stage":6, "install":7,
13                 "STATUS":       8,
14                 "CATEGORY":     9,
15                 "SECTION":      10,
16                 "PRIORITY":     11,
17                 "MAINTAINER":   12,
18                 "SRC_URI":      13,
19                 "HOMEPAGE":     14,
20                 "DEPENDS":      15,
21                 "RDEPENDS":     16,
22                 "SHORTNAME":    17 }
23
24     icons = {}
25     
26     def __init__( self, parent, provider ):
27     
28         if not ProviderItem.icons:
29             ProviderItem.icons =  { "unpack"    : QPixmap( imageDir + "do_unpack.png" ),
30                "patch"     : QPixmap( imageDir + "do_patch.png" ),
31                "configure" : QPixmap( imageDir + "do_configure.png" ),
32                "compile"   : QPixmap( imageDir + "do_compile.png" ),
33                "stage"     : QPixmap( imageDir + "do_stage.png" ),
34                "install"   : QPixmap( imageDir + "do_install.png" ) }
35
36     
37         self.parent = parent
38         self.p = Packages.instance()
39         self.fullname = provider
40         self.shortname = provider.split( "/" )[-1]
41         self.virtual = self.virtualValue()
42
43         if self.virtual:
44             #
45             # check if a corresponding parent element already has been added
46             #
47             vparent = parent.findItem( self.virtual, 0 )
48             if not vparent:
49                 vparent = ProviderItem( parent, self.virtual )
50                 vparent.setPixmap( 0, QPixmap( imageDir + "virtual.png" ) )
51
52             QListViewItem.__init__( self, vparent, provider )
53             #QCheckListItem.__init__( self, vparent, provider, QCheckListItem.CheckBox )           
54         else:
55             QListViewItem.__init__( self, parent, provider )
56             #QCheckListItem.__init__( self, parent, provider, QCheckListItem.CheckBox )            
57
58         self.decorate()
59         self.setPixmap( 0, QPixmap( imageDir + "package.png" ) )
60         
61         self.setCheckStatus( False )
62         
63     def virtualValue( self ):
64         #print self.p.data(self.fullname, "PROVIDES" )
65         providers = self.p.data(self.fullname, "PROVIDES" ).split()
66         for p in providers:
67             if p.split( '/' )[0] == "virtual": return p
68
69     def setCheckStatus( self, checked ):
70         self.checked = checked
71         if self.checked:
72             self.setPixmap( 1, QPixmap( imageDir + "checked.png" ) )
73         else:
74             self.setPixmap( 1, QPixmap( imageDir + "unchecked.png" ) )
75             
76     def setBuildStatus( self, **args ):
77         for el in args:
78             if el in ProviderItem.columns:
79                 self.setPixmap( ProviderItem.columns[el], ( QPixmap(), ProviderItem.icons[el] )[ args[el] ] )
80         if "status" in args:
81             self.setText( ProviderItem.columns["STATUS"], args["status"] )
82         
83     def decorate( self ):
84         if self.fullname.startswith( "virtual" ):
85             return
86         self.st( "PROVIDES", self.fullname.split('/')[-1] )
87         self.st( "CATEGORY", self.p.data(self.fullname, "CATEGORY") )
88         self.st( "SECTION", self.p.data(self.fullname, "SECTION") )
89         self.st( "PRIORITY", self.p.data(self.fullname, "PRIORITY") )
90         self.st( "MAINTAINER", self.p.data(self.fullname, "MAINTAINER") )
91         self.st( "SRC_URI", self.p.data(self.fullname, "SRC_URI") )
92         self.st( "HOMEPAGE", self.p.data(self.fullname, "HOMEPAGE") )
93         self.st( "DEPENDS", self.p.data(self.fullname, "DEPENDS") )
94         self.st( "RDEPENDS", self.p.data(self.fullname, "RDEPENDS") )
95         self.st( "SHORTNAME", self.shortname )
96
97     def st( self, column, value ):
98         self.setText( ProviderItem.columns[column], value )
99         
100     def toggleCheck( self ):
101         self.setCheckStatus( not self.checked )
102
103 #------------------------------------------------------------------------#
104 # main
105 #------------------------------------------------------------------------#
106
107 if __name__ == "__main__":
108     import sys
109     from qt import *
110     app = QApplication( sys.argv )
111     mw = QListView()
112     app.setMainWidget( mw )
113     app.exec_loop()
114