Ejemplo n.º 1
0
    def __init__(self, uid):
        gtk.Window.__init__(self, gtk.WINDOW_POPUP)

        # Init transparent colormap
        cm = self.get_screen().get_rgba_colormap()
        if cm != None:
            self.set_colormap(cm)

        screen = self.get_screen()
        mon_num = screen.get_monitor_at_point(0, 0)
        rect = screen.get_monitor_geometry(mon_num)

        self.screen_w = rect.width
        self.screen_h = rect.height

        screen.connect("size-changed", self.screen_changed)

        awn.utils_ensure_transparent_bg(self)

        # Connect to signals we need
        self.drag_dest_set(gtk.DEST_DEFAULT_DROP | gtk.DEST_DEFAULT_MOTION,
                           [("text/uri-list", 0, 0),
                            ("text/plain", 0, 1)], gtk.gdk.ACTION_COPY)

        self.connect("drag-data-received", self.no_target_drop)

        # We will use this themed icon to get the hi-res pixbufs
        self.icon_cache = awn.ThemedIcon()
        self.icon_cache.set_applet_info("dropper", uid)
        self.icon_cache.set_info_append("icon-1", "stock_internet")
        self.icon_cache.set_info_append("icon-2", "stock_open")

        self.init_components()
Ejemplo n.º 2
0
    def __init__(self):
        # Create GUI objects
        rgbaColormap = gtk.gdk.screen_get_default().get_rgba_colormap()
        if rgbaColormap != None:
            gtk.gdk.screen_get_default().set_default_colormap(rgbaColormap)
        self.window = gtk.Window()
        self.window.connect("delete-event", self.OnQuit)

        self.vbox = gtk.VBox(False)
        self.effectsHBox = gtk.HBox()

        self.icon = awn.ThemedIcon()
        self.icon.set_info_simple("Applet", "123", "awn-manager")

        self.icon.connect("button-release-event", self.OnButton)
        self.icon.connect("enter-notify-event", self.OnMouseOver)
        self.icon.connect("leave-notify-event", self.OnMouseOut)
        self.effectsHBox.pack_start(self.icon, True, True)

        self.vbox.pack_start(self.effectsHBox)

        self.table = gtk.Table(2, 3)
        self.quitButton = gtk.Button(stock='gtk-quit')
        self.quitButton.connect("clicked", self.OnQuit)
        self.textOvrly = gtk.ToggleButton("Text overlay")
        self.textOvrly.connect("toggled", self.TextOverlay)
        self.throOvrly = gtk.ToggleButton("Throbber overlay")
        self.throOvrly.connect("toggled", self.ThrobberOverlay)
        self.thioOvrly = gtk.ToggleButton("ThemedIcon overlay")
        self.thioOvrly.connect("toggled", self.ThemedIconOverlay)
        self.pixbOvrly = gtk.ToggleButton("Pixbuf overlay")
        self.pixbOvrly.connect("toggled", self.PixbufOverlay)
        self.pixfOvrly = gtk.ToggleButton("Pixbuf file overlay")
        self.pixfOvrly.connect("toggled", self.PixbufFileOverlay)

        self.table.attach(self.textOvrly, 0, 1, 0, 1)
        self.table.attach(self.throOvrly, 1, 2, 0, 1)
        self.table.attach(self.thioOvrly, 2, 3, 0, 1)

        self.table.attach(self.pixbOvrly, 0, 1, 1, 2)
        self.table.attach(self.pixfOvrly, 1, 2, 1, 2)

        self.table.attach(self.quitButton, 2, 3, 1, 2)

        self.vbox.pack_start(self.table, False)
        self.window.add(self.vbox)

        self.window.show_all()
Ejemplo n.º 3
0
def show_hide_tooltip(icon):
    tooltip = icon.get_tooltip()
    if (tooltip.flags() & gtk.VISIBLE) == 0:
        tooltip.update_position()
        tooltip.show()
        icon.set_state("icon1")
    else:
        tooltip.hide()
        icon.set_state("icon2")

    return True  # timer repeats


