diff options
Diffstat (limited to 'atoidejouerbeta/tools/ui.py')
-rw-r--r-- | atoidejouerbeta/tools/ui.py | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/atoidejouerbeta/tools/ui.py b/atoidejouerbeta/tools/ui.py new file mode 100644 index 0000000..c7dc89e --- /dev/null +++ b/atoidejouerbeta/tools/ui.py @@ -0,0 +1,111 @@ + +# python import +import logging, os + +# gtk import +import gtk + +# atoidejouerbeta import +from atoidejouerbeta.tools import image, storage + +# get application logger +logger = logging.getLogger('atoidejouerbeta') + + +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 |