# This file is part of Recently Used Desklet # # Recently Used Desklet is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # Recently Used Desklet is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with Recently Used Desklet; if not, write to the Free # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307 USA from sensor.Sensor import Sensor from RfileSet import RfileSet from Animator import Animator from utils.datatypes import * from utils import i18n import gnome import os import commands class Recent(Sensor): # panel orientation values TOP = "top" BOTTOM = "bottom" LEFT = "left" RIGHT = "right" def __init__(self, *args): global _; _ = i18n.Translator("rubar-sensor") # the set of icons self.__rfile_set = None # the animator self.__animator = Animator() # the index of the currently selected icon or -1 self.__current_index = -1 # the index of the currently hovered icon or -1 # this is for the text showing up self.__current_icon_index = -1 # the current orientation of the panel self.__orientation = self.BOTTOM # the jump align for icons self.__jump_align = -1 # the scaling of the panel self.__panel_scaling = 0.5 # the size of the panel self.__panel_size = 0 # the number of items in the panel self.__item_count = 6 Sensor.__init__(self) self._set_config_type("orientation", TYPE_STRING, self.__orientation) self._set_config_type("animation", TYPE_BOOL, 1) self._set_config_type("item-count", TYPE_INT, self.__item_count) self._set_config_type("panel-scaling", TYPE_INT, 100) self._add_timer(0, self.__initialize) # # initialize the panel # def __initialize(self): self.__rfile_set = RfileSet() self.__rfile_set.set_visualizer(self.__on_visualize) self._add_timer(0, self.__watch_config) self._add_timer(0, self.__rfile_set.load_files) self._add_timer(50, self.__animator.animation, self.__on_animate) # # Visualizes the panel. # def __on_visualize(self, src): self.__set_orientation(self.__get_orientation()) self.__setup_panel() # # Visualizes animations. # def __on_animate(self, zoom, align, jump): output = self._new_output() for i in xrange(len(zoom)): try: if (i == self.__current_index): output.set("saturation[%(i)d]" % vars(), 4.0) else: output.set("saturation[%(i)d]" % vars(), 1.0) except StandardError, e: print e output.set("icon-scale[%(i)d]" % vars(), zoom[i] * self.__panel_scaling) if (self.__orientation in [self.TOP, self.BOTTOM]): output.set("icon-align-x[%(i)d]" % vars(), 0.5 + align[i]) output.set("icon-align-y[%(i)d]" % vars(), abs(self.__jump_align + jump[i])) elif (self.__orientation in [self.LEFT, self.RIGHT]): output.set("icon-align-y[%(i)d]" % vars(), 0.5 + align[i]) output.set("icon-align-x[%(i)d]" % vars(), abs(self.__jump_align + jump[i])) #end for self._send_output(output) # # Watches the configuration for changes. # TODO: watching service should be provided in the Sensor API # def __watch_config(self): orientation = self._get_config("orientation") scaling = self._get_config("panel-scaling") / 100.0 if (orientation != self.__get_orientation() or scaling != self.__panel_scaling): self.__panel_scaling = scaling self.__set_orientation(orientation) self.__setup_panel() count = self._get_config("item-count") if ( count != self.__item_count ): self.__item_count = count self.__set_orientation(orientation) self.__setup_panel() self._add_timer(250, self.__watch_config) # # Sets up the panel. # def __setup_panel(self): length = self.__get_length() output = self._new_output() for i in xrange(length): rfile = self.__rfile_set.get_rfile(i) output.set("icon-uri[%(i)d]"%vars(),rfile.get_icon().get_pixmap()) #output.set("icon-file-name[%(i)d]" % vars(), rfile.get_file_name()) #output.set("icon-scale[%(i)d]" % vars(), self.__panel_scaling) if (self.__orientation in [self.TOP, self.BOTTOM]): output.set("icon-align-x[%(i)d]" % vars(), 0.5) output.set("icon-align-y[%(i)d]" % vars(), abs(self.__jump_align)) elif (self.__orientation in [self.LEFT, self.RIGHT]): output.set("icon-align-y[%(i)d]" % vars(), 0.5) output.set("icon-align-x[%(i)d]" % vars(), abs(self.__jump_align)) #end for output.set("length", length) self._send_output(output) self.__animator.set_size(length) # # Sets the orientation of the panel. # def __set_orientation(self, orientation): length = self.__get_length() distance = int(56 * self.__panel_scaling) size = max(32, length * 56) output = self._new_output() if (orientation == self.TOP): layout = "horizontal, %(distance)d" % vars() panel = (36, 0, size, 50) align_width = 120 align_height = 80 self.__jump_align = 0 elif (orientation == self.BOTTOM): layout = "horizontal, %(distance)d" % vars() panel = (36, 30, size, 50) align_width = 120 align_height = 80 self.__jump_align = -1 elif (orientation == self.LEFT): layout = "vertical, %(distance)d" % vars() panel = (0, 36, 50, size) align_width = 80 align_height = 120 self.__jump_align = 0 elif (orientation == self.RIGHT): layout = "vertical, %(distance)d" % vars() panel = (32, 36, 50, size) align_width = 80 align_height = 120 self.__jump_align = -1 scale = self.__panel_scaling output.set("layout", layout) output.set("panel-x", panel[0] * scale) output.set("panel-y", panel[1] * scale) output.set("panel-width", panel[2] * scale - 8) output.set("panel-height", panel[3] * scale - 8) for i in xrange(self.__get_length()): output.set("align-width[" + str(i) + "]", align_width * scale) output.set("align-height[" + str(i) + "]", align_height * scale) self._send_output(output) self.__orientation = orientation self.__panel_size = (size + max(panel[0], panel[1])) * scale # print "PANEL_SIZE: " + str(self.__panel_size) # # Returns the orientation of the panel. # def __get_orientation(self): return self.__orientation # # Returns the length of the bar with respect to the users # configuration options # def __get_length(self): tlength = self.__rfile_set.get_length() length = tlength plength = self.__item_count if ( plength > tlength ): length = tlength else: length = plength return length # # Reacts on user actions. # def call_action(self, action, path, args = []): # mouse motion over panel if (action == "motion"): x = int(args[0]) y = int(args[1]) orientation = self.__get_orientation() if (orientation in [self.TOP, self.BOTTOM]): value = x else: value = y #value -= 1.0 length = self.__get_length() pos = (value / float(self.__panel_size)) * length index = min(int(pos), self.__get_length() - 1) self.__current_index = index if (self._get_config("animation")): self.__animator.hilight(pos - 0.5) try: self.__current_icon_index = index output = self._new_output() rfile = self.__rfile_set.get_rfile(index) output.set("icon-file-name[%(index)d]" % vars(), rfile.get_file_name()) self._send_output(output) except StandardError, e: print e # enter icon # FIXME this is broken too! # if (action == "enter"): # x = int(args[0]) # y = int(args[1]) # orientation = self.__get_orientation() # if (orientation in [self.TOP, self.BOTTOM]): # value = x # else: # value = y # length = self.__get_length() # pos = (value / float(self.__panel_size)) * length # index = min(int(pos), self.__get_length() - 1) # try: # self.__current_icon_index = index # output = self._new_output() # rfile = self.__rfile_set.get_rfile(index) # output.set("icon-file-name[%(index)d]" % vars(), # rfile.get_file_name()) # self._send_output(output) # except StandardError, e: # pass # leave an icon # FIXME this is broken elif (action == "leave"): try: index = self.__current_icon_index self.__current_icon_index = -1 output = self._new_output() output.set("icon-file-name[%(index)d]" % vars(),"") self._send_output(output) except StandardError, e: pass # leave entire panel and clean everything up elif (action == "exit"): self.__current_index = -1 self.__animator.unhilight() # start application elif (action == "launch"): try: index = int(path[-1]) cmd = self.__rfile_set.get_rfile(index).get_uri() self.__animator.unhilight() gnome.url_show( cmd ) if (self._get_config("animation")): self.__animator.jump(index) # # protect against clicking in between files # except StandardError, e: pass # open menu elif (action == "menu"): menu = [] self._open_menu(menu) # # Returns the configuration GUI. # def get_configurator(self): configurator = self._new_configurator() configurator.set_name(_("Panel")) configurator.add_title(_("Appearance")) configurator.add_option(_("Orientation:"), "orientation", _("The orientation of the panel"), [(_("top"), self.TOP), (_("bottom"), self.BOTTOM), (_("left"), self.LEFT), (_("right"), self.RIGHT)] ) configurator.add_spin(_("Number of Items:"), "item-count", _("The max number of items in the panel"), 1, 20) configurator.add_spin(_("Panel Scaling:"), "panel-scaling", _("The size of the panel percent"), 10, 500) configurator.add_checkbox(_("Show animations"), "animation", _("Toggles eye candy animations on or off")) return configurator def new_sensor(args): return apply(Recent, args)