~ubuntu-branches/debian/sid/checkbox-ng/sid

« back to all changes in this revision

Viewing changes to checkbox_ng/ui.py

  • Committer: Package Import Robot
  • Author(s): Zygmunt Krynicki
  • Date: 2015-07-21 13:21:12 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20150721132112-amf111h2y2vfv9q8
Tags: 0.20-1
* New upstream release 
* debian/control: Use the new email address for the team
  (checkbox-devel@lists.ubuntu.com). 
* debian/patches/documentation-theme: refresh
* debian/patches/fix-tests-on-python35: drop (applied upstream)
* debian/control: require plainbox 0.22 or more recent (new APIs and fixes) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# This file is part of Checkbox.
2
2
#
3
 
# Copyright 2013-2014 Canonical Ltd.
 
3
# Copyright 2013-2015 Canonical Ltd.
4
4
# Written by:
5
5
#   Sylvain Pineau <sylvain.pineau@canonical.com>
6
6
#
33
33
from plainbox.vendor.textland import IApplication
34
34
from plainbox.vendor.textland import Size
35
35
from plainbox.vendor.textland import TextImage
36
 
from plainbox.vendor.textland import NORMAL, REVERSE, UNDERLINE
 
36
from plainbox.vendor.textland import NORMAL, REVERSE
37
37
 
38
38
 
39
39
logger = getLogger("checkbox.ng.ui")
246
246
        Expand/collapse a node
247
247
        """
248
248
        node, is_job = self.tree.get_node_by_index(self.top + self.highlight)
249
 
        if not is_job:
 
249
        if node is not None and not is_job:
250
250
            node.expanded = not(node.expanded)
251
251
 
252
252
    def _scroll(self, direction):
269
269
                (self.top + self.highlight + 1) != visible_length and
270
270
                (self.highlight + 1) != (self.image.size.height - 4)):
271
271
            self.highlight += 1
 
272
 
 
273
 
 
274
class ShowRerun(ScrollableTreeNode):
 
275
    """ Display the re-run screen."""
 
276
    def __init__(self, tree, title):
 
277
        super().__init__(tree, title)
 
278
 
 
279
    def consume_event(self, event: Event):
 
280
        if event.kind == EVENT_RESIZE:
 
281
            self.image = TextImage(event.data)  # data is the new size
 
282
        elif event.kind == EVENT_KEYBOARD:
 
283
            self.image = TextImage(self.image.size)
 
284
            if event.data.key == "up":
 
285
                self._scroll("up")
 
286
            elif event.data.key == "down":
 
287
                self._scroll("down")
 
288
            elif event.data.key == "space":
 
289
                self._selectNode()
 
290
            elif event.data.key == "enter":
 
291
                self._toggleNode()
 
292
            elif event.data.key in 'sS':
 
293
                self.tree.set_descendants_state(True)
 
294
            elif event.data.key in 'dD':
 
295
                self.tree.set_descendants_state(False)
 
296
            elif event.data.key in 'fF':
 
297
                self.tree.set_descendants_state(False)
 
298
                raise StopIteration
 
299
            elif event.data.key in 'rR':
 
300
                raise StopIteration
 
301
        self.repaint(event)
 
302
        return self.image
 
303
 
 
304
    def repaint(self, event: Event):
 
305
        ctx = DrawingContext(self.image)
 
306
        ctx.border(tm=1, bm=1)
 
307
        cols = self.image.size.width
 
308
        extra_cols = 0
 
309
        if cols > 80:
 
310
            extra_cols = cols - 80
 
311
        ctx.attributes.style = REVERSE
 
312
        ctx.print(' ' * cols)
 
313
        ctx.move_to(1, 0)
 
314
        bottom = self.top + self.image.size.height - 4
 
315
        ctx.print(self.title)
 
316
        ctx.move_to(1, self.image.size.height - 1)
 
317
        ctx.attributes.style = REVERSE
 
318
        ctx.print(_("Enter"))
 
319
        ctx.move_to(6, self.image.size.height - 1)
 
320
        ctx.attributes.style = NORMAL
 
321
        ctx.print(_(": Expand/Collapse"))
 
322
        ctx.move_to(27, self.image.size.height - 1)
 
323
        ctx.attributes.style = REVERSE
 
324
        # FIXME: i18n problem
 
325
        ctx.print("S")
 
326
        ctx.move_to(28, self.image.size.height - 1)
 
327
        ctx.attributes.style = NORMAL
 
328
        ctx.print("elect All")
 
329
        ctx.move_to(41, self.image.size.height - 1)
 
330
        ctx.attributes.style = REVERSE
 
331
        # FIXME: i18n problem
 
332
        ctx.print("D")
 
333
        ctx.move_to(42, self.image.size.height - 1)
 
334
        ctx.attributes.style = NORMAL
 
335
        ctx.print("eselect All")
 
336
        ctx.move_to(63 + extra_cols, self.image.size.height - 1)
 
337
        ctx.attributes.style = REVERSE
 
338
        # FIXME: i18n problem
 
339
        ctx.print("F")
 
340
        ctx.move_to(64 + extra_cols, self.image.size.height - 1)
 
341
        ctx.attributes.style = NORMAL
 
342
        ctx.print(_("inish"))
 
343
        ctx.move_to(73 + extra_cols, self.image.size.height - 1)
 
344
        ctx.attributes.style = REVERSE
 
345
        # FIXME: i18n problem
 
346
        ctx.print("R")
 
347
        ctx.move_to(74 + extra_cols, self.image.size.height - 1)
 
348
        ctx.attributes.style = NORMAL
 
349
        ctx.print("e-run")
 
350
        for i, line in enumerate(self.tree.render(cols - 3)[self.top:bottom]):
 
351
            ctx.move_to(2, i + 2)
 
352
            if i != self.highlight:
 
353
                ctx.attributes.style = NORMAL
 
354
            else:  # highlight the current line
 
355
                ctx.attributes.style = REVERSE
 
356
            ctx.print(line)