Show More
@@ -344,7 +344,10 b' def _getattr(obj, name, default=_default):' | |||||
344 | elif isinstance(name, basestring): |
|
344 | elif isinstance(name, basestring): | |
345 | return getattr(obj, name, default) |
|
345 | return getattr(obj, name, default) | |
346 | elif callable(name): |
|
346 | elif callable(name): | |
347 | return name(obj) |
|
347 | try: | |
|
348 | return name(obj) | |||
|
349 | except AttributeError: | |||
|
350 | return default | |||
348 | else: |
|
351 | else: | |
349 | try: |
|
352 | try: | |
350 | return obj[name] |
|
353 | return obj[name] | |
@@ -444,8 +447,14 b' def xrepr(item, mode):' | |||||
444 | except AttributeError: |
|
447 | except AttributeError: | |
445 | pass |
|
448 | pass | |
446 | else: |
|
449 | else: | |
447 | for x in func(mode): |
|
450 | try: | |
448 | yield x |
|
451 | for x in func(mode): | |
|
452 | yield x | |||
|
453 | except (KeyboardInterrupt, SystemExit): | |||
|
454 | raise | |||
|
455 | except Exception: | |||
|
456 | yield (-1, True) | |||
|
457 | yield (style_default, repr(item)) | |||
449 | return |
|
458 | return | |
450 | if item is None: |
|
459 | if item is None: | |
451 | yield (-1, True) |
|
460 | yield (-1, True) | |
@@ -574,7 +583,12 b' def xattrs(item, mode):' | |||||
574 | except AttributeError: |
|
583 | except AttributeError: | |
575 | return (None,) |
|
584 | return (None,) | |
576 | else: |
|
585 | else: | |
577 | return func(mode) |
|
586 | try: | |
|
587 | return func(mode) | |||
|
588 | except (KeyboardInterrupt, SystemExit): | |||
|
589 | raise | |||
|
590 | except Exception: | |||
|
591 | return (None,) | |||
578 |
|
592 | |||
579 |
|
593 | |||
580 | def xiter(item, mode): |
|
594 | def xiter(item, mode): | |
@@ -1887,7 +1901,7 b' if curses is not None:' | |||||
1887 | def __init__(self, browser, input, iterator, mainsizey, *attrs): |
|
1901 | def __init__(self, browser, input, iterator, mainsizey, *attrs): | |
1888 | self.browser = browser |
|
1902 | self.browser = browser | |
1889 | self.input = input |
|
1903 | self.input = input | |
1890 |
self.header = |
|
1904 | self.header = [x for x in xrepr(input, "header") if not isinstance(x[0], int)] | |
1891 | # iterator for the input |
|
1905 | # iterator for the input | |
1892 | self.iterator = iterator |
|
1906 | self.iterator = iterator | |
1893 |
|
1907 | |||
@@ -2626,8 +2640,14 b' if curses is not None:' | |||||
2626 |
|
2640 | |||
2627 | def cmd_enterdefault(self): |
|
2641 | def cmd_enterdefault(self): | |
2628 | level = self.levels[-1] |
|
2642 | level = self.levels[-1] | |
2629 | self.report("entering object (default mode)...") |
|
2643 | try: | |
2630 |
|
|
2644 | item = level.items[level.cury].item | |
|
2645 | except IndexError: | |||
|
2646 | self.report(CommandError("No object")) | |||
|
2647 | curses.beep() | |||
|
2648 | else: | |||
|
2649 | self.report("entering object (default mode)...") | |||
|
2650 | self.enter(item, "default") | |||
2631 |
|
2651 | |||
2632 | def cmd_leave(self): |
|
2652 | def cmd_leave(self): | |
2633 | self.report("leave") |
|
2653 | self.report("leave") | |
@@ -2640,8 +2660,14 b' if curses is not None:' | |||||
2640 |
|
2660 | |||
2641 | def cmd_enter(self): |
|
2661 | def cmd_enter(self): | |
2642 | level = self.levels[-1] |
|
2662 | level = self.levels[-1] | |
2643 | self.report("entering object...") |
|
2663 | try: | |
2644 |
|
|
2664 | item = level.items[level.cury].item | |
|
2665 | except IndexError: | |||
|
2666 | self.report(CommandError("No object")) | |||
|
2667 | curses.beep() | |||
|
2668 | else: | |||
|
2669 | self.report("entering object...") | |||
|
2670 | self.enter(item, None) | |||
2645 |
|
2671 | |||
2646 | def cmd_enterattr(self): |
|
2672 | def cmd_enterattr(self): | |
2647 | level = self.levels[-1] |
|
2673 | level = self.levels[-1] | |
@@ -2650,17 +2676,29 b' if curses is not None:' | |||||
2650 | curses.beep() |
|
2676 | curses.beep() | |
2651 | self.report(AttributeError(_attrname(attrname))) |
|
2677 | self.report(AttributeError(_attrname(attrname))) | |
2652 | return |
|
2678 | return | |
2653 | attr = _getattr(level.items[level.cury].item, attrname) |
|
2679 | try: | |
2654 | if attr is _default: |
|
2680 | item = level.items[level.cury].item | |
2655 | self.report(AttributeError(_attrname(attrname))) |
|
2681 | except IndexError: | |
|
2682 | self.report(CommandError("No object")) | |||
|
2683 | curses.beep() | |||
2656 | else: |
|
2684 | else: | |
2657 | self.report("entering object attribute %s..." % _attrname(attrname)) |
|
2685 | attr = _getattr(item, attrname) | |
2658 |
|
|
2686 | if attr is _default: | |
|
2687 | self.report(AttributeError(_attrname(attrname))) | |||
|
2688 | else: | |||
|
2689 | self.report("entering object attribute %s..." % _attrname(attrname)) | |||
|
2690 | self.enter(attr, None) | |||
2659 |
|
2691 | |||
2660 | def cmd_detail(self): |
|
2692 | def cmd_detail(self): | |
2661 | level = self.levels[-1] |
|
2693 | level = self.levels[-1] | |
2662 | self.report("entering detail view for object...") |
|
2694 | try: | |
2663 |
|
|
2695 | item = level.items[level.cury].item | |
|
2696 | except IndexError: | |||
|
2697 | self.report(CommandError("No object")) | |||
|
2698 | curses.beep() | |||
|
2699 | else: | |||
|
2700 | self.report("entering detail view for object...") | |||
|
2701 | self.enter(item, "detail") | |||
2664 |
|
2702 | |||
2665 | def cmd_detailattr(self): |
|
2703 | def cmd_detailattr(self): | |
2666 | level = self.levels[-1] |
|
2704 | level = self.levels[-1] | |
@@ -2669,12 +2707,18 b' if curses is not None:' | |||||
2669 | curses.beep() |
|
2707 | curses.beep() | |
2670 | self.report(AttributeError(_attrname(attrname))) |
|
2708 | self.report(AttributeError(_attrname(attrname))) | |
2671 | return |
|
2709 | return | |
2672 | attr = _getattr(level.items[level.cury].item, attrname) |
|
2710 | try: | |
2673 | if attr is _default: |
|
2711 | item = level.items[level.cury].item | |
2674 | self.report(AttributeError(_attrname(attrname))) |
|
2712 | except IndexError: | |
|
2713 | self.report(CommandError("No object")) | |||
|
2714 | curses.beep() | |||
2675 | else: |
|
2715 | else: | |
2676 | self.report("entering detail view for attribute...") |
|
2716 | attr = _getattr(item, attrname) | |
2677 |
|
|
2717 | if attr is _default: | |
|
2718 | self.report(AttributeError(_attrname(attrname))) | |||
|
2719 | else: | |||
|
2720 | self.report("entering detail view for attribute...") | |||
|
2721 | self.enter(attr, "detail") | |||
2678 |
|
2722 | |||
2679 | def cmd_tooglemark(self): |
|
2723 | def cmd_tooglemark(self): | |
2680 | level = self.levels[-1] |
|
2724 | level = self.levels[-1] | |
@@ -2795,81 +2839,86 b' if curses is not None:' | |||||
2795 | posx += self.addstr(posy, posx, 0, self.scrsizex, msg, self.style_objheadernumber) |
|
2839 | posx += self.addstr(posy, posx, 0, self.scrsizex, msg, self.style_objheadernumber) | |
2796 | posx += self.addchr(posy, posx, 0, self.scrsizex, " ", self.scrsizex-posx, self.style_objheadernumber) |
|
2840 | posx += self.addchr(posy, posx, 0, self.scrsizex, " ", self.scrsizex-posx, self.style_objheadernumber) | |
2797 |
|
2841 | |||
2798 |
|
|
2842 | if not level.items: | |
2799 | scr.move(self._headerlines, 0) |
|
2843 | self.addchr(self._headerlines, 0, 0, self.scrsizex, " ", self.scrsizex, self.style_colheader) | |
2800 | scr.addstr(" %*s " % (level.numbersizex, "#"), self.getstyle(self.style_colheader)) |
|
2844 | self.addstr(self._headerlines+1, 0, 0, self.scrsizex, " <empty>", style_error) | |
2801 | scr.addstr(self.headersepchar, self.getstyle(self.style_colheadersep)) |
|
2845 | scr.clrtobot() | |
2802 | begx = level.numbersizex+3 |
|
|||
2803 | posx = begx-level.datastartx |
|
|||
2804 | for attrname in level.displayattrs: |
|
|||
2805 | strattrname = _attrname(attrname) |
|
|||
2806 | cwidth = level.colwidths[attrname] |
|
|||
2807 | header = strattrname.ljust(cwidth) |
|
|||
2808 | if attrname == level.displayattr[1]: |
|
|||
2809 | style = self.style_colheaderhere |
|
|||
2810 | else: |
|
|||
2811 | style = self.style_colheader |
|
|||
2812 | posx += self.addstr(self._headerlines, posx, begx, self.scrsizex, header, style) |
|
|||
2813 | posx += self.addstr(self._headerlines, posx, begx, self.scrsizex, self.headersepchar, self.style_colheadersep) |
|
|||
2814 | if posx >= self.scrsizex: |
|
|||
2815 | break |
|
|||
2816 | else: |
|
2846 | else: | |
2817 | scr.addstr(" "*(self.scrsizex-posx), self.getstyle(self.style_colheader)) |
|
2847 | # Paint column headers | |
2818 |
|
2848 | scr.move(self._headerlines, 0) | ||
2819 | # Paint rows |
|
2849 | scr.addstr(" %*s " % (level.numbersizex, "#"), self.getstyle(self.style_colheader)) | |
2820 | posy = self._headerlines+1+level.datastarty |
|
2850 | scr.addstr(self.headersepchar, self.getstyle(self.style_colheadersep)) | |
2821 | for i in xrange(level.datastarty, min(level.datastarty+level.mainsizey, len(level.items))): |
|
2851 | begx = level.numbersizex+3 | |
2822 | cache = level.items[i] |
|
|||
2823 | if i == level.cury: |
|
|||
2824 | style = self.style_numberhere |
|
|||
2825 | else: |
|
|||
2826 | style = self.style_number |
|
|||
2827 |
|
||||
2828 | posy = self._headerlines+1+i-level.datastarty |
|
|||
2829 | posx = begx-level.datastartx |
|
2852 | posx = begx-level.datastartx | |
2830 |
|
||||
2831 | scr.move(posy, 0) |
|
|||
2832 | scr.addstr(" %*d%s" % (level.numbersizex, i, " !"[cache.marked]), self.getstyle(style)) |
|
|||
2833 | scr.addstr(self.headersepchar, self.getstyle(self.style_sep)) |
|
|||
2834 |
|
||||
2835 | for attrname in level.displayattrs: |
|
2853 | for attrname in level.displayattrs: | |
|
2854 | strattrname = _attrname(attrname) | |||
2836 | cwidth = level.colwidths[attrname] |
|
2855 | cwidth = level.colwidths[attrname] | |
2837 |
|
|
2856 | header = strattrname.ljust(cwidth) | |
2838 | (align, length, parts) = level.displayrows[i-level.datastarty][attrname] |
|
2857 | if attrname == level.displayattr[1]: | |
2839 |
|
|
2858 | style = self.style_colheaderhere | |
2840 | align = 2 |
|
|||
2841 | padstyle = self.style_datapad |
|
|||
2842 | sepstyle = self.style_sep |
|
|||
2843 | if i == level.cury: |
|
|||
2844 | padstyle = self.getstylehere(padstyle) |
|
|||
2845 | sepstyle = self.getstylehere(sepstyle) |
|
|||
2846 | if align == 2: |
|
|||
2847 | posx += self.addchr(posy, posx, begx, self.scrsizex, self.nodatachar, cwidth, style) |
|
|||
2848 | else: |
|
2859 | else: | |
2849 |
|
|
2860 | style = self.style_colheader | |
2850 |
|
|
2861 | posx += self.addstr(self._headerlines, posx, begx, self.scrsizex, header, style) | |
2851 | elif align == 0: |
|
2862 | posx += self.addstr(self._headerlines, posx, begx, self.scrsizex, self.headersepchar, self.style_colheadersep) | |
2852 |
|
|
2863 | if posx >= self.scrsizex: | |
2853 |
|
|
2864 | break | |
2854 | posx += self.addchr(posy, posx, begx, self.scrsizex, self.datapadchar, pad1, padstyle) |
|
|||
2855 | for (style, text) in parts: |
|
|||
2856 | if i == level.cury: |
|
|||
2857 | style = self.getstylehere(style) |
|
|||
2858 | posx += self.addstr(posy, posx, begx, self.scrsizex, text, style) |
|
|||
2859 | if posx >= self.scrsizex: |
|
|||
2860 | break |
|
|||
2861 | if align == -1: |
|
|||
2862 | posx += self.addchr(posy, posx, begx, self.scrsizex, self.datapadchar, cwidth-length, padstyle) |
|
|||
2863 | elif align == 0: |
|
|||
2864 | posx += self.addchr(posy, posx, begx, self.scrsizex, self.datapadchar, pad2, padstyle) |
|
|||
2865 | posx += self.addstr(posy, posx, begx, self.scrsizex, self.datasepchar, sepstyle) |
|
|||
2866 | else: |
|
2865 | else: | |
2867 | scr.clrtoeol() |
|
2866 | scr.addstr(" "*(self.scrsizex-posx), self.getstyle(self.style_colheader)) | |
|
2867 | ||||
|
2868 | # Paint rows | |||
|
2869 | posy = self._headerlines+1+level.datastarty | |||
|
2870 | for i in xrange(level.datastarty, min(level.datastarty+level.mainsizey, len(level.items))): | |||
|
2871 | cache = level.items[i] | |||
|
2872 | if i == level.cury: | |||
|
2873 | style = self.style_numberhere | |||
|
2874 | else: | |||
|
2875 | style = self.style_number | |||
|
2876 | ||||
|
2877 | posy = self._headerlines+1+i-level.datastarty | |||
|
2878 | posx = begx-level.datastartx | |||
|
2879 | ||||
|
2880 | scr.move(posy, 0) | |||
|
2881 | scr.addstr(" %*d%s" % (level.numbersizex, i, " !"[cache.marked]), self.getstyle(style)) | |||
|
2882 | scr.addstr(self.headersepchar, self.getstyle(self.style_sep)) | |||
|
2883 | ||||
|
2884 | for attrname in level.displayattrs: | |||
|
2885 | cwidth = level.colwidths[attrname] | |||
|
2886 | try: | |||
|
2887 | (align, length, parts) = level.displayrows[i-level.datastarty][attrname] | |||
|
2888 | except KeyError: | |||
|
2889 | align = 2 | |||
|
2890 | padstyle = self.style_datapad | |||
|
2891 | sepstyle = self.style_sep | |||
|
2892 | if i == level.cury: | |||
|
2893 | padstyle = self.getstylehere(padstyle) | |||
|
2894 | sepstyle = self.getstylehere(sepstyle) | |||
|
2895 | if align == 2: | |||
|
2896 | posx += self.addchr(posy, posx, begx, self.scrsizex, self.nodatachar, cwidth, style) | |||
|
2897 | else: | |||
|
2898 | if align == 1: | |||
|
2899 | posx += self.addchr(posy, posx, begx, self.scrsizex, self.datapadchar, cwidth-length, padstyle) | |||
|
2900 | elif align == 0: | |||
|
2901 | pad1 = (cwidth-length)//2 | |||
|
2902 | pad2 = cwidth-length-len(pad1) | |||
|
2903 | posx += self.addchr(posy, posx, begx, self.scrsizex, self.datapadchar, pad1, padstyle) | |||
|
2904 | for (style, text) in parts: | |||
|
2905 | if i == level.cury: | |||
|
2906 | style = self.getstylehere(style) | |||
|
2907 | posx += self.addstr(posy, posx, begx, self.scrsizex, text, style) | |||
|
2908 | if posx >= self.scrsizex: | |||
|
2909 | break | |||
|
2910 | if align == -1: | |||
|
2911 | posx += self.addchr(posy, posx, begx, self.scrsizex, self.datapadchar, cwidth-length, padstyle) | |||
|
2912 | elif align == 0: | |||
|
2913 | posx += self.addchr(posy, posx, begx, self.scrsizex, self.datapadchar, pad2, padstyle) | |||
|
2914 | posx += self.addstr(posy, posx, begx, self.scrsizex, self.datasepchar, sepstyle) | |||
|
2915 | else: | |||
|
2916 | scr.clrtoeol() | |||
2868 |
|
2917 | |||
2869 | # Add blank row headers for the rest of the screen |
|
2918 | # Add blank row headers for the rest of the screen | |
2870 | for posy in xrange(posy+1, self.scrsizey-2): |
|
2919 | for posy in xrange(posy+1, self.scrsizey-2): | |
2871 | scr.addstr(posy, 0, " " * (level.numbersizex+2), self.getstyle(self.style_colheader)) |
|
2920 | scr.addstr(posy, 0, " " * (level.numbersizex+2), self.getstyle(self.style_colheader)) | |
2872 | scr.clrtoeol() |
|
2921 | scr.clrtoeol() | |
2873 |
|
2922 | |||
2874 | posy = self.scrsizey-footery |
|
2923 | posy = self.scrsizey-footery | |
2875 | # Display footer |
|
2924 | # Display footer |
General Comments 0
You need to be logged in to leave comments.
Login now