| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | # Copyright (C) 2008 Adriano Monteiro Marques |
|---|
| 4 | # |
|---|
| 5 | # Author: Francesco Piccinno <stack.box@gmail.com> |
|---|
| 6 | # |
|---|
| 7 | # This program is free software; you can redistribute it and/or modify |
|---|
| 8 | # it under the terms of the GNU General Public License as published by |
|---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | # (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, |
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | # GNU General Public License for more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License |
|---|
| 18 | # along with this program; if not, write to the Free Software |
|---|
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | import os |
|---|
| 22 | import os.path |
|---|
| 23 | |
|---|
| 24 | import gtk |
|---|
| 25 | import gobject |
|---|
| 26 | from umitCore.Paths import Path |
|---|
| 27 | |
|---|
| 28 | icons = ( |
|---|
| 29 | 'protocol', |
|---|
| 30 | 'locked', |
|---|
| 31 | 'packet', |
|---|
| 32 | 'layer', |
|---|
| 33 | 'sniff' |
|---|
| 34 | ) |
|---|
| 35 | |
|---|
| 36 | def register_icons(): |
|---|
| 37 | factory = gtk.IconFactory() |
|---|
| 38 | pix_dir = Path.pixmaps_dir |
|---|
| 39 | |
|---|
| 40 | for icon_name in icons: |
|---|
| 41 | for type, size in (('small', 16), ('normal', 32)): |
|---|
| 42 | key = "%s_%s" % (icon_name, type) |
|---|
| 43 | |
|---|
| 44 | try: |
|---|
| 45 | pixbuf = gtk.gdk.pixbuf_new_from_file( |
|---|
| 46 | os.path.join(pix_dir, "%s-%d.png" % (icon_name, size)) |
|---|
| 47 | ) |
|---|
| 48 | factory.add(key, gtk.IconSet(pixbuf)) |
|---|
| 49 | |
|---|
| 50 | print "Registering", key |
|---|
| 51 | except gobject.GError: |
|---|
| 52 | continue |
|---|
| 53 | |
|---|
| 54 | factory.add_default() |
|---|
| 55 | |
|---|
| 56 | def get_pixbuf(stock_id): |
|---|
| 57 | name, size = stock_id.split("_") |
|---|
| 58 | print name, size |
|---|
| 59 | |
|---|
| 60 | if size == "small": |
|---|
| 61 | size = 16 |
|---|
| 62 | elif size == "normal": |
|---|
| 63 | size = 32 |
|---|
| 64 | else: |
|---|
| 65 | raise Exception("Could not determine the pixel size") |
|---|
| 66 | |
|---|
| 67 | return gtk.gdk.pixbuf_new_from_file(os.path.join(Path.pixmaps_dir, "%s-%d.png" % (name, size))) |
|---|