Exemple #1
0
 def make_listrow(self, contents=None, *args):
     list_row = RoundBox()
     list_row.props.border = 0  # properties not being set properly by constructor
     list_row.props.padding = theme.DEFAULT_PADDING
     #list_row.props.padding_right=0
     list_row.props.background_color = self.color_listrow
     if contents is not None:
         list_row.append(contents, *args)
     return list_row
Exemple #2
0
 def make_listrow(self, contents=None, *args):
     list_row = RoundBox()
     list_row.props.border = 0  # properties not being set properly by constructor
     list_row.props.padding = theme.DEFAULT_PADDING
     # list_row.props.padding_right=0
     list_row.props.background_color = self.color_listrow
     if contents is not None:
         list_row.append(contents, *args)
     return list_row
Exemple #3
0
    def __textview(self,
                   text,
                   width=300,
                   height=-1,
                   editable=True,
                   multiline=False):
        textview = gtk.TextView()
        textview.get_buffer().set_text(text)

        # control props
        textview.set_wrap_mode(gtk.WRAP_WORD)
        textview.modify_base(gtk.STATE_NORMAL,
                             theme.COLOR_TEXTBOX.get_gdk_color())
        textview.set_editable(editable)
        textview.set_cursor_visible(editable)
        if height == -1:
            context = textview.create_pango_context()
            layout = pango.Layout(context)
            layout.set_text(text[:text.find('\n')])
            (w, h) = layout.get_pixel_size()
            height = h  #+ theme.BORDER_WIDTH_CONTROL / 2 # fudge factor - on the XO-1 hardware all known solutions evaporate
        textview.set_size_request(width, height)
        textview.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 0)
        textview.set_border_window_size(gtk.TEXT_WINDOW_RIGHT, 0)
        textview.set_border_window_size(gtk.TEXT_WINDOW_TOP, 0)
        textview.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 0)
        textview.show()

        if editable:  # because rounded corners are well... pretty
            border_box = RoundBox()
            border_box.control = textview
            border_box.props.padding = 2
            border_box.props.spacing = 0
            border_box.props.border = theme.BORDER_WIDTH_CONTROL / 2
            border_box.props.border_color = theme.COLOR_DARK_GREEN.get_int()
            border_box.props.background_color = theme.COLOR_TEXTBOX.get_int()
            border_box.props.xalign = hippo.ALIGNMENT_START
            #border_box.props.box_width = width
            #border_box.props.box_height = height

            # TODO - File bug: RoundBox seriously messes with TextView's
            #                  (and other things) width !!
            deglitch_box = hippo.CanvasBox()
            deglitch_box.append(hippo.CanvasWidget(widget=textview))
            border_box.append(deglitch_box)
            return border_box

        no_edit_box = hippo.CanvasWidget(widget=textview)
        no_edit_box.control = textview
        return no_edit_box
Exemple #4
0
    def __textview(self, text, width=300, height=-1, editable=True, multiline=False):
        textview = gtk.TextView()
        textview.get_buffer().set_text(text)

        # control props
        textview.set_wrap_mode(gtk.WRAP_WORD)
        textview.modify_base(gtk.STATE_NORMAL, theme.COLOR_TEXTBOX.get_gdk_color())
        textview.set_editable(editable)
        textview.set_cursor_visible(editable)
        if height == -1:
            context = textview.create_pango_context()
            layout = pango.Layout(context)
            layout.set_text(text[: text.find("\n")])
            (w, h) = layout.get_pixel_size()
            height = (
                h
            )  # + theme.BORDER_WIDTH_CONTROL / 2 # fudge factor - on the XO-1 hardware all known solutions evaporate
        textview.set_size_request(width, height)
        textview.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 0)
        textview.set_border_window_size(gtk.TEXT_WINDOW_RIGHT, 0)
        textview.set_border_window_size(gtk.TEXT_WINDOW_TOP, 0)
        textview.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 0)
        textview.show()

        if editable:  # because rounded corners are well... pretty
            border_box = RoundBox()
            border_box.control = textview
            border_box.props.padding = 2
            border_box.props.spacing = 0
            border_box.props.border = theme.BORDER_WIDTH_CONTROL / 2
            border_box.props.border_color = theme.COLOR_DARK_GREEN.get_int()
            border_box.props.background_color = theme.COLOR_TEXTBOX.get_int()
            border_box.props.xalign = hippo.ALIGNMENT_START
            # border_box.props.box_width = width
            # border_box.props.box_height = height

            # TODO - File bug: RoundBox seriously messes with TextView's
            #                  (and other things) width !!
            deglitch_box = hippo.CanvasBox()
            deglitch_box.append(hippo.CanvasWidget(widget=textview))
            border_box.append(deglitch_box)
            return border_box

        no_edit_box = hippo.CanvasWidget(widget=textview)
        no_edit_box.control = textview
        return no_edit_box
