Changeset 4452

Show
Ignore:
Timestamp:
04/05/09 20:34:19 (4 years ago)
Author:
ignotus
Message:

Auto-scroll support and change superclass from VPaned to HIGVBox.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/umit/gui/NmapOutputViewer.py

    r4299 r4452  
    3030 
    3131from higwidgets.higbuttons import HIGButton 
     32from higwidgets.higboxes import HIGVBox 
    3233 
    3334from umit.core.I18N import _, enc 
     
    3738from umit.gui.NmapOutputProperties import NmapOutputProperties 
    3839 
    39 class NmapOutputViewer (gtk.VPaned): 
     40class NmapOutputViewer (HIGVBox): 
    4041    def __init__ (self, refresh=1, stop=1): 
    4142        self.nmap_highlight = NmapOutputHighlight() 
    42         gtk.VPaned.__init__ (self) 
     43        HIGVBox.__init__ (self) 
    4344         
    4445        # Creating widgets 
     
    6162         
    6263        # Adding widgets to the VPaned 
    63         self.pack1(self.scrolled, resize=True, shrink=True) 
    64         self.pack2(self.hbox_buttons, resize=True, shrink=False) 
     64        self._pack_expand_fill(self.scrolled) 
     65        self._pack_noexpand_nofill(self.hbox_buttons) 
    6566         
    6667        self.nmap_output_file = None 
     
    7677         
    7778        self.__create_tags() 
    78      
     79 
     80 
    7981    def __create_tags(self): 
    8082        tag_table = self.text_buffer.get_tag_table() 
     
    398400 
    399401            if self.nmap_previous_output != new_output: 
     402 
     403                # See if scroll is at the end (must be done before text_buffer 
     404                # changes 
     405                scroll_flag = False 
     406 
     407                scroll_upper = self.scrolled.get_vadjustment().upper 
     408                scroll_size = self.scrolled.get_vadjustment().page_size 
     409                scroll_end = scroll_upper - scroll_size 
     410                scroll_current = self.scrolled.get_vadjustment().get_value() 
     411 
     412                scroll_flag = (scroll_end == scroll_current) 
     413 
    400414                # Setting text and moving mark to the start  
    401415                # to update_colors correctly 
     
    403417 
    404418                self.nmap_previous_output = new_output 
     419         
     420                self.text_buffer.move_mark(self.mark, 
     421                                           self.text_buffer.get_start_iter()) 
     422                self.update_output_colors() 
     423 
     424                # Do all pending events (otherwise the adjustment don't 
     425                # work correctly sometimes) 
     426                while (gtk.events_pending()): 
     427                    gtk.main_iteration() 
     428 
     429                # Auto-scroll if scroll was at end 
     430                if scroll_flag: 
     431 
     432                    # Get and apply the new scrolled vadjustment value 
     433                    scroll_new_upper = self.scrolled.get_vadjustment().upper 
     434                    scroll_new_size = self.scrolled.get_vadjustment().page_size 
     435                    scroll_new_end = scroll_new_upper - scroll_new_size 
     436 
     437                    self.scrolled.get_vadjustment().set_value(scroll_new_end) 
     438 
     439                else: 
     440                    self.scrolled.get_vadjustment().set_value(scroll_current) 
    405441 
    406442            nmap_of.close() 
    407          
    408         self.text_buffer.move_mark(self.mark, self.text_buffer.get_start_iter()) 
    409         self.update_output_colors() 
    410      
     443 
     444 
    411445if __name__ == '__main__': 
    412446    w = gtk.Window()