win = gtk.Window()
box = gtk.HBox()
icon = awn.ThemedIcon()
icon.set_info_simple("media-player", "12345", "media-player")
icon.set_tooltip_text("Icon with smart-behavior & toggle-on-click")

icon2 = awn.ThemedIcon()
icon2.set_info("media-player", "1234", ["icon1", "icon2"],
               ["gnome-main-menu", "media-player"])
icon2.set_state("icon2")
icon2.set_tooltip_text("Icon with manual tooltip control")
icon2.get_tooltip().set_position_hint("top", 35)
icon2.get_tooltip().props.smart_behavior = False
icon2.get_tooltip().props.toggle_on_click = False
gobject.timeout_add(1500, show_hide_tooltip, icon2)

icon3 = awn.ThemedIcon()
icon3.set_info_simple("media-player", "123456", "media-player")
Ejemplo n.º 4
0
  def __init__(self, uid, panel_id):
    #AWN Applet Configuration
    awn.Applet.__init__(self, 'file-browser-launcher', uid, panel_id)

    self.icon_box = awn.IconBox(self)
    self.add(self.icon_box)
    self.icon = awn.ThemedIcon()
    self.icon.set_tooltip_text(_("File Browser Launcher"))
    self.icon.set_size(self.get_size())
    self.dialog = awn.Dialog(self.icon, self)

    #AwnConfigClient instance
    self.client = awn.config_get_default_for_applet(self)

    #Get the default icon theme
    self.theme = gtk.icon_theme_get_default()
    self.icons[24] = {}
    try:
      self.icons[24]['folder'] = self.theme.load_icon('folder', 24, 0)
    except:
      self.icons[24]['folder'] = None

    #Docklet...
    self.mode = self.client.get_int(group, 'mode')
    self.client.notify_add(group, 'mode', self.update_mode)

    if self.mode == 2:
      self.docklet_visible = True
      self.update_docklet(False)

    else:
      self.icon_box.add(self.icon)

    #Set the icon
    self.icon.set_info_simple('file-browser-launcher', uid, 'folder')

    if gio:
      #This part (and other progress overlay code) adapted from
      #mhr3's 'Dropper' applet
      #Set the progress overlay
      self.timer_overlay = awn.OverlayProgressCircle()
      self.timer_overlay.props.active = False
      self.timer_overlay.props.apply_effects = False
      self.icon.add_overlay(self.timer_overlay)
    else:
      #Read fstab for mounting info
      #(It it assumed that fstab won't change after the applet is started)
      self.fstab2 = open('/etc/fstab', 'r')
      self.fstab = self.fstab2.read().split('\n')
      self.fstab2.close()

    #Check if nautilus-connect-server is installed
    if os.path.exists('/usr/bin/nautilus-connect-server') or os.path.exists \
      ('/usr/local/bin/nautilus-connect-server'):
      self.nautilus_connect_server = True
    else:
      self.nautilus_connect_server = False

    if os.path.exists('/usr/share/applications/nautilus-computer.desktop') or \
      os.path.exists('/usr/local/share/applications/nautilus-computer.desktop'):
      self.nautilus_computer = True
    else:
      self.nautilus_computer = False

    def trash_count_cb(*args):
      if self.show_trash:
        if gio:
          self.do_gio_places()
        else:
          self.add_places()

    self.trash = vfs.Trash.get_default()
    self.trash.connect('file-count-changed', trash_count_cb)

    #Make the dialog, will only be shown when approiate
    #Make all the things needed for a treeview for the homefolder, root dir, bookmarks, and mounted drives
    self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str, gtk.gdk.Pixbuf, str, int)

    #Renderers
    renderer0 = gtk.CellRendererPixbuf()
    renderer1 = gtk.CellRendererText()
    self.eject_render = gtk.CellRendererPixbuf()
    self.eject_render.set_property("mode", gtk.CELL_RENDERER_MODE_ACTIVATABLE)

    #Add renderers to column
    column = gtk.TreeViewColumn('0')
    column.pack_start(renderer0, False)
    column.add_attribute(renderer0, 'pixbuf', 0)
    column.pack_start(renderer1, True)
    column.add_attribute(renderer1, 'markup', 1)
    column.pack_start(self.eject_render, False)
    column.add_attribute(self.eject_render, 'pixbuf', 2)

    #TreeView
    self.treeview = gtk.TreeView(self.liststore)
    self.treeview.set_hover_selection(True)
    self.treeview.set_headers_visible(False)
    self.treeview.append_column(column)
    self.treeview.set_no_show_all(True)
    self.treeview.connect('button-press-event', self.treeview_clicked)

    self.vbox = gtk.VBox()
    self.vbox.pack_start(self.treeview)

    if gio:
      self.monitor = gio.volume_monitor_get()
      for signal in ('volume-added', 'volume-changed', 'volume-removed', 'mount-added',
        'mount-changed', 'mount-removed'):
        self.monitor.connect(signal, self.do_gio_places)

      for key in ('show_computer', 'show_home', 'show_filesystem', 'show_local', 'show_network',
        'show_connect', 'show_trash', 'show_bookmarks'):
        self.client.notify_add(group, key, self.do_gio_places)

      self.do_gio_places()

      #(From YAMA by Onox)
      #Monitor bookmarks file for changes
      bookmarks_file = os.path.expanduser("~/.gtk-bookmarks")

      #keep a reference to avoid getting it garbage collected
      self.__bookmarks_monitor = gio.File(bookmarks_file).monitor_file()

      def bookmarks_changed_cb(monitor, file, other_file, event):
        if event in (gio.FILE_MONITOR_EVENT_CHANGES_DONE_HINT, gio.FILE_MONITOR_EVENT_CREATED,
          gio.FILE_MONITOR_EVENT_DELETED):
          #Refresh menu to re-initialize the widget
          self.do_gio_places()

      self.__bookmarks_monitor.connect("changed", bookmarks_changed_cb)

    #Entry widget for displaying the path to open
    self.entry = gtk.Entry()
    self.entry.set_text(os.environ['HOME'])
    self.entry.connect('key-release-event', self.detect_enter)
    self.entry.show()

    #Open button to run the file browser
    self.enter = gtk.Button(stock=gtk.STOCK_OPEN)
    self.enter.connect('clicked', self.launch_fb)
    self.enter.show()

    #HBox to put the two together
    entry_hbox = gtk.HBox()
    entry_hbox.pack_start(self.entry)
    entry_hbox.pack_start(self.enter, False)

    #And add the HBox to the vbox and add the vbox to the dialog
    self.vbox.pack_end(entry_hbox)
    self.dialog.add(self.vbox)

    #Connect to signals
    self.icon.connect('clicked', self.icon_clicked)
    self.icon.connect('middle-clicked', self.icon_clicked)
    self.icon.connect('context-menu-popup', self.show_context_menu)
    self.connect('size-changed', self.size_changed)
    self.dialog.connect('focus-out-event', self.dialog_focus_out)
    self.theme.connect('changed', self.icon_theme_changed)

    if gio:
      #Allow the user to drag&drop a file/folder onto the applet. After
      #a short delay, show the dialog, and allow the file/folder to be dropped
      #on any place in the TreeView (other than root, Connect to Server..., and
      #maybe unmounted places). The move the file/folder and (if successful)
      #open the place in the file browser
      #The Applet icon - just open the dialog after a short delay
      self.icon.drag_dest_set(gtk.DEST_DEFAULT_DROP | gtk.DEST_DEFAULT_MOTION, \
        [("text/uri-list", 0, 0)], \
        gtk.gdk.ACTION_COPY)
      self.icon.connect('drag-data-received', self.applet_drag_data_received)
      self.icon.connect('drag-motion', self.applet_drag_motion)
      self.icon.connect('drag-leave', self.applet_drag_leave)

      #The TreeView - drop the file to move it to the folder
      self.treeview.drag_dest_set(gtk.DEST_DEFAULT_DROP | gtk.DEST_DEFAULT_MOTION, \
        [("text/uri-list", 0, 0)], \
        gtk.gdk.ACTION_MOVE)
      self.treeview.connect('drag-data-received', self.treeview_drag_data_received)
      self.treeview.connect('drag-motion', self.treeview_drag_motion)
      self.treeview.connect('drag-leave', self.treeview_drag_leave)

    elif self.mode == 2:
      self.add_places()
