def process_key_press(self, event, mode): modifiers = gtk.accelerator_get_default_mod_mask() shift = event.state & modifiers == gtk.gdk.SHIFT_MASK handled = True clear_attrs = True if not self.editing: return False if (event.state & modifiers) & gtk.gdk.CONTROL_MASK: if event.keyval == gtk.keysyms.a: self.index = self.bindex = 0 self.end_index = len(self.text) elif event.keyval == gtk.keysyms.Escape: self.leave() elif event.keyval == gtk.keysyms.Left: if prefs.get_direction() == gtk.TEXT_DIR_LTR: self.move_index_back(shift) else: self.move_index_forward(shift) elif event.keyval == gtk.keysyms.Right: if prefs.get_direction() == gtk.TEXT_DIR_RTL: self.move_index_back(shift) else: self.move_index_forward(shift) elif event.keyval == gtk.keysyms.Up: self.move_index_up(shift) elif event.keyval == gtk.keysyms.Down: self.move_index_down(shift) elif event.keyval == gtk.keysyms.Home: if prefs.get_direction() == gtk.TEXT_DIR_LTR: self.move_index_horizontal(shift, True) # move home else: self.move_index_horizontal(shift) # move end self.move_index_horizontal(shift, True) # move home elif event.keyval == gtk.keysyms.End: self.move_index_horizontal(shift) # move elif event.keyval == gtk.keysyms.BackSpace and self.editing: self.backspace_char() elif event.keyval == gtk.keysyms.Delete and self.editing: self.delete_char() elif len(event.string) != 0: self.add_text(event.string) clear_attrs = False else: handled = False if clear_attrs: del self.current_attrs self.current_attrs = [] self.recalc_edges() self.selection_changed() self.emit("title_changed", self.text) self.bindex = self.bindex_from_index(self.index) self.emit("update_view") return handled
def process_key_press (self, event, mode): modifiers = gtk.accelerator_get_default_mod_mask () shift = event.state & modifiers == gtk.gdk.SHIFT_MASK handled = True clear_attrs = True if not self.editing: return False if (event.state & modifiers) & gtk.gdk.CONTROL_MASK: if event.keyval == gtk.keysyms.a: self.index = self.bindex = 0 self.end_index = len (self.text) elif event.keyval == gtk.keysyms.Escape: self.emit ("finish_editing") elif event.keyval == gtk.keysyms.Left: if prefs.get_direction() == gtk.TEXT_DIR_LTR: self.move_index_back (shift) else: self.move_index_forward (shift) elif event.keyval == gtk.keysyms.Right: if prefs.get_direction() == gtk.TEXT_DIR_RTL: self.move_index_back (shift) else: self.move_index_forward (shift) elif event.keyval == gtk.keysyms.Up: self.move_index_up (shift) elif event.keyval == gtk.keysyms.Down: self.move_index_down (shift) elif event.keyval == gtk.keysyms.Home: if prefs.get_direction() == gtk.TEXT_DIR_LTR: self.move_index_horizontal (shift, True) # move home else: self.move_index_horizontal (shift) # move end self.move_index_horizontal (shift, True) # move home elif event.keyval == gtk.keysyms.End: self.move_index_horizontal (shift) # move elif event.keyval == gtk.keysyms.BackSpace and self.editing: self.backspace_char () elif event.keyval == gtk.keysyms.Delete and self.editing: self.delete_char () elif len (event.string) != 0: self.add_text (event.string) clear_attrs = False else: handled = False if clear_attrs: del self.current_attrs self.current_attrs = [] self.recalc_edges () self.selection_changed () self.emit ("title_changed", self.text) self.bindex = self.bindex_from_index (self.index) self.emit ("update_view") return handled
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 draw(self, context): if not self.layout: self.recalc_edges() if not self.editing: # We should draw the entire bounding box around ourselves # We should also have our coordinates figured out. If not, scream! if not self.ul or not self.lr: print "Warning: Trying to draw unfinished box " + str( self.identity) + ". Aborting." return style = utils.STYLE_EXTENDED_CONTENT if len(self.extended_buffer.get_text()) == 0: style = utils.STYLE_NORMAL utils.draw_thought_outline(context, self.ul, self.lr, self.background_color, self.am_selected, self.am_primary, style) else: ux, uy = self.ul if prefs.get_direction() == gtk.TEXT_DIR_LTR: context.move_to(ux, uy + 5) context.line_to(ux, uy) context.line_to(ux + 5, uy) else: lx = self.lr[0] context.move_to(lx, uy + 5) context.line_to(lx, uy) context.line_to(lx - 5, uy) context.stroke() textx, texty = (self.text_location[0], self.text_location[1]) if (self.foreground_color): r, g, b = utils.gtk_to_cairo_color(self.foreground_color) else: r, g, b = utils.default_colors["text"] context.set_source_rgb(r, g, b) context.move_to(textx, texty) context.show_layout(self.layout) if self.editing: if self.preedit: strong, weak = self.layout.get_cursor_pos(self.index + self.preedit[2]) else: strong, weak = self.layout.get_cursor_pos(self.index) (startx, starty, curx, cury) = strong startx /= pango.SCALE starty /= pango.SCALE curx /= pango.SCALE cury /= pango.SCALE context.move_to(textx + startx, texty + starty) context.line_to(textx + startx, texty + starty + cury) context.stroke() context.set_source_rgb(0, 0, 0) context.stroke()
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 draw (self, context): if not self.layout: self.recalc_edges () if not self.editing: # We should draw the entire bounding box around ourselves # We should also have our coordinates figured out. If not, scream! if not self.ul or not self.lr: print "Warning: Trying to draw unfinished box "+str(self.identity)+". Aborting." return style = utils.STYLE_EXTENDED_CONTENT if len (self.extended_buffer.get_text()) == 0: style = utils.STYLE_NORMAL utils.draw_thought_outline (context, self.ul, self.lr, self.background_color, self.am_selected, self.am_primary, style) else: ux, uy = self.ul if prefs.get_direction() == gtk.TEXT_DIR_LTR: context.move_to (ux, uy+5) context.line_to (ux, uy) context.line_to (ux+5, uy) else: lx = self.lr[0] context.move_to (lx, uy+5) context.line_to (lx, uy) context.line_to (lx-5, uy) context.stroke () textx, texty = (self.text_location[0], self.text_location[1]) if (self.foreground_color): r, g, b = utils.gtk_to_cairo_color(self.foreground_color) else: r, g ,b = utils.default_colors["text"] context.set_source_rgb (r, g, b) context.move_to (textx, texty) context.show_layout (self.layout) if self.editing: if self.preedit: strong, weak = self.layout.get_cursor_pos (self.index + self.preedit[2]) else: strong, weak = self.layout.get_cursor_pos (self.index) (startx, starty, curx,cury) = strong startx /= pango.SCALE starty /= pango.SCALE curx /= pango.SCALE cury /= pango.SCALE context.move_to (textx + startx, texty + starty) context.line_to (textx + startx, texty + starty + cury) context.stroke () context.set_source_rgb (0,0,0) context.stroke ()
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 draw(self, context): if not self.layout: self.recalc_edges() if not self.editing: if not self.ul or not self.lr: print "Warning: Trying to draw unfinished box " + str( self.identity) + ". Aborting." return utils.draw_thought_extended (context, self.ul, self.lr, \ self.am_selected, self.am_primary, self.background_color, False, True) else: ux, uy = self.ul if prefs.get_direction() == gtk.TEXT_DIR_LTR: context.move_to(ux, uy + 5) context.line_to(ux, uy) context.line_to(ux + 5, uy) else: lx = self.lr[0] context.move_to(lx, uy + 5) context.line_to(lx, uy) context.line_to(lx - 5, uy) context.stroke() (textx, texty) = (self.text_location[0], self.text_location[1]) r, g, b = utils.gtk_to_cairo_color(self.foreground_color) context.set_source_rgb(r, g, b) context.move_to(textx, texty) context.show_layout(self.layout) if self.editing: if self.preedit: (strong, weak) = self.layout.get_cursor_pos(self.index + self.preedit[2]) else: (strong, weak) = self.layout.get_cursor_pos(self.index) (startx, starty, curx, cury) = strong startx /= pango.SCALE starty /= pango.SCALE curx /= pango.SCALE cury /= pango.SCALE context.move_to(textx + startx, texty + starty) context.line_to(textx + startx, texty + starty + cury) context.stroke() context.set_source_rgb(0, 0, 0) context.stroke()
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, 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 draw (self, context): if not self.layout: self.recalc_edges () if not self.editing: if not self.ul or not self.lr: print "Warning: Trying to draw unfinished box "+str(self.identity)+". Aborting." return utils.draw_thought_extended (context, self.ul, self.lr, \ self.am_selected, self.am_primary, self.background_color, False, True) else: ux, uy = self.ul if prefs.get_direction() == gtk.TEXT_DIR_LTR: context.move_to (ux, uy+5) context.line_to (ux, uy) context.line_to (ux+5, uy) else: lx = self.lr[0] context.move_to (lx, uy+5) context.line_to (lx, uy) context.line_to (lx-5, uy) context.stroke () (textx, texty) = (self.text_location[0], self.text_location[1]) r, g, b = utils.gtk_to_cairo_color(self.foreground_color) context.set_source_rgb (r, g, b) context.move_to (textx, texty) context.show_layout (self.layout) if self.editing: if self.preedit: (strong, weak) = self.layout.get_cursor_pos (self.index + self.preedit[2]) else: (strong, weak) = self.layout.get_cursor_pos (self.index) (startx, starty, curx,cury) = strong startx /= pango.SCALE starty /= pango.SCALE curx /= pango.SCALE cury /= pango.SCALE context.move_to (textx + startx, texty + starty) context.line_to (textx + startx, texty + starty + cury) context.stroke () context.set_source_rgb (0,0,0) context.stroke ()
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 process_key_press (self, event, mode): # Since we are using textviews, we don't use the # keypress code anymore if not self.editing: return False else: return True modifiers = Gtk.accelerator_get_default_mod_mask () shift = event.get_state() & modifiers == Gdk.ModifierType.SHIFT_MASK handled = True clear_attrs = True if not self.editing: return False if (event.get_state() & modifiers) & Gdk.ModifierType.CONTROL_MASK: if event.keyval == Gdk.KEY_a: self.index = self.bindex = 0 self.end_index = len (self.text) elif event.keyval == Gdk.KEY_Escape: self.leave() elif event.keyval == Gdk.KEY_Left: if prefs.get_direction() == Gtk.TextDirection.LTR: self.move_index_back (shift) else: self.move_index_forward (shift) elif event.keyval == Gdk.KEY_Right: if prefs.get_direction() == Gtk.TextDirection.RTL: self.move_index_back (shift) else: self.move_index_forward (shift) elif event.keyval == Gdk.KEY_Up: self.move_index_up (shift) elif event.keyval == Gdk.KEY_Down: self.move_index_down (shift) elif event.keyval == Gdk.KEY_Home: if prefs.get_direction() == Gtk.TextDirection.LTR: self.move_index_horizontal (shift, True) # move home else: self.move_index_horizontal (shift) # move end self.move_index_horizontal (shift, True) # move home elif event.keyval == Gdk.KEY_End: self.move_index_horizontal (shift) # move elif event.keyval == Gdk.KEY_BackSpace and self.editing: self.backspace_char () elif event.keyval == Gdk.KEY_Delete and self.editing: self.delete_char () elif len (event.string) != 0: self.add_text (event.string) clear_attrs = False else: handled = False if clear_attrs: del self.current_attrs self.current_attrs = [] self.recalc_edges () self.selection_changed () self.emit ("title_changed", self.text) self.bindex = self.bindex_from_index (self.index) self.emit ("update_view") return handled