Changeset 3074

Show
Ignore:
Timestamp:
07/04/08 10:52:59 (5 years ago)
Author:
nopper
Message:

First implementation of help system for umit-console

Location:
branch/UmitPlugins
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branch/UmitPlugins/higwidgets/higtooltips.py

    r2996 r3074  
    3131        self.stock = stock 
    3232        self.file = file 
     33        self.widgets = [] 
     34 
     35    def append_widget(self, widget, expand=True, fill=True, padding=0, show=True): 
     36        self.widgets.append(((widget, expand, fill, padding), show)) 
    3337 
    3438class HIGTooltip(gtk.Window): 
     
    6771        self._tail_width = 10 
    6872        self._tail_offset = 10 
    69  
    70         HIGTooltip.__instance = self 
    7173 
    7274    def __create_widgets(self): 
     
    8587        self._left = gtk.Label() 
    8688 
     89        self.vbox = gtk.VBox() 
     90 
    8791    def __pack_widgets(self): 
    8892        hbox = gtk.HBox(False, 2) 
     
    9195        hbox.set_spacing(4) 
    9296 
    93         vbox = gtk.VBox(False, 2) 
    94         vbox.pack_start(hbox, False, False, 0) 
    95         vbox.pack_start(gtk.HSeparator(), False, False, 0) 
    96         vbox.pack_start(self._message, False, False, 0) 
    97  
    98         vbox.set_spacing(4) 
    99         vbox.set_border_width(10) 
     97        self.vbox.pack_start(hbox, False, False, 0) 
     98        self.vbox.pack_start(gtk.HSeparator(), False, False, 0) 
     99        self.vbox.pack_start(self._message, False, False, 0) 
     100 
     101        self.vbox.set_spacing(4) 
     102        self.vbox.set_border_width(10) 
    100103 
    101104        table = gtk.Table(3, 3) 
     
    105108        table.attach(self._right, 2, 3, 0, 3, xoptions=gtk.SHRINK) 
    106109         
    107         table.attach(vbox, 1, 2, 1, 2) 
     110        table.attach(self.vbox, 1, 2, 1, 2) 
    108111 
    109112        table.show_all() 
     
    295298            return (start_x, start_y, _w, _h) 
    296299 
    297  
    298         #if self._is_top: 
    299         #    # Draw bottom 
    300         #    if self._is_left: 
    301         #        # Draw right 
    302         #        cr.move_to(w, h) 
    303         #        cr.rel_line_to(-self._tail_width, -self._tail_height + offset) 
    304         #        cr.rel_line_to(-self._tail_width * 2, 0) 
    305         #        return (w, h) 
    306         #    else: 
    307         #        # Draw left 
    308         #        cr.move_to(x, h) 
    309         #        cr.rel_line_to(self._tail_width, -self._tail_height + offset) 
    310         #        cr.rel_line_to(self._tail_width * 2, 0) 
    311         #        return (x, h) 
    312         #else: 
    313         #    # Draw top 
    314         #    if self._is_left: 
    315         #        # Draw right 
    316         #        cr.move_to(w, y) 
    317         #        cr.rel_line_to(-self._tail_width, self._tail_height + offset) 
    318         #        cr.rel_line_to(-self._tail_width * 2, 0) 
    319         #        return (w, y) 
    320         #    else: 
    321         #        # Draw left 
    322         #        cr.move_to(x, y) 
    323         #        cr.rel_line_to(self._tail_width, self._tail_height + offset) 
    324         #        cr.rel_line_to(self._tail_width * 2, 0) 
    325         #        return (x, y) 
    326      
    327300    def do_realize(self): 
    328301        gtk.Window.do_realize(self) 
     
    386359        HIGTooltip.get_instance().widgets[widget] = data 
    387360     
    388     def __show_tooltip(self, w): 
     361    def show_at(self, w, data, x, y, time=None): 
     362        """ 
     363        Show the tooltip at location 
     364 
     365        (make x, y optional) 
     366        """ 
     367 
     368        assert (self != HIGTooltip.__instance, \ 
     369                "You should create another HIGTooltip object to do it") 
     370 
     371        if self._timeout_started or \ 
     372           self.flags() & gtk.VISIBLE or \ 
     373           self._hover: 
     374            return False 
     375 
     376        # We pack the childs now 
     377        for child, show in data.widgets: 
     378            self.vbox.pack_start(*child) 
     379 
     380            if show: 
     381                child[0].show() 
     382 
     383        self._hover = w 
     384        self._timeout_started = True 
     385        self.__show_tooltip(w, data, x, y) 
     386 
     387        if time: 
     388            self._timeout_id = gobject.timeout_add(time, self.close_and_destroy) 
     389 
     390    def close_and_destroy(self): 
     391        """ 
     392        Hide the widget resetting values used and also destroy window 
     393        """ 
     394        assert (self != HIGTooltip.__instance, \ 
     395                "You should create another HIGTooltip object to do it") 
     396 
     397        self._hover = None 
     398        self._timeout_started = False 
     399 
     400        if self._timeout_id: 
     401            gobject.source_remove(self._timeout_id) 
     402            self._timeout_id = None 
     403 
     404        self.hide() 
     405        self.destroy() 
     406 
     407        return False 
     408 
     409    def __show_tooltip(self, w, data=None, x=None, y=None): 
    389410        if not self._timeout_started or \ 
    390411           self.flags() & gtk.VISIBLE or \ 
     
    392413            return False 
    393414 
    394         window = w.get_parent_window() 
    395  
    396         x, y = window.get_position() 
    397         px, py, pmask = window.get_pointer() 
    398  
    399         x += px; y += py 
     415        if not data: 
     416            window = w.get_parent_window() 
     417 
     418            x, y = window.get_position() 
     419            px, py, pmask = window.get_pointer() 
     420 
     421            x += px; y += py 
     422 
    400423        rect = w.get_allocation() 
    401424 
     
    412435        else: self._is_top = False 
    413436         
    414         data = self._widgets[w] 
     437        if not data: 
     438            data = self._widgets[w] 
    415439 
    416440        self.title = data.title 
     
    451475        "Return the instance of HIGTooltip" 
    452476        if not HIGTooltip.__instance: 
    453             HIGTooltip() 
     477            HIGTooltip.__instance = HIGTooltip() 
    454478 
    455479        return HIGTooltip.__instance 
  • branch/UmitPlugins/source-plugins/umit-console/sources/console/console.py

    r3033 r3074  
    5050import gtk 
    5151import pango 
     52import gobject 
    5253 
    5354# Completions stuff 
     
    212213    """ Interactive GTK console class """ 
    213214 
     215    __gsignals__ = { 
     216        'eval' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_BOOLEAN, (gobject.TYPE_STRING, )) 
     217    } 
     218 
    214219    def __init__(self, namespace={}, quit_handler = None): 
    215220        """ Initialize console 
     
    400405        self.prompt1() 
    401406 
     407    def append_text(self, txt): 
     408        iter = self.buffer.get_iter_at_mark(self.buffer.get_insert()) 
     409        self.buffer.insert_with_tags_by_name(iter, txt, 'normal') 
     410        self.text.scroll_to_mark (self.buffer.get_insert(), 0) 
    402411 
    403412    def prompt1 (self): 
     
    560569    def execute (self, cmd): 
    561570        """ Execute a given command """ 
     571 
     572        if self.emit('eval', cmd): 
     573            return 
    562574 
    563575        sys.stdout, self.stdout = self.stdout, sys.stdout 
     
    733745        return False 
    734746 
    735  
     747gobject.type_register(Console) 
    736748 
    737749# ============================================================================= 
  • branch/UmitPlugins/source-plugins/umit-console/sources/main.py

    r3033 r3074  
    2929 
    3030from umitPlugin.Engine import Plugin 
     31from higwidgets.higtooltips import HIGTooltip, HIGTooltipData 
    3132 
    3233class ConsoleView(UmitView): 
    3334    label_text = "Umit Shell" 
    34      
     35 
    3536    def create_ui(self): 
    3637        con = console.Console(globals()) 
    3738        con.banner() 
    3839 
     40        con.connect('eval', self.__on_help) 
     41 
    3942        self._main_widget.add(con) 
    4043        self._main_widget.show_all() 
     44 
     45    def __on_help(self, console, cmd): 
     46        print console, cmd 
     47 
     48        cmd = cmd.replace("\n", "") 
     49 
     50        if cmd == "help": 
     51            console.append_text("Have you called help?\n") 
     52 
     53            data = HIGTooltipData( 
     54                "This is the help system of umitConsole.\n" 
     55                "Now i'll show you some umit funcionality\n\n\n" + 
     56                "<i>Press <b>Close</b> or <b>Next</b> to continue</i>\n") 
     57 
     58            hbb = gtk.HButtonBox() 
     59            hbb.set_layout(gtk.BUTTONBOX_END) 
     60 
     61            btn = gtk.Button(stock=gtk.STOCK_CLOSE) 
     62            hbb.pack_start(btn) 
     63             
     64            btn = gtk.Button(stock=gtk.STOCK_GO_FORWARD) 
     65            hbb.pack_start(btn) 
     66 
     67            hbb.show_all() 
     68            data.append_widget(hbb) 
     69 
     70            x, y = console.window.get_origin() 
     71 
     72            tip = HIGTooltip() 
     73            tip.show_at(console, data, x, y, 10000) 
     74 
     75            return True 
     76         
     77        return False 
    4178 
    4279class ConsolePlugin(Plugin): 
  • branch/UmitPlugins/source-plugins/update.sh

    r3018 r3074  
    88dir=`dirname $current` 
    99 
    10 for i in */ 
    11 do 
    12         cd ${current}/${i} 
    13         PYTHONPATH=$dir:$PYTHONPATH python setup.py install 
     10if [ -e "$1" ]; then 
     11        cd ${current}/$1 
     12        PYTHONPATH=$dir:$PYTHONPATH python setup.py install --no-compile 
    1413        mv *.ump ../ 
    15 done 
     14else 
     15    for i in */ 
     16    do 
     17        cd ${current}/${i} 
     18        PYTHONPATH=$dir:$PYTHONPATH python setup.py install --no-compile 
     19        mv *.ump ../ 
     20    done 
     21fi 
    1622 
    1723echo