Ejemplo n.º 5
0
    def setup_docklet(self, window_id):
        def hover_cb(widget, event, effects):
            effects.start(awn.EFFECT_HOVER)

        def leave_cb(widget, event, effects):
            effects.stop(awn.EFFECT_HOVER)

        docklet = awn.Applet(self.applet.get_canonical_name(),
                             self.applet.props.uid, self.applet.props.panel_id)
        docklet.props.quit_on_delete = False

        docklet_orientation = docklet.get_pos_type()
        top_bottom = docklet_orientation in (gtk.POS_TOP, gtk.POS_BOTTOM)

        align = awn.Alignment(docklet, 1 / 3.0)
        align.props.offset_multiplier = 0
        if top_bottom:
            box = gtk.HBox()
        else:
            box = gtk.VBox()
        box.set_spacing(10)
        align.props.scale = 0.3
        align.add(box)

        for i in docklet_actions_label_icon:
            label, icon = docklet_actions_label_icon[i]

            if docklet_orientation == gtk.POS_RIGHT:
                label_align = gtk.Alignment(xalign=1.0)
                label_align.set_padding(0, 0, 0, docklet.get_offset())
            elif docklet_orientation == gtk.POS_BOTTOM:
                label_align = gtk.Alignment(yalign=1.0)
                label_align.set_padding(0, docklet.get_offset(), 0, 0)
            elif docklet_orientation == gtk.POS_TOP:
                label_align = gtk.Alignment()
                label_align.set_padding(docklet.get_offset(), 0, 0, 0)
            else:
                label_align = gtk.Alignment()
                label_align.set_padding(0, 0, docklet.get_offset(), 0)

            # Event box
            event_box = gtk.EventBox()
            event_box.set_visible_window(False)
            box.pack_start(event_box, True, False)

            # HBox/VBox (container)
            if top_bottom:
                container = gtk.HBox()
            else:
                container = gtk.VBox()
            container.set_spacing(5)
            event_box.add(container)

            # Label
            label_label = awn.Label(label)
            label_align.add(label_label)
            if top_bottom:
                label_label.set_size_request(-1, docklet.get_size())
            else:
                label_label.set_size_request(docklet.get_size(), -1)

            # Label left/right
            if docklet_orientation == gtk.POS_LEFT:
                container.pack_start(label_align, False, False)
                label_label.props.angle = 90

            # Icon
            themed_icon = awn.ThemedIcon()
            themed_icon.set_info_simple(self.applet.meta["short"],
                                        docklet.props.uid, icon)
            pixbuf = themed_icon.get_icon_at_size(
                (docklet.get_size() + docklet.props.max_size) / 2,
                themed_icon.get_state())
            image = awn.Image()
            image.set_from_pixbuf(pixbuf)
            if top_bottom:
                image.set_padding(0, docklet.get_offset())
            else:
                image.set_padding(docklet.get_offset(), 0)
            container.pack_start(image, False, False)

            effects = image.get_effects()
            event_box.connect("enter-notify-event", hover_cb, effects)
            event_box.connect("leave-notify-event", leave_cb, effects)
            event_box.connect("button-release-event", self.apply_action_cb, i,
                              docklet)

            # Label top/bottom
            if docklet_orientation != gtk.POS_LEFT:
                container.pack_start(label_align, False, False)
                if docklet_orientation == gtk.POS_RIGHT:
                    label_label.props.angle = 270

        docklet.add(align)
        gtk.Plug.__init__(docklet, long(window_id))
        docklet.show_all()