Home Page do Portal
Brasil, um país de todos

Changeset 426

Show
Ignorar:
Timestamp:
05/08/08 13:12:11
Autor:
rogeriolino@gmail.com
Mensagem:

Removido utilizacao de pacote extra egg para gerar Status Icon.

Rogério A. Lino Filho

Arquivos:

Legenda:

Não modificado
Adicionado
Removido
Modificado
Copiado
Movido
  • cacic/trunk/agente-linux/pycacic/src/gui.py

    r417 r426  
    2323    def __init__(self): 
    2424        self.createTray() 
    25         self.mw = MainWindow() 
     25        self.mw = MainWindow()         
    2626     
    2727    def createTray(self): 
    28         # TrayIcon 
    29         self.tray = TrayIcon('pycacic') 
    30         self.eventbox = gtk.EventBox() 
    31         self.tray.add(self.eventbox) 
    32         self.eventbox.connect("button_press_event", self.tray_icon_clicked) 
    33         # Create the tooltip for the tray icon 
    34         self.tooltip = gtk.Tooltips() 
    35         # Configura imagem para o tray icon 
     28        # TrayIcon         
     29        self.statusIcon = gtk.StatusIcon() 
     30         
     31        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 
     32        self.window.set_title("StatusIcon test (II)") 
     33        self.window.connect('delete_event', self.delete_cb, self.statusIcon) 
     34  
     35        self.menu = gtk.Menu() 
     36        self.menuItem = gtk.ImageMenuItem(gtk.STOCK_ABOUT) 
     37        self.menuItem.connect('activate', self.activate_icon_cb) 
     38        self.menu.append(self.menuItem) 
     39        self.menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT) 
     40        self.menuItem.connect('activate', self.quit_cb, self.statusIcon) 
     41        self.menu.append(self.menuItem) 
     42         
    3643        self.imageicon = gtk.Image() 
    3744        pixbuf = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH) 
    3845        scaled_buf = pixbuf.scale_simple(23, 23, gtk.gdk.INTERP_BILINEAR) 
    39         self.imageicon.set_from_pixbuf(scaled_buf) 
    40         self.eventbox.add(self.imageicon) 
    41         # Exibe o tray icon 
    42         self.tray.show_all() 
    43         self.tooltip.set_tip(self.tray,'pycacic') 
     46        self.statusIcon.set_from_pixbuf(scaled_buf) 
     47         
     48        self.statusIcon.set_tooltip("Pycacic") 
     49        self.statusIcon.connect('activate', self.activate_icon_cb) 
     50        self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu) 
     51        self.statusIcon.set_visible(True) 
    4452     
    45     def tray_icon_clicked(self, signal, event): 
    46         """ """ 
    47         if event.button == 3: 
    48             PopupMenu().show_menu(event) 
    49         else: 
    50             self.mw.toggleWindow() 
     53    def delete_cb(widget, event, data = None): 
     54        if data: 
     55            data.set_blinking(True) 
     56        return False 
     57         
     58    def quit_cb(self, widget, data = None): 
     59        if data: 
     60            dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, 'Deseja realmente sair?')         
     61            dialog.set_title('PyCacic')                 
     62            dialog.set_icon_from_file(self.ICON_PATH) 
     63            dialog.width, dialog.height = dialog.get_size() 
     64            dialog.move(gtk.gdk.screen_width()/2-dialog.width/2, gtk.gdk.screen_height()/2-dialog.height/2) 
     65            retorno = dialog.run()               
     66            if retorno == gtk.RESPONSE_YES:     
     67                self.quit() 
     68            dialog.destroy() 
     69            data.set_visible(False) 
     70     
     71         
     72    def activate_icon_cb(self, widget, data = None): 
     73        self.mw.toggleWindow()     
     74     
     75    def popup_menu_cb(self, widget, button, time, data = None): 
     76        if button == 3: 
     77            if data: 
     78                data.show_all() 
     79                data.popup(None, None, None, 3, time) 
     80 
    5181 
    5282    def quit(self): 
     
    105135             
    106136 
    107 class PopupMenu(GUI): 
    108      
    109     def __init__(self):      
    110         # Create menu items 
    111         self.item_lang = gtk.MenuItem('Idioma', True) 
    112         self.item_about = gtk.MenuItem('Sobre', True) 
    113         self.item_exit = gtk.MenuItem('Sair', True) 
    114         # Connect the events 
    115         self.item_lang.connect('activate', self.conflang) 
    116         self.item_about.connect('activate', self.about)                            
    117         self.item_exit.connect('activate', self.exit) 
    118         # Create the menu 
    119         self.menu = gtk.Menu() 
    120         # Append menu items to the menu 
    121         self.menu.append(self.item_lang) 
    122         self.menu.append(self.item_about)         
    123         self.menu.append( self.item_exit) 
    124         self.menu.show_all() 
    125  
    126     def show_menu(self, event): 
    127         # Display the menu 
    128         self.menu.popup(None, None, None, event.button, event.time) 
    129      
    130     def conflang(self, event): 
    131         pass 
    132      
    133     def about(self, event): 
    134         pass                
    135      
    136     def exit(self, event): 
    137         dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, 'Deseja realmente sair?')         
    138         dialog.set_title('PyCacic')                 
    139         dialog.set_icon_from_file(self.ICON_PATH) 
    140         dialog.width, dialog.height = dialog.get_size() 
    141         dialog.move(gtk.gdk.screen_width()/2-dialog.width/2, gtk.gdk.screen_height()/2-dialog.height/2) 
    142         retorno = dialog.run()               
    143         if retorno == gtk.RESPONSE_YES:             
    144             self.quit()                         
    145         dialog.destroy() 
    146  
    147137if __name__ == '__main__': 
    148138    try: