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
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