Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/atoidejouer/tools/ui.py
blob: 0b0fa76335da4745e0375a0778b26a52f423d2df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

# python import
import logging, os

# gtk import
import gtk

# atoidejouer import
from atoidejouer.tools import image, storage

# get application logger
logger = logging.getLogger('atoidejouer')


def get_color(red, green, blue):
    # ..
    red = int(red * 65535)
    green = int(green * 65535)
    blue = int(blue * 65535)
    # ..
    return gtk.gdk.Color(red, green, blue)


def get_button(label=None, stock_id=None, img_name=None, width=-1,
        padding=None, img_size=None):
    # little check:
    if label is None and stock_id is None and img_name is None:
        return None
    else:
        pass
    # init container
    _box = gtk.HBox(homogeneous=False, spacing=1)
    _box.show()
    # manage image width
    if width == -1:
        _expand = True
    else:
        _expand = False
    # use stock?
    if stock_id is None and img_name is None:
        pass
    else:
        # image stuff
        _img = gtk.Image()
        _img.show()
        # get img path
        _i_path = storage.get_icon_path(stock_id) if img_name is None\
                else storage.get_image_path(img_name)
        # set image
        if img_size is None:
            _img.set_from_file(_i_path)
        else:
            _img.set_from_pixbuf(image.get_pixbuf(_i_path, *img_size))
        # manage padding
        if padding is None:
            pass
        else:
            _img.set_padding(*padding)
        # do add
        _box.pack_start(_img, expand=_expand, fill=True)
    # use label?
    if label is None:
        pass
    else:
        # create a label for the button
        _label = gtk.Label(label)
        _label.show()
        # do add
        _box.pack_start(_label, expand=_expand, fill=True)
    # make it button
    _button = gtk.Button()
    _button.show()
    _button.add(_box)
    # manage image width
    if width == -1:
        pass
    else:
        _button.set_size_request(width, -1)
    # return the button
    return _button


def get_entry(label=None, value=""):
    # init hbox for the row
    _entry_box = gtk.HBox(homogeneous=False, spacing=4)
    # do show
    _entry_box.show()
    # use label?
    if label is None:
        pass
    else:
        # init label
        _label = gtk.Label(label)
        _label.set_size_request(12, -1)
        # do show
        _label.show()
        # add it to the box
        _entry_box.pack_start(_label, expand=False, fill=True)
    # init entry
    _entry = gtk.Entry()
    # do show
    _entry.show()
    # set value - should be a string
    _entry.set_text(str(value))
    _entry.set_alignment(1)
    _entry.set_property('editable', False)
    _entry.set_size_request(64, -1)
    # add it to the box
    _entry_box.pack_start(_entry, expand=True, fill=True)
    # return the box
    return _entry_box