Página Inicial > Outros, Variados > Criando Applets para Avant Window Navigator

Criando Applets para Avant Window Navigator

É isso ai mesmo, dei uma rápida estudada sobre o assunto, e descobri como fazer esta maravilha.
Este post vou mostrar com fiz usando python, mas pretendo estudar como fazer em C.

Bem, precisamos instalar o python-awnlib. Assim a gente importa ela, e já era. A base da coisa toda é GTK, então os botões e tudo mais, ficam como no GTK.

Como de praxe, segue o código de um applet para desligar, reiniciar, trocar usuário e bloquear a tela. Simples icone, quando clica abre um dialogzinho com 3 botoes. E o evento de cada botão, executa um comando no shell.

Aproveitem

# -*- coding: iso-8859-1 -*- "'
import pygtk
pygtk.require('2.0')
import gtk
from gtk import gdk
import awn
import sys, os

class App(awn.AppletSimple):
   def __init__(self, uid, orient, height):
      # Initiate Applet
      awn.AppletSimple.__init__(self, uid, orient, height)
      self.height = height

      # Get, resize, set icon
      icon = gdk.pixbuf_new_from_file("/usr/share/icons/gnome/scalable/actions/system-log-out.svg")

      if height != icon.get_height():
         icon = icon.scale_simple(height,height,gtk.gdk.INTERP_BILINEAR)

      self.set_temp_icon(icon)

      # Get out title ready
      self.title = awn.awn_title_get_default()

      # Draw our dialog
      self.dialog = awn.AppletDialog(self)

      buttonHalt = gtk.Button("Desligar")
      buttonLogoff = gtk.Button("Finalizar Sessão")
      buttonLock = gtk.Button("Travar tela")

      self.dialog.add(buttonHalt)
      self.dialog.add(buttonLogoff)
      self.dialog.add(buttonLock)

      buttonHalt.show_all()
      buttonLogoff.show_all()
      buttonLock.show_all()

      self.showing_dlog = False

      buttonHalt.connect("button-press-event", self.buttonHalt_press)
      buttonLogoff.connect("button-press-event", self.buttonLogff_press)
      buttonLock.connect("button-press-event", self.buttonLock_press)
      self.connect("button-press-event", self.button_press)
      self.connect("enter-notify-event", self.enter_notify)
      self.connect("leave-notify-event", self.leave_notify)
      self.dialog.connect("focus-out-event", self.dialog_focus_out)

   def buttonHalt_press(self, widget, event):
      os.system("gnome-session-save –shutdown-dialog")
      
   def buttonLogff_press(self, widget, event):
      os.system("gnome-session-save –logout")
      
   def buttonLock_press(self, widget, event):
      os.system("gnome-screensaver-command -l")

   def button_press(self, widget, event):
      if self.showing_dlog:
         self.dialog.hide()
      else:
         self.dialog.show_all()
      self.title.hide(self)
      self.showing_dlog = not self.showing_dlog

   def dialog_focus_out(self, widget, event):
      self.dialog.hide()

   def enter_notify(self, widget, event):
      self.title.show(self, "Showdown Manager")

   def leave_notify(self, widget, event):
      self.title.hide (self)

if __name__ == "__main__":
   awn.init(sys.argv[1:])
   applet = App(awn.uid, awn.orient, awn.height)
   awn.init_applet(applet)
   applet.show_all()
   gtk.main()
 

Para criar o instalador, vc precisa criar um .desktop, no meu caso, ficou shutdown_manager.desktop, com o seguinte conteudo

[Desktop Entry]
Type=Application
X-AWN-AppletType=Python
X-AWN-AppletCategory=Development
Encoding=UTF-8
Name=AWN Shutdown Manager
Comment=Shutdown applet manager
Exec=shutdown_manager.py
Icon=/usr/share/icons/gnome/scalable/actions/system-log-out.svg
X-Ubuntu-Gettext-Domain=awn-extras-applets
 

Dai você compacta o .py e o .desktop em um .tar.gz, abrir o AWN, clicar em Applet/Instalar e selecionar seu .tar.gz

A pedidos, o meu exemplo para download

e um uma telinha do resultado =)
shutdown_manager

;)

  1. RamTao
    20, março, 2009 em 22:51 | #1

    Parabéns Bruno, mas você bem que podia ter posto o pacote tar.gz pra quem quiser pegar, e um screenshot pra ilustrar né ;)

  2. 21, março, 2009 em 00:15 | #2

    aaa, demoro, vou postar já xD

  1. Nenhum trackback ainda.