~ubuntu-branches/ubuntu/raring/software-center/raring-proposed

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk3/session/displaystate.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2012-10-11 15:33:05 UTC
  • mfrom: (195.1.18 quantal)
  • Revision ID: package-import@ubuntu.com-20121011153305-fm5ln7if3rpzts4n
Tags: 5.4.1.1
* lp:~mvo/software-center/reinstall-previous-purchase-token-fix:
  - fix reinstall previous purchases that have a system-wide
    license key LP: #1065481
* lp:~mvo/software-center/lp1060106:
  - Add missing gettext init for utils/update-software-center-agent
    (LP: #1060106)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Canonical
 
2
#
 
3
# Authors:
 
4
#  Michael Vogt
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify it under
 
7
# the terms of the GNU General Public License as published by the Free Software
 
8
# Foundation; version 3.
 
9
#
 
10
# This program is distributed in the hope that it will be useful, but WITHOUT
 
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
12
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
13
# details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along with
 
16
# this program; if not, write to the Free Software Foundation, Inc.,
 
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
18
 
 
19
from gi.repository import Gtk
 
20
 
 
21
from softwarecenter.utils import utf8
 
22
 
 
23
# for DisplayState attribute type-checking
 
24
from softwarecenter.db.database import Application
 
25
from softwarecenter.db.categories import Category
 
26
from softwarecenter.backend.channel import SoftwareChannel
 
27
from softwarecenter.db.appfilter import AppFilter
 
28
 
 
29
 
 
30
class DisplayState(object):
 
31
    """ This represents the display state for the undo history """
 
32
 
 
33
    _attrs = {'category': (type(None), Category),
 
34
              'channel': (type(None), SoftwareChannel),
 
35
              'subcategory': (type(None), Category),
 
36
              'search_term': (str,),
 
37
              'application': (type(None), Application),
 
38
              'limit': (int,),
 
39
              'filter': (type(None), AppFilter),
 
40
              'vadjustment': (float, ),
 
41
            }
 
42
 
 
43
    def __init__(self):
 
44
        self.category = None
 
45
        self.channel = None
 
46
        self.subcategory = None
 
47
        self.search_term = ""
 
48
        self.application = None
 
49
        self.limit = 0
 
50
        self.filter = None
 
51
        self.vadjustment = 0.0
 
52
 
 
53
    def __setattr__(self, name, val):
 
54
        attrs = self._attrs
 
55
        if name not in attrs:
 
56
            raise AttributeError("The attr name \"%s\" is not permitted" %
 
57
                name)
 
58
            Gtk.main_quit()
 
59
        if not isinstance(val, attrs[name]):
 
60
            msg = "Attribute %s expects %s, got %s" % (name, attrs[name],
 
61
                type(val))
 
62
            raise TypeError(msg)
 
63
            Gtk.main_quit()
 
64
        return object.__setattr__(self, name, val)
 
65
 
 
66
    def __str__(self):
 
67
        s = utf8('%s %s "%s" %s %s') % \
 
68
                                  (self.category,
 
69
                                   self.subcategory,
 
70
                                   self.search_term,
 
71
                                   self.application,
 
72
                                   self.channel)
 
73
        return s
 
74
 
 
75
    def copy(self):
 
76
        state = DisplayState()
 
77
        state.channel = self.channel
 
78
        state.category = self.category
 
79
        state.subcategory = self.subcategory
 
80
        state.search_term = self.search_term
 
81
        state.application = self.application
 
82
        state.limit = self.limit
 
83
        if self.filter:
 
84
            state.filter = self.filter.copy()
 
85
        else:
 
86
            state.filter = None
 
87
        state.vadjustment = self.vadjustment
 
88
        return state
 
89
 
 
90
    def reset(self):
 
91
        self.channel = None
 
92
        self.category = None
 
93
        self.subcategory = None
 
94
        self.search_term = ""
 
95
        self.application = None
 
96
        self.limit = 0
 
97
        if self.filter:
 
98
            self.filter.reset()
 
99
        self.vadjustment = 0.0