Exemple #5
0
    def make_audiobox(self, obj, property, width):

        image_file = os.path.join(Globals.pwd, theme.AUDIO_CHOOSE)
        if not os.path.exists(image_file):
            logging.debug("cannot find %s" % image_file)
            return hippo.CanvasBox()

        surface = cairo.ImageSurface.create_from_png(image_file)
        preview_sound = hippo.CanvasImage(image=surface, xalign=hippo.ALIGNMENT_START, yalign=hippo.ALIGNMENT_CENTER)
        preview_sound.connect("button-press-event", self.__do_clicked_preview_sound, obj, property)

        if hasattr(obj, property) and getattr(obj, property) != None:
            sound_name = getattr(obj, property)
        else:
            sound_name = _("Click to choose a sound")

        choose_sound = hippo.CanvasText(text=sound_name, xalign=hippo.ALIGNMENT_START)
        choose_sound.connect("button-press-event", self.__do_clicked_choose_sound, obj, property)

        sound_box = RoundBox()
        sound_box.props.padding = 2
        sound_box.props.spacing = 10
        sound_box.props.box_width = width
        sound_box.props.border = theme.BORDER_WIDTH_CONTROL / 2
        sound_box.props.border_color = theme.COLOR_DARK_GREEN.get_int()
        sound_box.props.background_color = theme.COLOR_WHITE.get_int()
        sound_box.props.orientation = hippo.ORIENTATION_HORIZONTAL
        sound_box.props.xalign = hippo.ALIGNMENT_START
        sound_box.set_clickable(True)
        sound_box.append(preview_sound)
        sound_box.append(choose_sound)

        deglitch_box = hippo.CanvasBox(xalign=hippo.ALIGNMENT_START, box_width=width)
        deglitch_box.append(sound_box)
        return deglitch_box
Exemple #6
0
    def make_audiobox(self, obj, property, width):

        image_file = os.path.join(Globals.pwd, theme.AUDIO_CHOOSE)
        if not os.path.exists(image_file):
            logging.debug('cannot find %s' % image_file)
            return hippo.CanvasBox()

        surface = cairo.ImageSurface.create_from_png(image_file)
        preview_sound = hippo.CanvasImage(image=surface,
                                          xalign=hippo.ALIGNMENT_START,
                                          yalign=hippo.ALIGNMENT_CENTER)
        preview_sound.connect('button-press-event',
                              self.__do_clicked_preview_sound, obj, property)

        if hasattr(obj, property) and getattr(obj, property) != None:
            sound_name = getattr(obj, property)
        else:
            sound_name = _('Click to choose a sound')

        choose_sound = hippo.CanvasText(text=sound_name,
                                        xalign=hippo.ALIGNMENT_START)
        choose_sound.connect('button-press-event',
                             self.__do_clicked_choose_sound, obj, property)

        sound_box = RoundBox()
        sound_box.props.padding = 2
        sound_box.props.spacing = 10
        sound_box.props.box_width = width
        sound_box.props.border = theme.BORDER_WIDTH_CONTROL / 2
        sound_box.props.border_color = theme.COLOR_DARK_GREEN.get_int()
        sound_box.props.background_color = theme.COLOR_WHITE.get_int()
        sound_box.props.orientation = hippo.ORIENTATION_HORIZONTAL
        sound_box.props.xalign = hippo.ALIGNMENT_START
        sound_box.set_clickable(True)
        sound_box.append(preview_sound)
        sound_box.append(choose_sound)

        deglitch_box = hippo.CanvasBox(xalign=hippo.ALIGNMENT_START,
                                       box_width=width)
        deglitch_box.append(sound_box)
        return deglitch_box
