Merge lp:~mvo/software-center/refactor-move-displaystate into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 3117
Proposed branch: lp:~mvo/software-center/refactor-move-displaystate
Merge into: lp:software-center
Diff against target: 282 lines (+110/-84)
6 files modified
softwarecenter/ui/gtk3/panes/historypane.py (+2/-1)
softwarecenter/ui/gtk3/panes/pendingpane.py (+1/-1)
softwarecenter/ui/gtk3/panes/softwarepane.py (+2/-78)
softwarecenter/ui/gtk3/session/displaystate.py (+99/-0)
tests/gtk3/test_navhistory.py (+1/-1)
tests/gtk3/windows.py (+5/-3)
To merge this branch: bzr merge lp:~mvo/software-center/refactor-move-displaystate
Reviewer Review Type Date Requested Status
Łukasz Czyżykowski (community) Approve
software-store-developers Pending
Review via email: mp+120712@code.launchpad.net

Description of the change

Small refactor to move the "DisplayState" out of the softwarepane.py
into its own file under "session" as its more logical (and easy to find)
there.

To post a comment you must log in.
3117. By Michael Vogt

add missing file, thanks to Lukaz

Revision history for this message
Łukasz Czyżykowski (lukasz-czyzykowski) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/ui/gtk3/panes/historypane.py'
2--- softwarecenter/ui/gtk3/panes/historypane.py 2012-08-07 13:15:08 +0000
3+++ softwarecenter/ui/gtk3/panes/historypane.py 2012-08-22 07:50:23 +0000
4@@ -30,7 +30,8 @@
5 from basepane import BasePane
6 from softwarecenter.enums import Icons
7 from softwarecenter.ui.gtk3.session.viewmanager import get_viewmanager
8-from softwarepane import DisplayState
9+
10+from softwarecenter.ui.gtk3.session.displaystate import DisplayState
11
12
13 class HistoryPane(Gtk.VBox, BasePane):
14
15=== modified file 'softwarecenter/ui/gtk3/panes/pendingpane.py'
16--- softwarecenter/ui/gtk3/panes/pendingpane.py 2012-08-07 13:15:08 +0000
17+++ softwarecenter/ui/gtk3/panes/pendingpane.py 2012-08-22 07:50:23 +0000
18@@ -22,8 +22,8 @@
19
20 from basepane import BasePane
21 from softwarecenter.ui.gtk3.em import StockEms
22-from softwarecenter.ui.gtk3.panes.softwarepane import DisplayState
23 from softwarecenter.ui.gtk3.models.pendingstore import PendingStore
24+from softwarecenter.ui.gtk3.session.displaystate import DisplayState
25
26 LOG = logging.getLogger(__name__)
27
28
29=== modified file 'softwarecenter/ui/gtk3/panes/softwarepane.py'
30--- softwarecenter/ui/gtk3/panes/softwarepane.py 2012-06-28 08:51:44 +0000
31+++ softwarecenter/ui/gtk3/panes/softwarepane.py 2012-08-22 07:50:23 +0000
32@@ -25,7 +25,6 @@
33 import xapian
34
35 from softwarecenter.backend import get_install_backend
36-from softwarecenter.db.database import Application
37 from softwarecenter.db.enquire import AppEnquire
38 from softwarecenter.enums import (
39 DEFAULT_SEARCH_LIMIT,
40@@ -35,7 +34,6 @@
41 )
42 from softwarecenter.utils import (
43 ExecutionTime,
44- utf8,
45 wait_for_apt_cache_ready,
46 )
47
48@@ -47,86 +45,12 @@
49 from softwarecenter.ui.gtk3.views.appview import AppView
50 from softwarecenter.ui.gtk3.views.appdetailsview import AppDetailsView
51
52+from softwarecenter.ui.gtk3.session.displaystate import DisplayState
53+
54 from basepane import BasePane
55
56 LOG = logging.getLogger(__name__)
57
58-# for DisplayState attribute type-checking
59-from softwarecenter.db.categories import Category
60-from softwarecenter.backend.channel import SoftwareChannel
61-from softwarecenter.db.appfilter import AppFilter
62-
63-
64-class DisplayState(object):
65-
66- _attrs = {'category': (type(None), Category),
67- 'channel': (type(None), SoftwareChannel),
68- 'subcategory': (type(None), Category),
69- 'search_term': (str,),
70- 'application': (type(None), Application),
71- 'limit': (int,),
72- 'filter': (type(None), AppFilter),
73- 'vadjustment': (float, ),
74- }
75-
76- def __init__(self):
77- self.category = None
78- self.channel = None
79- self.subcategory = None
80- self.search_term = ""
81- self.application = None
82- self.limit = 0
83- self.filter = None
84- self.vadjustment = 0.0
85-
86- def __setattr__(self, name, val):
87- attrs = self._attrs
88- if name not in attrs:
89- raise AttributeError("The attr name \"%s\" is not permitted" %
90- name)
91- Gtk.main_quit()
92- if not isinstance(val, attrs[name]):
93- msg = "Attribute %s expects %s, got %s" % (name, attrs[name],
94- type(val))
95- raise TypeError(msg)
96- Gtk.main_quit()
97- return object.__setattr__(self, name, val)
98-
99- def __str__(self):
100- s = utf8('%s %s "%s" %s %s') % \
101- (self.category,
102- self.subcategory,
103- self.search_term,
104- self.application,
105- self.channel)
106- return s
107-
108- def copy(self):
109- state = DisplayState()
110- state.channel = self.channel
111- state.category = self.category
112- state.subcategory = self.subcategory
113- state.search_term = self.search_term
114- state.application = self.application
115- state.limit = self.limit
116- if self.filter:
117- state.filter = self.filter.copy()
118- else:
119- state.filter = None
120- state.vadjustment = self.vadjustment
121- return state
122-
123- def reset(self):
124- self.channel = None
125- self.category = None
126- self.subcategory = None
127- self.search_term = ""
128- self.application = None
129- self.limit = 0
130- if self.filter:
131- self.filter.reset()
132- self.vadjustment = 0.0
133-
134
135 class SoftwarePane(Gtk.VBox, BasePane):
136 """ Common base class for AvailablePane and InstalledPane"""
137
138=== added file 'softwarecenter/ui/gtk3/session/displaystate.py'
139--- softwarecenter/ui/gtk3/session/displaystate.py 1970-01-01 00:00:00 +0000
140+++ softwarecenter/ui/gtk3/session/displaystate.py 2012-08-22 07:50:23 +0000
141@@ -0,0 +1,99 @@
142+# Copyright (C) 2009 Canonical
143+#
144+# Authors:
145+# Michael Vogt
146+#
147+# This program is free software; you can redistribute it and/or modify it under
148+# the terms of the GNU General Public License as published by the Free Software
149+# Foundation; version 3.
150+#
151+# This program is distributed in the hope that it will be useful, but WITHOUT
152+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
153+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
154+# details.
155+#
156+# You should have received a copy of the GNU General Public License along with
157+# this program; if not, write to the Free Software Foundation, Inc.,
158+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
159+
160+from gi.repository import Gtk
161+
162+from softwarecenter.utils import utf8
163+
164+# for DisplayState attribute type-checking
165+from softwarecenter.db.database import Application
166+from softwarecenter.db.categories import Category
167+from softwarecenter.backend.channel import SoftwareChannel
168+from softwarecenter.db.appfilter import AppFilter
169+
170+
171+class DisplayState(object):
172+ """ This represents the display state for the undo history """
173+
174+ _attrs = {'category': (type(None), Category),
175+ 'channel': (type(None), SoftwareChannel),
176+ 'subcategory': (type(None), Category),
177+ 'search_term': (str,),
178+ 'application': (type(None), Application),
179+ 'limit': (int,),
180+ 'filter': (type(None), AppFilter),
181+ 'vadjustment': (float, ),
182+ }
183+
184+ def __init__(self):
185+ self.category = None
186+ self.channel = None
187+ self.subcategory = None
188+ self.search_term = ""
189+ self.application = None
190+ self.limit = 0
191+ self.filter = None
192+ self.vadjustment = 0.0
193+
194+ def __setattr__(self, name, val):
195+ attrs = self._attrs
196+ if name not in attrs:
197+ raise AttributeError("The attr name \"%s\" is not permitted" %
198+ name)
199+ Gtk.main_quit()
200+ if not isinstance(val, attrs[name]):
201+ msg = "Attribute %s expects %s, got %s" % (name, attrs[name],
202+ type(val))
203+ raise TypeError(msg)
204+ Gtk.main_quit()
205+ return object.__setattr__(self, name, val)
206+
207+ def __str__(self):
208+ s = utf8('%s %s "%s" %s %s') % \
209+ (self.category,
210+ self.subcategory,
211+ self.search_term,
212+ self.application,
213+ self.channel)
214+ return s
215+
216+ def copy(self):
217+ state = DisplayState()
218+ state.channel = self.channel
219+ state.category = self.category
220+ state.subcategory = self.subcategory
221+ state.search_term = self.search_term
222+ state.application = self.application
223+ state.limit = self.limit
224+ if self.filter:
225+ state.filter = self.filter.copy()
226+ else:
227+ state.filter = None
228+ state.vadjustment = self.vadjustment
229+ return state
230+
231+ def reset(self):
232+ self.channel = None
233+ self.category = None
234+ self.subcategory = None
235+ self.search_term = ""
236+ self.application = None
237+ self.limit = 0
238+ if self.filter:
239+ self.filter.reset()
240+ self.vadjustment = 0.0
241
242=== modified file 'tests/gtk3/test_navhistory.py'
243--- tests/gtk3/test_navhistory.py 2012-06-18 20:26:49 +0000
244+++ tests/gtk3/test_navhistory.py 2012-08-22 07:50:23 +0000
245@@ -7,9 +7,9 @@
246
247 from softwarecenter.ui.gtk3.session.navhistory import (
248 NavigationHistory, NavigationItem)
249-from softwarecenter.ui.gtk3.panes.softwarepane import DisplayState
250 from softwarecenter.ui.gtk3.panes.availablepane import AvailablePane
251 from softwarecenter.db.categories import Category
252+from softwarecenter.ui.gtk3.session.displaystate import DisplayState
253
254
255 class MockButton():
256
257=== modified file 'tests/gtk3/windows.py'
258--- tests/gtk3/windows.py 2012-06-20 12:44:14 +0000
259+++ tests/gtk3/windows.py 2012-08-22 07:50:23 +0000
260@@ -35,10 +35,12 @@
261 historypane,
262 installedpane,
263 pendingpane,
264- softwarepane,
265 viewswitcher,
266 )
267-from softwarecenter.ui.gtk3.session import appmanager
268+from softwarecenter.ui.gtk3.session import (
269+ appmanager,
270+ displaystate,
271+ )
272 from softwarecenter.ui.gtk3.utils import (
273 get_sc_icon_theme,
274 init_sc_css_provider,
275@@ -340,7 +342,7 @@
276 w.init_view()
277
278 w.state.channel = channel.AllInstalledChannel()
279- view_state = softwarepane.DisplayState()
280+ view_state = displaystate.DisplayState()
281 view_state.channel = channel.AllInstalledChannel()
282 w.display_overview_page(view_state)
283

Subscribers

People subscribed via source and target branches