| 1 | # Copyright (C) 2008 Adriano Monteiro Marques. |
|---|
| 2 | # |
|---|
| 3 | # Author: Luis A. Bastiao Silva <luis.kop@gmail.com> |
|---|
| 4 | # |
|---|
| 5 | # This program is free software; you can redistribute it and/or modify |
|---|
| 6 | # it under the terms of the GNU General Public License as published by |
|---|
| 7 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | # (at your option) any later version. |
|---|
| 9 | # |
|---|
| 10 | # This program is distributed in the hope that it will be useful, |
|---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | # GNU General Public License for more details. |
|---|
| 14 | # |
|---|
| 15 | # You should have received a copy of the GNU General Public License |
|---|
| 16 | # along with this program; if not, write to the Free Software |
|---|
| 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | """ |
|---|
| 21 | Widget to make semilar tabs to firefox |
|---|
| 22 | |
|---|
| 23 | References: |
|---|
| 24 | http://www.moeraki.com/pygtktutorial/pygtk2reference/class-gtkiconview.html |
|---|
| 25 | |
|---|
| 26 | Idea of implementation: |
|---|
| 27 | |
|---|
| 28 | Create a Scroll Box with icons of tabs |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | """ |
|---|
| 32 | import gtk |
|---|
| 33 | |
|---|
| 34 | from higwidgets.higboxes import HIGHBox |
|---|
| 35 | import os.path |
|---|
| 36 | from umitCore.Paths import Path |
|---|
| 37 | # Develpment step |
|---|
| 38 | Path.set_umit_conf("umit") |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | class TabStruct: |
|---|
| 42 | def __init__(self): |
|---|
| 43 | """ Constructor """ |
|---|
| 44 | self.__list = [] |
|---|
| 45 | ### Interface - Public Functions ### |
|---|
| 46 | def add_item(self, name): |
|---|
| 47 | self.__list.append(name) |
|---|
| 48 | def del_item(self, name): |
|---|
| 49 | self.__list.append(name) |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | class TabsIcon(HIGHBox): |
|---|
| 55 | def __init__(self): |
|---|
| 56 | """ Constructor """ |
|---|
| 57 | HIGHBox.__init__(self) |
|---|
| 58 | self._box = HIGHBox() |
|---|
| 59 | self._icons_list = [] |
|---|
| 60 | self._tabstruct = TabStruct() |
|---|
| 61 | |
|---|
| 62 | self.__model = gtk.ListStore(str, gtk.gdk.Pixbuf) |
|---|
| 63 | self.__pixmap_d = Path.pixmaps_dir |
|---|
| 64 | |
|---|
| 65 | self.__icon = gtk.IconView() |
|---|
| 66 | self.__icon.set_model(self.__model) |
|---|
| 67 | self.__icon.set_text_column(0) |
|---|
| 68 | self.__icon.set_pixbuf_column(1) |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | self.__icon.set_orientation(gtk.ORIENTATION_VERTICAL) |
|---|
| 72 | self.__icon.connect('selection-changed', self.on_select, self.__model) |
|---|
| 73 | self.__icon.set_name("icon tabs") |
|---|
| 74 | gtk.rc_parse_string( |
|---|
| 75 | """ |
|---|
| 76 | style "iconview" |
|---|
| 77 | { |
|---|
| 78 | bg[PRELIGHT] = { 0.75, 3, 1 } |
|---|
| 79 | } |
|---|
| 80 | class 'GtkIconView' style 'iconview' |
|---|
| 81 | |
|---|
| 82 | """) |
|---|
| 83 | self.cellpb = gtk.CellRendererPixbuf() |
|---|
| 84 | self.cell = gtk.CellRendererText() |
|---|
| 85 | |
|---|
| 86 | self.pack_start(self.__icon, True, True) |
|---|
| 87 | |
|---|
| 88 | ### Interface - Public Functions ### |
|---|
| 89 | |
|---|
| 90 | def on_select(self,icon_view, model=None): |
|---|
| 91 | print "lol" |
|---|
| 92 | def add_item(self, name, image): |
|---|
| 93 | """ |
|---|
| 94 | @name: str with name of option |
|---|
| 95 | @image: str with name of image (e.g. sample.svg) |
|---|
| 96 | """ |
|---|
| 97 | pixmap_file = os.path.join(self.__pixmap_d, "Preferences" ,image) |
|---|
| 98 | pixbuf = gtk.gdk.pixbuf_new_from_file (pixmap_file) |
|---|
| 99 | |
|---|
| 100 | self.__model.append([name, pixbuf]) |
|---|
| 101 | |
|---|
| 102 | #self.__icon.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse("blue")) |
|---|
| 103 | |
|---|
| 104 | ### Private Functions #### |
|---|
| 105 | |
|---|
| 106 | def __create_icon_list(self): |
|---|
| 107 | |
|---|
| 108 | iconView = gtk.IconView () |
|---|
| 109 | self._icons_list.append(iconView) |
|---|
| 110 | |
|---|
| 111 | |
|---|