def recalc_text_edges(self): if (not hasattr(self, "layout")): return self.layout = Pango.Layout(self.pango_context) if self.textview != None: start, end = self.textview.get_buffer().get_bounds() text = self.textview.get_buffer().get_text(start, end, True) self.layout.set_text(text, len(text)) ##self.layout.set_attributes(self.attrlist) margin = utils.margin_required(utils.STYLE_NORMAL) text_w, text_h = self.layout.get_pixel_size() text_w += margin[0] + margin[2] text_h += margin[1] + margin[3] self.width = max(self.width, text_w) self.height = max(self.height, text_h) self.min_x = self.ul[0] + (self.width - text_w) / 2 + margin[0] self.min_y = self.ul[1] + (self.height - text_h) / 2 + margin[1] self.max_x = self.min_x + text_w self.max_y = self.min_y + text_h
def load (self, node, tar): tmp = node.getAttribute ("ul-coords") self.ul = utils.parse_coords (tmp) tmp = node.getAttribute ("lr-coords") self.lr = utils.parse_coords (tmp) self.filename = os.path.join('images', os.path.basename(node.getAttribute ("file"))) self.identity = int (node.getAttribute ("identity")) try: tmp = node.getAttribute ("background-color") self.background_color = Gdk.Color.parse(tmp) except ValueError: pass self.width = float(node.getAttribute ("image_width")) self.height = float(node.getAttribute ("image_height")) self.am_selected = node.hasAttribute ("current_root") self.am_primary = node.hasAttribute ("primary_root") for n in node.childNodes: if n.nodeName == "Extended": self.extended_buffer.load(n) else: print "Unknown: "+n.nodeName margin = utils.margin_required (utils.STYLE_NORMAL) self.pic_location = (self.ul[0]+margin[0], self.ul[1]+margin[1]) self.orig_pic = tar.read_pixbuf(self.filename) self.lr = (self.pic_location[0]+self.width+margin[2], self.pic_location[1]+self.height+margin[3]) self.recalc_edges()
def __init__ (self, coords, pango_context, thought_number, save, undo, loading, background_color, foreground_color, name="thought"): super (TextThought, self).__init__(save, name, undo, background_color, foreground_color) self.index = 0 self.end_index = 0 self.bytes = "" self.bindex = 0 self.text_location = coords self.text_element = save.createTextNode ("GOOBAH") self.element.appendChild (self.text_element) self.layout = None self.identity = thought_number self.pango_context = pango_context self.moving = False self.preedit = None self.attrlist = None self.attributes = pango.AttrList() self.current_attrs = [] if prefs.get_direction () == gtk.TEXT_DIR_LTR: self.pango_context.set_base_dir (pango.DIRECTION_LTR) else: self.pango_context.set_base_dir (pango.DIRECTION_RTL) self.b_f_i = self.bindex_from_index margin = utils.margin_required (utils.STYLE_NORMAL) if coords: self.ul = (coords[0]-margin[0], coords[1] - margin[1]) else: self.ul = None self.all_okay = True
def recalc_text_edges (self): if (not hasattr(self, "layout")): return self.layout = Pango.Layout(self.pango_context) if self.textview != None: start, end = self.textview.get_buffer().get_bounds() text = self.textview.get_buffer().get_text(start, end, True) self.layout.set_text(text, len(text)) ##self.layout.set_attributes(self.attrlist) margin = utils.margin_required(utils.STYLE_NORMAL) text_w, text_h = self.layout.get_pixel_size() text_w += margin[0] + margin[2] text_h += margin[1] + margin[3] self.width = max(self.width, text_w) self.height = max(self.height, text_h) self.min_x = self.ul[0] + (self.width - text_w)/2 + margin[0] self.min_y = self.ul[1] + (self.height - text_h)/2 + margin[1] self.max_x = self.min_x + text_w self.max_y = self.min_y + text_h
def load(self, node, tar): tmp = node.getAttribute("ul-coords") self.ul = utils.parse_coords(tmp) tmp = node.getAttribute("lr-coords") self.lr = utils.parse_coords(tmp) self.filename = os.path.join( 'images', os.path.basename(node.getAttribute("file"))) self.identity = int(node.getAttribute("identity")) try: tmp = node.getAttribute("background-color") self.background_color = Gdk.Color.parse(tmp) except ValueError: pass self.width = float(node.getAttribute("image_width")) self.height = float(node.getAttribute("image_height")) self.am_selected = node.hasAttribute("current_root") self.am_primary = node.hasAttribute("primary_root") for n in node.childNodes: if n.nodeName == "Extended": self.extended_buffer.load(n) else: print "Unknown: " + n.nodeName margin = utils.margin_required(utils.STYLE_NORMAL) self.pic_location = (self.ul[0] + margin[0], self.ul[1] + margin[1]) self.orig_pic = tar.read_pixbuf(self.filename) self.lr = (self.pic_location[0] + self.width + margin[2], self.pic_location[1] + self.height + margin[3]) self.recalc_edges()
def __init__(self, coords, pango_context, thought_number, save, undo, loading, background_color, foreground_color): global ndraw super(DrawingThought, self).__init__(save, "drawing_thought", undo, background_color, foreground_color) ndraw += 1 self.identity = thought_number self.want_move = False self.points = [] self.text = _("Drawing #%d" % ndraw) self.drawing = 0 if not loading: margin = utils.margin_required(utils.STYLE_NORMAL) self.ul = (coords[0] - margin[0], coords[1] - margin[1]) self.lr = (coords[0] + 100 + margin[2], coords[1] + 100 + margin[3]) self.min_x = coords[0] + 90 self.max_x = coords[0] + 15 self.min_y = coords[1] + 90 self.max_y = coords[1] + 15 self.width = 100 self.height = 100 self.all_okay = True
def recalc_text_edges(self): if (not hasattr(self, "layout")): return del self.layout show_text = self.attrs_changed() r, g, b = utils.selected_colors["fill"] r *= 65536 g *= 65536 b *= 65536 if self.index > self.end_index: bgsel = pango.AttrBackground(int(r), int(g), int(b), self.end_index, self.index) else: bgsel = pango.AttrBackground(int(r), int(g), int(b), self.index, self.end_index) self.attrlist.insert(bgsel) self.layout = pango.Layout(self.pango_context) self.layout.set_text(show_text) self.layout.set_attributes(self.attrlist) margin = utils.margin_required(utils.STYLE_NORMAL) text_w, text_h = self.layout.get_pixel_size() text_w += margin[0] + margin[2] text_h += margin[1] + margin[3] self.width = max(self.width, text_w) self.height = max(self.height, text_h) self.min_x = self.ul[0] + (self.width - text_w) / 2 + margin[0] self.min_y = self.ul[1] + (self.height - text_h) / 2 + margin[1] self.max_x = self.min_x + text_w self.max_y = self.min_y + text_h """
def recalc_edges (self, force=False, scale=GdkPixbuf.InterpType.HYPER): self.lr = (self.ul[0]+self.width, self.ul[1]+self.height) margin = utils.margin_required (utils.STYLE_NORMAL) self.pic_location = (self.ul[0]+margin[0], self.ul[1]+margin[1]) pic_w = max(MIN_SIZE, self.width - margin[0] - margin[2]) pic_h = max(MIN_SIZE, self.height - margin[1] - margin[3]) if self.orig_pic and (force or not self.pic or self.pic.get_width() != pic_w or self.pic.get_height() != pic_h): self.pic = self.orig_pic.scale_simple(int(pic_w), int(pic_h), scale)
def recalc_edges(self, force=False, scale=gtk.gdk.INTERP_HYPER): self.lr = (self.ul[0] + self.width, self.ul[1] + self.height) margin = utils.margin_required(utils.STYLE_NORMAL) self.pic_location = (self.ul[0] + margin[0], self.ul[1] + margin[1]) pic_w = max(MIN_SIZE, self.width - margin[0] - margin[2]) pic_h = max(MIN_SIZE, self.height - margin[1] - margin[3]) if self.orig_pic and (force or not self.pic or self.pic.get_width() != pic_w or self.pic.get_height() != pic_h): self.pic = self.orig_pic.scale_simple(pic_w, pic_h, scale)
def __init__ (self, coords, pango_context, thought_number, save, undo, loading, background_color, foreground_color, name="thought", fixed=None, parent=None): super(TextThought, self).__init__(coords, save, name, undo, background_color, foreground_color) self.index = 0 self.end_index = 0 self.bytes = "" self.bindex = 0 self.text_element = save.createTextNode ("GOOBAH") self.element.appendChild (self.text_element) self.layout = None self.identity = thought_number self.pango_context = pango_context self.moving = False self.preedit = None self.current_attrs = [] self.double_click = False self.orig_text = None self._parent = parent self._fixed = fixed self.textview = None self._textview_handler = None self._clipboard = None self.attributes = {"bold": False, "italic": False, "underline": False, "font": "Sans"} self.tag_bold = None self.tag_italic = None self.tag_underline = None if prefs.get_direction() == Gtk.TextDirection.LTR: self.pango_context.set_base_dir(Pango.Direction.LTR) else: self.pango_context.set_base_dir(Pango.Direction.RTL) self.b_f_i = self.bindex_from_index margin = utils.margin_required (utils.STYLE_NORMAL) if coords: self.ul = (coords[0]-margin[0], coords[1] - margin[1]) else: self.ul = None self.all_okay = True
def __init__ (self, coords, save, elem_type, undo, background_color, foreground_color): super (ResizableThought, self).__init__(save, elem_type, undo, background_color, foreground_color) self.resizing = RESIZE_NONE self.button_down = False self.orig_size = None if coords: margin = utils.margin_required (utils.STYLE_NORMAL) self.ul = (coords[0]-margin[0], coords[1]-margin[1]) self.lr = (coords[0]+margin[2], coords[1]+margin[3]) self.width = 1 self.height = 1 self.min_x = self.max_x = None self.min_y = self.max_y = None
def recalc_position (self): if self.layout is None: self.recalc_edges() (x,y) = self.layout.get_pixel_size () margin = utils.margin_required (utils.STYLE_NORMAL) if prefs.get_direction () == gtk.TEXT_DIR_LTR: self.text_location = (self.ul[0] + margin[0], self.ul[1] + margin[1]) self.lr = (x + self.text_location[0]+margin[2], y + self.text_location[1] + margin[3]) else: self.layout.set_alignment (pango.ALIGN_RIGHT) tmp1 = self.ul[1] if not self.lr: self.lr = (self.ul[0], self.ul[1] + y + margin[1] + margin[3]) self.text_location = (self.lr[0] - margin[2] - x, self.ul[1] + margin[1]) self.ul = (self.lr[0] - margin[0] - margin[2] - x, tmp1)
def __init__ (self, coords, pango_context, thought_number, save, undo, loading, background_color): super (ImageThought, self).__init__(save, "image_thought", undo, background_color, None) self.identity = thought_number margin = utils.margin_required (utils.STYLE_NORMAL) self.want_move = False if coords: self.ul = (coords[0]-margin[0], coords[1] - margin[1]) self.pic_location = coords else: self.ul = None self.button_press = False if not loading: self.all_okay = self.open_image () else: self.all_okay = True
def __init__(self, coords, save, elem_type, undo, background_color, foreground_color): super(ResizableThought, self).__init__(save, elem_type, undo, background_color, foreground_color) self.resizing = RESIZE_NONE self.button_down = False self.orig_size = None if coords: margin = utils.margin_required(utils.STYLE_NORMAL) self.ul = (coords[0] - margin[0], coords[1] - margin[1]) self.lr = (coords[0] + margin[2], coords[1] + margin[3]) self.width = 1 self.height = 1 self.min_x = self.max_x = None self.min_y = self.max_y = None
def load(self, node): tmp = node.getAttribute("ul-coords") self.ul = utils.parse_coords(tmp) tmp = node.getAttribute("lr-coords") self.lr = utils.parse_coords(tmp) self.filename = node.getAttribute("file") self.identity = int(node.getAttribute("identity")) try: tmp = node.getAttribute("background-color") self.background_color = gtk.gdk.color_parse(tmp) except ValueError: pass self.width = float(node.getAttribute("image_width")) self.height = float(node.getAttribute("image_height")) self.am_selected = node.hasAttribute("current_root") self.am_primary = node.hasAttribute("primary_root") for n in node.childNodes: if n.nodeName == "Extended": self.extended_buffer.load(n) else: print "Unknown: " + n.nodeName margin = utils.margin_required(utils.STYLE_NORMAL) self.pic_location = (self.ul[0] + margin[0], self.ul[1] + margin[1]) self.okay = self.open_image(self.filename) self.lr = (self.pic_location[0] + self.width + margin[2], self.pic_location[1] + self.height + margin[3]) if not self.okay: dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE, _("Error loading file")) dialog.format_secondary_text( _("%s could not be found. Associated thought will be empty." % self.filename)) dialog.run() dialog.hide() self.pic = None self.orig_pic = None else: self.pic = self.orig_pic.scale_simple(int(self.width), int(self.height), gtk.gdk.INTERP_HYPER) return
def __init__(self, coords, pango_context, thought_number, save, undo, loading, background_color): super(ImageThought, self).__init__(save, "image_thought", undo, background_color, None) self.identity = thought_number margin = utils.margin_required(utils.STYLE_NORMAL) self.want_move = False if coords: self.ul = (coords[0] - margin[0], coords[1] - margin[1]) self.pic_location = coords else: self.ul = None self.button_press = False if not loading: self.all_okay = self.open_image() else: self.all_okay = True
def __init__(self, coords, pango_context, thought_number, save, undo, loading, background_color, foreground_color, name="thought"): super(TextThought, self).__init__(coords, save, name, undo, background_color, foreground_color) self.index = 0 self.end_index = 0 self.bytes = "" self.bindex = 0 self.text_element = save.createTextNode("GOOBAH") self.element.appendChild(self.text_element) self.layout = None self.identity = thought_number self.pango_context = pango_context self.moving = False self.preedit = None self.attrlist = None self.attributes = pango.AttrList() self.current_attrs = [] self.double_click = False self.orig_text = None if prefs.get_direction() == gtk.TEXT_DIR_LTR: self.pango_context.set_base_dir(pango.DIRECTION_LTR) else: self.pango_context.set_base_dir(pango.DIRECTION_RTL) self.b_f_i = self.bindex_from_index margin = utils.margin_required(utils.STYLE_NORMAL) if coords: self.ul = (coords[0] - margin[0], coords[1] - margin[1]) else: self.ul = None self.all_okay = True
def recalc_position(self): if self.layout is None: self.recalc_edges() (x, y) = self.layout.get_pixel_size() margin = utils.margin_required(utils.STYLE_NORMAL) if prefs.get_direction() == gtk.TEXT_DIR_LTR: self.text_location = (self.ul[0] + margin[0], self.ul[1] + margin[1]) self.lr = (x + self.text_location[0] + margin[2], y + self.text_location[1] + margin[3]) else: self.layout.set_alignment(pango.ALIGN_RIGHT) tmp1 = self.ul[1] if not self.lr: self.lr = (self.ul[0], self.ul[1] + y + margin[1] + margin[3]) self.text_location = (self.lr[0] - margin[2] - x, self.ul[1] + margin[1]) self.ul = (self.lr[0] - margin[0] - margin[2] - x, tmp1)
def textview_rescale(self): tx = self._parent.translation[0] * self._parent.scale_fac ty = self._parent.translation[1] * self._parent.scale_fac margin = utils.margin_required(utils.STYLE_NORMAL) hadj = int(self._parent.hadj) vadj = int(self._parent.vadj) w = int((self.width - margin[0] - margin[2]) \ * self._parent.scale_fac) # w = max(w, margin[0] + margin[2]) h = int((self.height - margin[1] - margin[3]) \ * self._parent.scale_fac) # h = max(h, margin[1] + margin[3]) xo = Gdk.Screen.width() \ * (1. - self._parent.scale_fac) / 2. yo = Gdk.Screen.height() \ * (1. - self._parent.scale_fac) / 1.25 # FIXME x = (self.ul[0] + margin[0]) * self._parent.scale_fac y = (self.ul[1] + margin[1]) * self._parent.scale_fac return int(x + xo - hadj + tx), int(y + yo - vadj + ty), \ int(w), int(h)
def textview_rescale(self): tx = self._parent.translation[0] * self._parent.scale_fac ty = self._parent.translation[1] * self._parent.scale_fac margin = utils.margin_required (utils.STYLE_NORMAL) hadj = int(self._parent.hadj) vadj = int(self._parent.vadj) w = int((self.width - margin[0] - margin[2]) \ * self._parent.scale_fac) # w = max(w, margin[0] + margin[2]) h = int((self.height - margin[1] - margin[3]) \ * self._parent.scale_fac) # h = max(h, margin[1] + margin[3]) xo = gtk.gdk.screen_width() \ * (1. - self._parent.scale_fac) / 2. yo = gtk.gdk.screen_height() \ * (1. - self._parent.scale_fac) / 1.25 # FIXME x = (self.ul[0] + margin[0]) * self._parent.scale_fac y = (self.ul[1] + margin[1]) * self._parent.scale_fac return int(x + xo - hadj + tx), int(y + yo - vadj + ty), \ int(w), int(h)
def open_image(self, filename=None): # Present a dialog for the user to choose an image here if not filename: fil = gtk.FileFilter() fil.set_name("Images") fil.add_pixbuf_formats() dialog = gtk.FileChooserDialog (_("Choose image to insert"), None, gtk.FILE_CHOOSER_ACTION_OPEN, \ (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) dialog.add_filter(fil) res = dialog.run() dialog.hide() if res != gtk.RESPONSE_OK: return False else: fname = dialog.get_filename() else: fname = filename try: self.orig_pic = gtk.gdk.pixbuf_new_from_file(fname) except: try: # lets see if file was imported and is already extracted fname = os.path.join(utils.get_images_dir(), +os.path.basename(filename)) self.orig_pic = gtk.gdk.pixbuf_new_from_file(fname) except: return False self.filename = fname if not filename: self.width = self.orig_pic.get_width() self.height = self.orig_pic.get_height() margin = utils.margin_required(utils.STYLE_NORMAL) self.lr = (self.pic_location[0] + self.width + margin[2], self.pic_location[1] + self.height + margin[3]) self.pic = self.orig_pic self.text = fname[fname.rfind('/') + 1:fname.rfind('.')] return True
def __init__ (self, coords, pango_context, thought_number, save, undo, loading, background_color, foreground_color): global ndraw super (DrawingThought, self).__init__(save, "drawing_thought", undo, background_color, foreground_color) ndraw+=1 self.identity = thought_number self.want_move = False self.points = [] self.text = _("Drawing #%d" % ndraw) self.drawing = 0 if not loading: margin = utils.margin_required (utils.STYLE_NORMAL) self.ul = (coords[0]-margin[0], coords[1]-margin[1]) self.lr = (coords[0]+100+margin[2], coords[1]+100+margin[3]) self.min_x = coords[0]+90 self.max_x = coords[0]+15 self.min_y = coords[1]+90 self.max_y = coords[1]+15 self.width = 100 self.height = 100 self.all_okay = True
def open_image (self, filename = None): # Present a dialog for the user to choose an image here if not filename: fil = gtk.FileFilter () fil.set_name("Images") fil.add_pixbuf_formats () dialog = gtk.FileChooserDialog (_("Choose image to insert"), None, gtk.FILE_CHOOSER_ACTION_OPEN, \ (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) dialog.add_filter (fil) res = dialog.run () dialog.hide () if res != gtk.RESPONSE_OK: return False else: fname = dialog.get_filename() else: fname = filename try: self.orig_pic = gtk.gdk.pixbuf_new_from_file (fname) except: try: # lets see if file was imported and is already extracted fname = os.path.join (utils.get_images_dir (), + os.path.basename(filename)) self.orig_pic = gtk.gdk.pixbuf_new_from_file (fname) except: return False self.filename = fname if not filename: self.width = self.orig_pic.get_width () self.height = self.orig_pic.get_height () margin = utils.margin_required (utils.STYLE_NORMAL) self.lr = (self.pic_location[0]+self.width+margin[2], self.pic_location[1]+self.height+margin[3]) self.pic = self.orig_pic self.text = fname[fname.rfind('/')+1:fname.rfind('.')] return True
def load (self, node): tmp = node.getAttribute ("ul-coords") self.ul = utils.parse_coords (tmp) tmp = node.getAttribute ("lr-coords") self.lr = utils.parse_coords (tmp) self.filename = node.getAttribute ("file") self.identity = int (node.getAttribute ("identity")) try: tmp = node.getAttribute ("background-color") self.background_color = gtk.gdk.color_parse(tmp) except ValueError: pass self.width = float(node.getAttribute ("image_width")) self.height = float(node.getAttribute ("image_height")) self.am_selected = node.hasAttribute ("current_root") self.am_primary = node.hasAttribute ("primary_root") for n in node.childNodes: if n.nodeName == "Extended": self.extended_buffer.load(n) else: print "Unknown: "+n.nodeName margin = utils.margin_required (utils.STYLE_NORMAL) self.pic_location = (self.ul[0]+margin[0], self.ul[1]+margin[1]) self.okay = self.open_image (self.filename) self.lr = (self.pic_location[0]+self.width+margin[2], self.pic_location[1]+self.height+margin[3]) if not self.okay: dialog = gtk.MessageDialog (None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE, _("Error loading file")) dialog.format_secondary_text (_("%s could not be found. Associated thought will be empty."%self.filename)) dialog.run () dialog.hide () self.pic = None self.orig_pic = None else: self.pic = self.orig_pic.scale_simple (int(self.width), int(self.height), gtk.gdk.INTERP_HYPER) return
def recalc_text_edges (self): if (not hasattr(self, "layout")): return del self.layout show_text = self.attrs_changed () ''' r,g,b = utils.selected_colors["fill"] r *= 65536 g *= 65536 b *= 65536 if self.index > self.end_index: bgsel = pango.AttrBackground (int(r), int(g), int(b), self.end_index, self.index) else: bgsel = pango.AttrBackground (int(r), int(g), int(b), self.index, self.end_index) self.attrlist.insert (bgsel) ''' self.layout = pango.Layout (self.pango_context) self.layout.set_text (show_text) self.layout.set_attributes(self.attrlist) margin = utils.margin_required (utils.STYLE_NORMAL) text_w, text_h = self.layout.get_pixel_size() text_w += margin[0] + margin[2] text_h += margin[1] + margin[3] self.width = max(self.width, text_w) self.height = max(self.height, text_h) self.min_x = self.ul[0] + (self.width - text_w)/2 + margin[0] self.min_y = self.ul[1] + (self.height - text_h)/2 + margin[1] self.max_x = self.min_x + text_w self.max_y = self.min_y + text_h """
def recalc_edges (self): margin = utils.margin_required (utils.STYLE_NORMAL) self.pic_location = (self.ul[0]+margin[0], self.ul[1]+margin[1]) self.lr = (self.pic_location[0]+self.width+margin[2], self.pic_location[1]+self.height+margin[3])
def recalc_edges(self): margin = utils.margin_required(utils.STYLE_NORMAL) self.pic_location = (self.ul[0] + margin[0], self.ul[1] + margin[1]) self.lr = (self.pic_location[0] + self.width + margin[2], self.pic_location[1] + self.height + margin[3])
def _create_textview(self): # When the button is pressed inside a text thought, # create a textview (necessary for invoking the # on-screen keyboard) instead of processing the text # by grabbing keyboard events. if self.textview is None: self.textview = gtk.TextView() margin = utils.margin_required (utils.STYLE_NORMAL) x, y, w, h = self.textview_rescale() self.textview.set_size_request(w, h) self._fixed.put(self.textview, x, y) self.textview.set_justification(gtk.JUSTIFY_CENTER) font, size = None, None bold, italic, underline = False, False, False # Get current attributes and set them here it = self.attributes.get_iterator() while (1): r = it.range() for x in it.get_attrs(): if x.type == pango.ATTR_WEIGHT and x.value == pango.WEIGHT_BOLD: bold = True elif x.type == pango.ATTR_STYLE and x.value == pango.STYLE_ITALIC: italic = True elif x.type == pango.ATTR_UNDERLINE and x.value == pango.UNDERLINE_SINGLE: underline = True elif x.type == pango.ATTR_FONT_DESC: parts = x.desc.to_string ().split() font = string.join(parts[0:-2]) size = parts[-1] if not it.next(): break if font is None: font = 'Sans' if size is None: size = utils.default_font_size font_desc = pango.FontDescription(font) font_desc.set_size( int(int(size) * pango.SCALE * self._parent.scale_fac)) if bold: font_desc.set_weight(pango.WEIGHT_BOLD) if italic: font_desc.set_style(pango.STYLE_ITALIC) self.textview.modify_font(font_desc) r, g, b = utils.gtk_to_cairo_color(self.foreground_color) rgba = gtk.gdk.Color( int(65535 * r), int(65535 * g), int(65535 * b)) self.textview.modify_text(gtk.STATE_NORMAL, rgba) self.textview.get_buffer().set_text(self.text) self.textview.show() if self._textview_handler is None: self._textview_handler = self.textview.connect( 'focus-out-event', self._textview_focus_out_cb) self.copy_handler = self.textview.connect( 'copy-clipboard', self._textview_copy_cb) self.cut_handler = self.textview.connect( 'cut-clipboard', self._textview_cut_cb) self.paste_handler = self.textview.connect( 'paste-clipboard', self._textview_paste_cb) self.select_handler = self.textview.connect( 'select-all', self._textview_select_cb) self.textview.grab_focus() self._fixed.show()
def _create_textview(self): # When the button is pressed inside a text thought, # create a textview (necessary for invoking the # on-screen keyboard) instead of processing the text # by grabbing keyboard events. if self.textview is None: self.textview = Gtk.TextView() margin = utils.margin_required(utils.STYLE_NORMAL) x, y, w, h = self.textview_rescale() self.textview.set_size_request(w if w > 0 else 1, h if h > 0 else 1) self._fixed.put(self.textview, x, y) self.textview.set_justification(Gtk.Justification.CENTER) font, size = None, None bold, italic, underline = False, False, False # Get current attributes and set them here """ while (1): r = it.range() for x in it.get_attrs(): if x.type == Pango.Weight and x.value == Pango.Weight.BOLD: bold = True elif x.type == Pango.Style and x.value == Pango.Style.ITALIC: italic = True elif x.type == Pango.Underline and x.value == Pango.Underline.SINGLE: underline = True elif x.type == Pango.ATTR_FONT_DESC: parts = x.desc.to_string ().split() font = string.join(parts[0:-2]) size = parts[-1] if not it.next(): break if font is None: font = 'Sans' if size is None: size = utils.default_font_size font_desc = Pango.FontDescription(font) font_desc.set_size( int(int(size) * Pango.SCALE * self._parent.scale_fac)) if bold: font_desc.set_weight(Pango.Weight.BOLD) if italic: font_desc.set_style(Pango.Style.ITALIC) self.textview.modify_font(font_desc) """ r, g, b = utils.gtk_to_cairo_color(self.foreground_color) rgba = Gdk.Color(int(65535 * r), int(65535 * g), int(65535 * b)) self.textview.modify_text(Gtk.StateType.NORMAL, rgba) self.textview.get_buffer().set_text(self.text) self.textview.show() if self._textview_handler is None: self._textview_handler = self.textview.connect( 'focus-out-event', self._textview_focus_out_cb) self.copy_handler = self.textview.connect('copy-clipboard', self._textview_copy_cb) self.cut_handler = self.textview.connect('cut-clipboard', self._textview_cut_cb) self.paste_handler = self.textview.connect('paste-clipboard', self._textview_paste_cb) self.select_handler = self.textview.connect( 'select-all', self._textview_select_cb) self.textview.grab_focus() self._fixed.show()
def __init__(self, coords, pango_context, thought_number, save, undo, loading, background_color, foreground_color, name="thought", fixed=None, parent=None): super(TextThought, self).__init__(coords, save, name, undo, background_color, foreground_color) self.index = 0 self.end_index = 0 self.bytes = "" self.bindex = 0 self.text_element = save.createTextNode("GOOBAH") self.element.appendChild(self.text_element) self.layout = None self.identity = thought_number self.pango_context = pango_context self.moving = False self.preedit = None self.current_attrs = [] self.double_click = False self.orig_text = None self._parent = parent self._fixed = fixed self.textview = None self._textview_handler = None self._clipboard = None self.attributes = { "bold": False, "italic": False, "underline": False, "font": "Sans" } self.tag_bold = None self.tag_italic = None self.tag_underline = None if prefs.get_direction() == Gtk.TextDirection.LTR: self.pango_context.set_base_dir(Pango.Direction.LTR) else: self.pango_context.set_base_dir(Pango.Direction.RTL) self.b_f_i = self.bindex_from_index margin = utils.margin_required(utils.STYLE_NORMAL) if coords: self.ul = (coords[0] - margin[0], coords[1] - margin[1]) else: self.ul = None self.all_okay = True