~ubuntu-branches/debian/sid/hal/sid

« back to all changes in this revision

Viewing changes to tools/device-manager/Device.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-10-23 12:33:58 UTC
  • Revision ID: james.westby@ubuntu.com-20071023123358-xaf8mjc5n84d5gtz
Tags: upstream-0.5.10
ImportĀ upstreamĀ versionĀ 0.5.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""This file contains the Device class."""
2
 
 
3
 
import Const
4
 
 
5
 
class Device:
6
 
    def __init__(self, device_name, parent_name, properties):
7
 
        self.device_name = device_name
8
 
        self.parent_name = parent_name
9
 
        self.parent_device = None
10
 
        self.properties = properties
11
 
        self.children = []
12
 
 
13
 
    def print_tree(self, indent):
14
 
        if indent==0:
15
 
            print " "*indent + self.device_name
16
 
        else:
17
 
            print " "*indent + "- " + self.device_name
18
 
        for c in self.children:
19
 
            c.print_tree(indent+4)
20
 
 
21
 
    def populate_gtk_tree(self, tree_model, dont_show_virtual, representation):
22
 
        # see if we should show virtual devices
23
 
        if dont_show_virtual:
24
 
            try:
25
 
                if self.properties["info.virtual"]:
26
 
                    # do show all block devices, ide channels
27
 
                    if not self.properties["info.subsystem"] in ["block", "ide_host"]:
28
 
                        self.row = self.parent_device.row
29
 
                        # and recurse the childs
30
 
                        for c in self.children:
31
 
                            c.populate_gtk_tree(tree_model,
32
 
                                                dont_show_virtual,
33
 
                                                representation)
34
 
                        return
35
 
            except:
36
 
                pass
37
 
        if self.parent_device==None:
38
 
            self.row = None
39
 
        else:
40
 
            self.row = tree_model.append(self.parent_device.row)
41
 
 
42
 
        if self.row != None:
43
 
            # Get icon
44
 
            icon = representation.get_icon(self)
45
 
 
46
 
            tree_model.set_value(self.row, Const.PIXBUF_COLUMN, icon)
47
 
            try:
48
 
                title_name = self.properties["info.product"]
49
 
            except KeyError:
50
 
                title_name = "Unknown Device"
51
 
            except TypeError:
52
 
                title_name = "Unknown Device"
53
 
            tree_model.set_value(self.row, Const.TITLE_COLUMN, title_name)
54
 
            tree_model.set_value(self.row, Const.UDI_COLUMN, self.device_name)
55
 
 
56
 
        for c in self.children:
57
 
            c.populate_gtk_tree(tree_model,
58
 
                                dont_show_virtual,
59
 
                                representation)
60
 
            
61
 
    def find_by_udi(self, device_udi):
62
 
        if self.device_name==device_udi:
63
 
            return self
64
 
        for c in self.children:
65
 
            rc = c.find_by_udi(device_udi)
66
 
            if rc!=None:
67
 
                return rc
68
 
        return None