Added Pane.clear.
This commit is contained in:
parent
48828364f9
commit
dd50043520
1 changed files with 35 additions and 17 deletions
52
wizpym.py
52
wizpym.py
|
@ -140,6 +140,22 @@ class Pane(gtk.VBox):
|
|||
self._error.pack_start(error_label, False, False, 10)
|
||||
self._error.show_all()
|
||||
|
||||
def clear(self, safe=None):
|
||||
"""Clear all the pane children but internal widgets.
|
||||
|
||||
If the safe parameter is a list, then its content should be
|
||||
widgets that should not be removed either. Invalid parameters
|
||||
are ignored.
|
||||
|
||||
This method leaves the header and the error labels untouched
|
||||
(eg. if they were displayed, they remain displayed).
|
||||
"""
|
||||
if safe is None or not isinstance(safe, list):
|
||||
safe = []
|
||||
safe.extend([self._header, self._error])
|
||||
for w in filter(lambda x: x not in safe, self.get_children()):
|
||||
self.remove(w)
|
||||
|
||||
def switch(self, klass):
|
||||
"""Update the switch using the given class.
|
||||
|
||||
|
@ -244,6 +260,17 @@ class ActivePane(Pane):
|
|||
gobject.idle_add(self._progress_box.remove,
|
||||
self._progress_box.get_children()[0])
|
||||
|
||||
def clear(self, safe=None):
|
||||
"""Clear all the pane children but internal widgets.
|
||||
|
||||
This method specializes Pane.clear so that the progress box is
|
||||
also left untouched.
|
||||
"""
|
||||
if safe is None or not isinstance(safe, list):
|
||||
safe = []
|
||||
safe.append(self._progress_box)
|
||||
Pane.clear(self, safe)
|
||||
|
||||
def enter(self):
|
||||
"""Proceed to this pane initialization.
|
||||
|
||||
|
@ -510,15 +537,9 @@ class GoogleSearchTestPane(ActivePane):
|
|||
def __init__(self, frame):
|
||||
ActivePane.__init__(self, frame)
|
||||
|
||||
self._inner_pane = gtk.VBox(False, 5)
|
||||
self.pack_start(self._inner_pane, True, True)
|
||||
|
||||
def enter(self):
|
||||
self.set_header('Google Code results for: "' + self.subject[0] + '"')
|
||||
|
||||
self.remove(self._inner_pane)
|
||||
self._inner_pane = gtk.VBox(False, 5)
|
||||
self.pack_start(self._inner_pane, True, True)
|
||||
self.clear()
|
||||
|
||||
# Start thread
|
||||
ActivePane.enter(self)
|
||||
|
@ -534,20 +555,17 @@ class GoogleSearchTestPane(ActivePane):
|
|||
gobject.idle_add(self._show_response, c.getresponse())
|
||||
|
||||
def _show_response(self, r):
|
||||
self.remove(self._inner_pane)
|
||||
self._inner_pane = gtk.VBox(False, 5)
|
||||
|
||||
lbl = None
|
||||
if r.status != 200:
|
||||
self._inner_pane.pack_start(
|
||||
gtk.Label('Got error (' + r.reason + ') from google'), True, False)
|
||||
lbl = gtk.Label('Got error (' + r.reason + ') from google')
|
||||
lbl.show()
|
||||
self.pack_start(lbl)
|
||||
else:
|
||||
tree = etree.fromstring(r.read())
|
||||
for e in tree.findall(self.XMLNS_ATOM + 'entry'):
|
||||
self._inner_pane.pack_start(
|
||||
gtk.Label(e.find(self.XMLNS_GCS + 'package').get('name')), False, False)
|
||||
|
||||
self._inner_pane.show_all()
|
||||
self.pack_start(self._inner_pane, True, True)
|
||||
lbl = gtk.Label(e.find(self.XMLNS_GCS + 'package').get('name'))
|
||||
lbl.show()
|
||||
self.pack_start(lbl)
|
||||
|
||||
|
||||
class LocalSearchTestPane(ActivePane):
|
||||
|
|
Loading…
Reference in a new issue