Changeset 3093

Show
Ignore:
Timestamp:
07/07/08 15:10:11 (5 years ago)
Author:
nopper
Message:

Fixing bugs for console (umit-console plugin) and higtooltips (hiwidgets) and implementing a more sensed help system for umit-console

Location:
branch/UmitPlugins
Files:
4 modified

Legend:

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

    r3074 r3093  
    4949        Create a HIGTooltip object 
    5050        """ 
    51         gtk.Window.__init__(self, gtk.WINDOW_POPUP) 
     51        gtk.Window.__init__(self)#, gtk.WINDOW_POPUP) 
     52        self.set_decorated(False) 
    5253 
    5354        self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_MENU) # should be tooltip 
     
    381382                child[0].show() 
    382383 
     384        w.get_toplevel().connect('configure-event', self.__close_on_event) 
     385 
    383386        self._hover = w 
    384387        self._timeout_started = True 
     
    387390        if time: 
    388391            self._timeout_id = gobject.timeout_add(time, self.close_and_destroy) 
     392    def __close_on_event(self, w, event): 
     393        self.close_and_destroy() 
    389394 
    390395    def close_and_destroy(self): 
  • branch/UmitPlugins/source-plugins/umit-console/sources/console/console.py

    r3074 r3093  
    358358 
    359359        iter = self.buffer.get_iter_at_mark(self.buffer.get_insert()) 
    360         self.buffer.insert(iter, '\n') 
     360        self.buffer.insert_with_tags_by_name(iter, '\n', 'normal') 
    361361 
    362362        width = max(self.get_width(), 4) 
     
    383383                    else: 
    384384                        n_spaces = col_width - len(completions[ind]) 
    385                     self.buffer.insert(iter, completions[ind] + " " * n_spaces) 
    386             self.buffer.insert(iter, "\n") 
     385                    self.buffer.insert_with_tags_by_name( \ 
     386                            iter, completions[ind] + " " * n_spaces, 'normal') 
     387            self.buffer.insert_with_tags_by_name(iter, '\n', 'normal') 
    387388 
    388389        self.write (self.prompt, 'prompt') 
     
    526527         
    527528        l = self.current_line() 
    528         self.write ('\n') 
     529        self.write ('\n', 'normal') 
    529530        self.history.append (l) 
    530531        end = self.buffer.get_end_iter() 
     
    621622            for line in f: 
    622623                self.write ('\t'+line, 'script') 
    623             self.write ('\n') 
     624            self.write ('\n', 'normal') 
    624625            self.execute ("execfile('%s')" % filename) 
    625626            self.prompt1() 
     
    660661                self.buffer.apply_tag_by_name('script', start, end) 
    661662 
    662                 self.write('\n') 
     663                self.write('\n', 'normal') 
    663664            else: 
    664665                start, end = self.current_line_bounds() 
  • branch/UmitPlugins/source-plugins/umit-console/sources/main.py

    r3074 r3093  
    2828from tabber.views import UmitView 
    2929 
     30from umitCore.I18N import _ 
    3031from umitPlugin.Engine import Plugin 
     32from umitPlugin.Atoms import Singleton 
     33from higwidgets.higbuttons import HIGButton 
    3134from higwidgets.higtooltips import HIGTooltip, HIGTooltipData 
     35 
     36help_strings = [ 
     37    _("This is the help system of umitConsole.\n" 
     38    "Now i'll show you some umit funcionality\n\n\n" + 
     39    "<i>Press <b>Close</b> or <b>Next</b> to continue</i>\n"), 
     40 
     41    _("Ok, let's introduce myself. The window above is a Python prompt.\n" 
     42      "Type a line of Python code, hit <i>Enter</i> and watch it run!\n\n" 
     43      "For example try typing some math. Like <tt>2 + 6</tt>\n"), 
     44 
     45    _("It could handle everything that Python supports. But it is also\n" 
     46      "used to interact with <b>UMIT</b> codebase and his <i>UI</i>.\n" 
     47      "For example try typing:\n\n" 
     48      "<tt>from umitPlugin.Core import Core</tt>\n" 
     49      "<tt>Core().get_main_toolbar().hide()</tt>\n") 
     50] 
     51 
     52 
     53class MiniButton(gtk.Button): 
     54    def __init__(self, stock): 
     55        gtk.Button.__init__(self) 
     56 
     57        img = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_MENU) 
     58        img.show() 
     59 
     60        self.add(img) 
     61        self.set_relief(gtk.RELIEF_NONE) 
     62        self.connect('size-allocate', self.__size_allocate) 
     63 
     64    def __size_allocate(self, widget, alloc): 
     65        alloc.width = alloc.height 
     66        return gtk.Button.do_size_allocate(self, alloc) 
     67 
     68class Help(object): 
     69    def __init__(self, console): 
     70        self.index = 0 
     71        self.array = help_strings 
     72        self.console = console 
     73        self.tip = None 
     74 
     75    def next(self): 
     76        if self.index < len(self.array) - 1: 
     77            self.index += 1 
     78 
     79    def previous(self): 
     80        if self.index > 0: 
     81            self.index -= 1 
     82 
     83    def current(self): 
     84        string = self.array[self.index] 
     85        data = HIGTooltipData(string) 
     86 
     87        hbb = gtk.HBox(2, False) 
     88 
     89        btn = MiniButton(stock=gtk.STOCK_CLOSE) 
     90        btn.connect('clicked', self.__on_close) 
     91        hbb.pack_start(btn, False, False, 0) 
     92         
     93        btn = MiniButton(stock=gtk.STOCK_GO_BACK) 
     94        btn.connect('clicked', self.__on_back) 
     95 
     96        if self.index == 0: 
     97            btn.set_sensitive(False) 
     98 
     99        hbb.pack_start(btn, False, False, 0) 
     100 
     101        btn = MiniButton(stock=gtk.STOCK_GO_FORWARD) 
     102        btn.connect('clicked', self.__on_forward) 
     103 
     104        if self.index == len(self.array) - 1: 
     105            btn.set_sensitive(False) 
     106 
     107        hbb.pack_start(btn, False, False, 0) 
     108 
     109        hbb.show_all() 
     110         
     111        align = gtk.Alignment(1.0, 0.5) 
     112        align.add(hbb) 
     113 
     114        align.show_all() 
     115 
     116        data.append_widget(align) 
     117 
     118        return data 
     119 
     120    def __on_back(self, widget): 
     121        self.previous() 
     122        self.__on_close(widget) 
     123        self.show_help() 
     124 
     125    def __on_forward(self, widget): 
     126        self.next() 
     127        self.__on_close(widget) 
     128        self.show_help() 
     129 
     130    def __on_close(self, widget): 
     131        if self.tip: 
     132            self.tip.close_and_destroy() 
     133 
     134    def show_help(self): 
     135        self.__on_close(None) 
     136        self.tip = HIGTooltip() 
     137        x, y = self.console.window.get_origin() 
     138        self.tip.show_at(self.console, self.current(), x, y) 
    32139 
    33140class ConsoleView(UmitView): 
     
    35142 
    36143    def create_ui(self): 
    37         con = console.Console(globals()) 
    38         con.banner() 
     144        self.console = console.Console(globals()) 
     145        self.console.connect('eval', self.__on_help) 
     146        self.console.banner() 
    39147 
    40         con.connect('eval', self.__on_help) 
     148        self.help = Help(self.console) 
    41149 
    42         self._main_widget.add(con) 
     150        self._main_widget.add(self.console) 
    43151        self._main_widget.show_all() 
    44152 
    45153    def __on_help(self, console, cmd): 
    46         print console, cmd 
    47  
    48154        cmd = cmd.replace("\n", "") 
    49155 
    50156        if cmd == "help": 
    51             console.append_text("Have you called help?\n") 
     157            #console.append_text("Have you called help?\n") 
    52158 
    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) 
     159            self.help.show_help() 
    63160             
    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  
    75161            return True 
    76162         
  • branch/UmitPlugins/umitPlugin/Core.py

    r3090 r3093  
    109109 
    110110    def open_url(self, link): 
     111        """ 
     112        Open the default browser at link location 
     113 
     114        @param link the link to open 
     115        """ 
     116 
    111117        import webbrowser 
    112118