Exemple #7
0
class Page(hippo.CanvasBox):
    def __init__(self, **kwargs):
        hippo.CanvasBox.__init__(self, **kwargs)

        self.__alternate_color_listrows = False
        self.__color_listrow = theme.COLOR_LIST_ROW_ALT.get_int()

    def append(self, item, *args, **kwargs):
        hippo.CanvasBox.append(self, item, *args, **kwargs)

    @property
    def color_listrow(self):
        if not self.__alternate_color_listrows:
            return theme.COLOR_LIST_ROW.get_int()
        if self.__color_listrow == theme.COLOR_LIST_ROW_ALT.get_int():
            self.__color_listrow = theme.COLOR_LIST_ROW.get_int()
        else:
            self.__color_listrow = theme.COLOR_LIST_ROW_ALT.get_int()
        return self.__color_listrow

    def make_listrow(self, contents=None, *args):
        list_row = RoundBox()
        list_row.props.border = 0  # properties not being set properly by constructor
        list_row.props.padding = theme.DEFAULT_PADDING
        #list_row.props.padding_right=0
        list_row.props.background_color = self.color_listrow
        if contents is not None:
            list_row.append(contents, *args)
        return list_row

    def make_audiobox(self, obj, property, width):

        image_file = os.path.join(Globals.pwd, theme.AUDIO_CHOOSE)
        if not os.path.exists(image_file):
            logging.debug('cannot find %s' % image_file)
            return hippo.CanvasBox()

        surface = cairo.ImageSurface.create_from_png(image_file)
        preview_sound = hippo.CanvasImage(image=surface,
                                          xalign=hippo.ALIGNMENT_START,
                                          yalign=hippo.ALIGNMENT_CENTER)
        preview_sound.connect('button-press-event',
                              self.__do_clicked_preview_sound, obj, property)

        if hasattr(obj, property) and getattr(obj, property) != None:
            sound_name = getattr(obj, property)
        else:
            sound_name = _('Click to choose a sound')

        choose_sound = hippo.CanvasText(text=sound_name,
                                        xalign=hippo.ALIGNMENT_START)
        choose_sound.connect('button-press-event',
                             self.__do_clicked_choose_sound, obj, property)

        sound_box = RoundBox()
        sound_box.props.padding = 2
        sound_box.props.spacing = 10
        sound_box.props.box_width = width
        sound_box.props.border = theme.BORDER_WIDTH_CONTROL / 2
        sound_box.props.border_color = theme.COLOR_DARK_GREEN.get_int()
        sound_box.props.background_color = theme.COLOR_WHITE.get_int()
        sound_box.props.orientation = hippo.ORIENTATION_HORIZONTAL
        sound_box.props.xalign = hippo.ALIGNMENT_START
        sound_box.set_clickable(True)
        sound_box.append(preview_sound)
        sound_box.append(choose_sound)

        deglitch_box = hippo.CanvasBox(xalign=hippo.ALIGNMENT_START,
                                       box_width=width)
        deglitch_box.append(sound_box)
        return deglitch_box

    def make_imagebox(self,
                      obj,
                      property=None,
                      width=-1,
                      height=-1,
                      editable=True,
                      padding=0):
        image = self.__get_property_value(obj, property)
        if image == '' or image == None:
            image = theme.IMAGE_CHOOSE
        file_name = os.path.join(Globals.pwd, image)
        logging.debug('make_imagebox(%r)' % file_name)

        # TODO -> handle landscape/portrait properly

        # load image - could be cleaner on the whole... :)
        try:
            if hasattr(obj, 'image_blob') and getattr(
                    obj, 'image_blob') is not None:
                image_file = StringIO.StringIO(obj.image_blob)
                surface = cairo.ImageSurface.create_from_png(image_file)
            else:
                surface = cairo.ImageSurface.create_from_png(file_name)
        except Exception, e:
            logging.error('Error while loading image: %r' % e)

        # set border
        if editable:
            border_width = 0
        else:
            border_width = theme.BORDER_WIDTH_IMAGE

        # the image itself
        cover_image = hippo.CanvasImage(
            image=surface,
            border=border_width,
            border_color=theme.COLOR_BLACK.get_int(),
            xalign=hippo.ALIGNMENT_CENTER,
            yalign=hippo.ALIGNMENT_CENTER,
            scale_width=width,
            scale_height=height)
        if editable:
            cover_image.set_clickable(True)
            cover_image.connect('button-press-event', self.__do_clicked_image,
                                obj, 'image_blob')
            image_box = RoundBox()
            image_box.props.padding = 0
            image_box.props.spacing = 0
            image_box.props.border = theme.BORDER_WIDTH_CONTROL
            image_box.props.border_color = theme.COLOR_DARK_GREEN.get_int()
            image_box.append(cover_image)
        else:
            image_box = cover_image

        # Grrr... RoundedBoxes and CanvasImages expand their width to their parent
        # unless they're in a CanvasBox
        deglitch_box = hippo.CanvasBox(xalign=hippo.ALIGNMENT_CENTER,
                                       padding=padding)
        deglitch_box.append(image_box)
        return deglitch_box