0001863: <gramps> tags in notes, consistency. This should be in all notes or only in the ones that have markup

Markup has been disabled for notes. A new strategy is being worked on to allow styles for notes.

svn: r10230
This commit is contained in:
Brian Matherly 2008-03-08 21:20:42 +00:00
parent b04ef64231
commit fa0b508924
4 changed files with 237 additions and 191 deletions

View File

@ -1,3 +1,12 @@
2008-03-08 Brian Matherly <brian@gramps-project.org>
* src/gen/lib/note.py:
* src/Editors/_EditNote.py:
* src/DisplayModels/_NoteModel.py:
0001863: <gramps> tags in notes, consistency. This should be in all
notes or only in the ones that have markup
Markup has been disabled for notes. A new strategy is being worked
on to allow styles for notes.
2008-03-08 Douglas S. Blank <dblank@saliva.brynmawr.edu> 2008-03-08 Douglas S. Blank <dblank@saliva.brynmawr.edu>
* src/DataViews/GrampletView.py (GrampletWindow.close): * src/DataViews/GrampletView.py (GrampletWindow.close):
fixed issue with reattaching detached gramplet after a col change fixed issue with reattaching detached gramplet after a col change

View File

@ -100,11 +100,6 @@ class NoteModel(BaseModel):
#data is the encoding in the database, make it a unicode object #data is the encoding in the database, make it a unicode object
#for universal work #for universal work
note = " ".join(unicode(data[2]).split()) note = " ".join(unicode(data[2]).split())
note = re.sub(r'(<.*?>)', '', note)
note = note.replace('&amp;', '&')
note = note.replace('&lt;', '<')
note = note.replace('&gt;', '>')
if len(note) > 80: if len(note) > 80:
return note[:80]+"..." return note[:80]+"..."
else: else:

View File

@ -37,7 +37,7 @@ log = logging.getLogger(".")
import gtk import gtk
from gtk import glade from gtk import glade
import gobject import gobject
from pango import UNDERLINE_SINGLE import pango
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -61,16 +61,16 @@ from QuestionDialog import ErrorDialog
# Constants # Constants
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
USERCHARS = "-A-Za-z0-9" #USERCHARS = "-A-Za-z0-9"
PASSCHARS = "-A-Za-z0-9,?;.:/!%$^*&~\"#'" #PASSCHARS = "-A-Za-z0-9,?;.:/!%$^*&~\"#'"
HOSTCHARS = "-A-Za-z0-9" #HOSTCHARS = "-A-Za-z0-9"
PATHCHARS = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%" #PATHCHARS = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%"
#SCHEME = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)" ##SCHEME = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)"
SCHEME = "(file:/|https?:|ftps?:|webcal:)" #SCHEME = "(file:/|https?:|ftps?:|webcal:)"
USER = "[" + USERCHARS + "]+(:[" + PASSCHARS + "]+)?" #USER = "[" + USERCHARS + "]+(:[" + PASSCHARS + "]+)?"
URLPATH = "/[" + PATHCHARS + "]*[^]'.}>) \t\r\n,\\\"]" #URLPATH = "/[" + PATHCHARS + "]*[^]'.}>) \t\r\n,\\\"]"
#
(GENERAL, HTTP, MAIL) = range(3) #(GENERAL, HTTP, MAIL) = range(3)
@ -267,53 +267,102 @@ class EditNote(EditPrimary):
self._setup_notebook_tabs( notebook) self._setup_notebook_tabs( notebook)
def build_interface(self): # THIS IS THE MARKUP VERSION - enable for markup
FORMAT_TOOLBAR = ''' # def build_interface(self):
<ui> # FORMAT_TOOLBAR = '''
<toolbar name="ToolBar"> # <ui>
<toolitem action="italic"/> # <toolbar name="ToolBar">
<toolitem action="bold"/> # <toolitem action="italic"/>
<toolitem action="underline"/> # <toolitem action="bold"/>
<separator/> # <toolitem action="underline"/>
<toolitem action="font"/> # <separator/>
<toolitem action="foreground"/> # <toolitem action="font"/>
<toolitem action="background"/> # <toolitem action="foreground"/>
<separator/> # <toolitem action="background"/>
<toolitem action="clear"/> # <separator/>
</toolbar> # <toolitem action="clear"/>
</ui> # </toolbar>
''' # </ui>
# '''
#
# buffer_ = MarkupText.MarkupBuffer()
# buffer_.create_tag('hyperlink',
# underline=pango.UNDERLINE_SINGLE,
# foreground='blue')
# buffer_.match_add("(www|ftp)[" + HOSTCHARS + "]*\\.[" + HOSTCHARS +
# ".]+" + "(:[0-9]+)?(" + URLPATH + ")?/?", HTTP)
# buffer_.match_add("(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9][a-z0-9-]*"
# "(\\.[a-z0-9][a-z0-9-]*)+", MAIL)
# buffer_.match_add(SCHEME + "//(" + USER + "@)?[" + HOSTCHARS + ".]+" +
# "(:[0-9]+)?(" + URLPATH + ")?/?", GENERAL)
# self.match = None
# self.last_match = None
#
# self.text = self.top.get_widget('text')
# self.text.set_editable(not self.dbstate.db.readonly)
# self.text.set_buffer(buffer_)
# self.text.connect('key-press-event',
# self.on_textview_key_press_event)
# self.text.connect('insert-at-cursor',
# self.on_textview_insert_at_cursor)
# self.text.connect('delete-from-cursor',
# self.on_textview_delete_from_cursor)
# self.text.connect('paste-clipboard',
# self.on_textview_paste_clipboard)
# self.text.connect('motion-notify-event',
# self.on_textview_motion_notify_event)
# self.text.connect('button-press-event',
# self.on_textview_button_press_event)
# self.text.connect('populate-popup',
# self.on_textview_populate_popup)
#
# # setup spell checking interface
# spellcheck = Spell.Spell(self.text)
# liststore = gtk.ListStore(gobject.TYPE_STRING)
# cell = gtk.CellRendererText()
# lang_selector = self.top.get_widget('spell')
# lang_selector.set_model(liststore)
# lang_selector.pack_start(cell, True)
# lang_selector.add_attribute(cell, 'text', 0)
# act_lang = spellcheck.get_active_language()
# idx = 0
# for lang in spellcheck.get_all_languages():
# lang_selector.append_text(lang)
# if lang == act_lang:
# act_idx = idx
# idx = idx + 1
# lang_selector.set_active(act_idx)
# lang_selector.connect('changed', self.on_spell_change, spellcheck)
# #lang_selector.set_sensitive(Config.get(Config.SPELLCHECK))
#
# # create a formatting toolbar
# if not self.dbstate.db.readonly:
# uimanager = gtk.UIManager()
# uimanager.insert_action_group(buffer_.format_action_group, 0)
# uimanager.add_ui_from_string(FORMAT_TOOLBAR)
# uimanager.ensure_update()
#
# toolbar = uimanager.get_widget('/ToolBar')
# toolbar.set_style(gtk.TOOLBAR_ICONS)
# vbox = self.top.get_widget('container')
# vbox.pack_start(toolbar)
#
# # setup initial values for textview and buffer_
# if self.obj:
# self.empty = False
# self.flow_changed(self.obj.get_format())
# buffer_.set_text(self.obj.get(markup=True))
# log.debug("Initial Note: %s" % buffer_.get_text())
# else:
# self.empty = True
buffer_ = MarkupText.MarkupBuffer() # NON-MARKUP VERSION - Disable for markup
buffer_.create_tag('hyperlink', def build_interface(self):
underline=UNDERLINE_SINGLE, buffer_ = gtk.TextBuffer()
foreground='blue')
buffer_.match_add("(www|ftp)[" + HOSTCHARS + "]*\\.[" + HOSTCHARS +
".]+" + "(:[0-9]+)?(" + URLPATH + ")?/?", HTTP)
buffer_.match_add("(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9][a-z0-9-]*"
"(\\.[a-z0-9][a-z0-9-]*)+", MAIL)
buffer_.match_add(SCHEME + "//(" + USER + "@)?[" + HOSTCHARS + ".]+" +
"(:[0-9]+)?(" + URLPATH + ")?/?", GENERAL)
self.match = None
self.last_match = None
self.text = self.top.get_widget('text') self.text = self.top.get_widget('text')
self.text.set_editable(not self.dbstate.db.readonly) self.text.set_editable(not self.dbstate.db.readonly)
self.text.set_buffer(buffer_) self.text.set_buffer(buffer_)
self.text.connect('key-press-event',
self.on_textview_key_press_event)
self.text.connect('insert-at-cursor',
self.on_textview_insert_at_cursor)
self.text.connect('delete-from-cursor',
self.on_textview_delete_from_cursor)
self.text.connect('paste-clipboard',
self.on_textview_paste_clipboard)
self.text.connect('motion-notify-event',
self.on_textview_motion_notify_event)
self.text.connect('button-press-event',
self.on_textview_button_press_event)
self.text.connect('populate-popup',
self.on_textview_populate_popup)
# setup spell checking interface # setup spell checking interface
spellcheck = Spell.Spell(self.text) spellcheck = Spell.Spell(self.text)
@ -333,25 +382,12 @@ class EditNote(EditPrimary):
lang_selector.set_active(act_idx) lang_selector.set_active(act_idx)
lang_selector.connect('changed', self.on_spell_change, spellcheck) lang_selector.connect('changed', self.on_spell_change, spellcheck)
#lang_selector.set_sensitive(Config.get(Config.SPELLCHECK)) #lang_selector.set_sensitive(Config.get(Config.SPELLCHECK))
# create a formatting toolbar
if not self.dbstate.db.readonly:
uimanager = gtk.UIManager()
uimanager.insert_action_group(buffer_.format_action_group, 0)
uimanager.add_ui_from_string(FORMAT_TOOLBAR)
uimanager.ensure_update()
toolbar = uimanager.get_widget('/ToolBar')
toolbar.set_style(gtk.TOOLBAR_ICONS)
vbox = self.top.get_widget('container')
vbox.pack_start(toolbar)
# setup initial values for textview and buffer_ # setup initial values for textview and buffer_
if self.obj: if self.obj:
self.empty = False self.empty = False
self.flow_changed(self.obj.get_format()) self.flow_changed(self.obj.get_format())
buffer_.set_text(self.obj.get(markup=True)) buffer_.set_text(self.obj.get(markup=True))
log.debug("Initial Note: %s" % buffer_.get_text())
else: else:
self.empty = True self.empty = True
@ -365,108 +401,110 @@ class EditNote(EditPrimary):
def _post_init(self): def _post_init(self):
self.text.grab_focus() self.text.grab_focus()
def on_textview_key_press_event(self, textview, event): # enable for markup
"""Handle shortcuts in the TextView.""" # def on_textview_key_press_event(self, textview, event):
return textview.get_buffer().on_key_press_event(textview, event) # """Handle shortcuts in the TextView."""
# return textview.get_buffer().on_key_press_event(textview, event)
def on_textview_insert_at_cursor(self, textview, string): #
log.debug("Textview insert '%s'" % string) # def on_textview_insert_at_cursor(self, textview, string):
# log.debug("Textview insert '%s'" % string)
def on_textview_delete_from_cursor(self, textview, type, count): #
log.debug("Textview delete type %d count %d" % (type, count)) # def on_textview_delete_from_cursor(self, textview, type, count):
# log.debug("Textview delete type %d count %d" % (type, count))
def on_textview_paste_clipboard(self, textview): #
log.debug("Textview paste clipboard") # def on_textview_paste_clipboard(self, textview):
# log.debug("Textview paste clipboard")
def on_textview_motion_notify_event(self, textview, event): #
window = textview.get_window(gtk.TEXT_WINDOW_TEXT) # def on_textview_motion_notify_event(self, textview, event):
x, y = textview.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET, # window = textview.get_window(gtk.TEXT_WINDOW_TEXT)
int(event.x), int(event.y)) # x, y = textview.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET,
iter = textview.get_iter_at_location(x, y) # int(event.x), int(event.y))
buffer_ = textview.get_buffer() # iter = textview.get_iter_at_location(x, y)
self.match = buffer_.match_check(iter.get_offset()) # buffer_ = textview.get_buffer()
# self.match = buffer_.match_check(iter.get_offset())
if self.match != self.last_match: #
start, end = buffer_.get_bounds() # if self.match != self.last_match:
buffer_.remove_tag_by_name('hyperlink', start, end) # start, end = buffer_.get_bounds()
if self.match: # buffer_.remove_tag_by_name('hyperlink', start, end)
start_offset = self.match[MarkupText.MATCH_START] # if self.match:
end_offset = self.match[MarkupText.MATCH_END] # start_offset = self.match[MarkupText.MATCH_START]
# end_offset = self.match[MarkupText.MATCH_END]
start = buffer_.get_iter_at_offset(start_offset) #
end = buffer_.get_iter_at_offset(end_offset) # start = buffer_.get_iter_at_offset(start_offset)
# end = buffer_.get_iter_at_offset(end_offset)
buffer_.apply_tag_by_name('hyperlink', start, end) #
window.set_cursor(self.hand_cursor) # buffer_.apply_tag_by_name('hyperlink', start, end)
else: # window.set_cursor(self.hand_cursor)
window.set_cursor(self.regular_cursor) # else:
# window.set_cursor(self.regular_cursor)
self.last_match = self.match #
# self.last_match = self.match
textview.window.get_pointer() #
return False # textview.window.get_pointer()
# return False
def on_textview_button_press_event(self, textview, event): #
if ((event.type == gtk.gdk.BUTTON_PRESS) and # def on_textview_button_press_event(self, textview, event):
(event.button == 1) and # if ((event.type == gtk.gdk.BUTTON_PRESS) and
(event.state and gtk.gdk.CONTROL_MASK) and # (event.button == 1) and
(self.match)): # (event.state and gtk.gdk.CONTROL_MASK) and
# (self.match)):
flavor = self.match[MarkupText.MATCH_FLAVOR] #
url = self.match[MarkupText.MATCH_STRING] # flavor = self.match[MarkupText.MATCH_FLAVOR]
self.open_url_cb(None, url, flavor) # url = self.match[MarkupText.MATCH_STRING]
# self.open_url_cb(None, url, flavor)
return False #
# return False
def on_textview_populate_popup(self, textview, menu): #
"""Insert extra menuitems according to matched pattern.""" # def on_textview_populate_popup(self, textview, menu):
if self.match: # """Insert extra menuitems according to matched pattern."""
flavor = self.match[MarkupText.MATCH_FLAVOR] # if self.match:
url = self.match[MarkupText.MATCH_STRING] # flavor = self.match[MarkupText.MATCH_FLAVOR]
# url = self.match[MarkupText.MATCH_STRING]
if flavor == MAIL: #
open_menu = gtk.MenuItem(_('_Send Mail To...')) # if flavor == MAIL:
copy_menu = gtk.MenuItem(_('Copy _E-mail Address')) # open_menu = gtk.MenuItem(_('_Send Mail To...'))
else: # copy_menu = gtk.MenuItem(_('Copy _E-mail Address'))
open_menu = gtk.MenuItem(_('_Open Link')) # else:
copy_menu = gtk.MenuItem(_('Copy _Link Address')) # open_menu = gtk.MenuItem(_('_Open Link'))
# copy_menu = gtk.MenuItem(_('Copy _Link Address'))
copy_menu.connect('activate', self.copy_url_cb, url, flavor) #
copy_menu.show() # copy_menu.connect('activate', self.copy_url_cb, url, flavor)
menu.prepend(copy_menu) # copy_menu.show()
# menu.prepend(copy_menu)
open_menu.connect('activate', self.open_url_cb, url, flavor) #
open_menu.show() # open_menu.connect('activate', self.open_url_cb, url, flavor)
menu.prepend(open_menu) # open_menu.show()
# menu.prepend(open_menu)
def on_spell_change(self, combobox, spell): def on_spell_change(self, combobox, spell):
"""Set spell checker language according to user selection.""" """Set spell checker language according to user selection."""
lang = combobox.get_active_text() lang = combobox.get_active_text()
spell.set_active_language(lang) spell.set_active_language(lang)
def open_url_cb(self, menuitem, url, flavor): # enable for markup
if not url: # def open_url_cb(self, menuitem, url, flavor):
return # if not url:
# return
if flavor == HTTP: #
url = 'http:' + url # if flavor == HTTP:
elif flavor == MAIL: # url = 'http:' + url
if not url.startswith('mailto:'): # elif flavor == MAIL:
url = 'mailto:' + url # if not url.startswith('mailto:'):
elif flavor == GENERAL: # url = 'mailto:' + url
pass # elif flavor == GENERAL:
else: # pass
return # else:
# return
GrampsDisplay.url(url) #
# GrampsDisplay.url(url)
def copy_url_cb(self, menuitem, url, flavor): #
"""Copy url to both useful selections.""" # def copy_url_cb(self, menuitem, url, flavor):
clipboard = gtk.Clipboard(selection="CLIPBOARD") # """Copy url to both useful selections."""
clipboard.set_text(url) # clipboard = gtk.Clipboard(selection="CLIPBOARD")
# clipboard.set_text(url)
clipboard = gtk.Clipboard(selection="PRIMARY") #
clipboard.set_text(url) # clipboard = gtk.Clipboard(selection="PRIMARY")
# clipboard.set_text(url)
def update_note(self): def update_note(self):
"""Update the Note object with current value.""" """Update the Note object with current value."""
@ -479,9 +517,13 @@ class EditNote(EditPrimary):
def flow_changed(self, active): def flow_changed(self, active):
if active: if active:
# Set the text style to monospace
self.text.set_wrap_mode(gtk.WRAP_NONE) self.text.set_wrap_mode(gtk.WRAP_NONE)
self.text.modify_font(pango.FontDescription("monospace"))
else: else:
# Set the text style to normal
self.text.set_wrap_mode(gtk.WRAP_WORD) self.text.set_wrap_mode(gtk.WRAP_WORD)
self.text.modify_font(pango.FontDescription("normal"))
def save(self, *obj): def save(self, *obj):
"""Save the data.""" """Save the data."""

View File

@ -41,7 +41,7 @@ from gen.lib.primaryobj import BasicPrimaryObject
from gen.lib.notetype import NoteType from gen.lib.notetype import NoteType
from gen.lib.markertype import MarkerType from gen.lib.markertype import MarkerType
ROOT_START_TAG = '<gramps>' #ROOT_START_TAG = '<gramps>'
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -96,7 +96,7 @@ class Note(BasicPrimaryObject):
@return: Returns the list of all textual attributes of the object. @return: Returns the list of all textual attributes of the object.
@rtype: list @rtype: list
""" """
return [self.delete_tags(self.text)] return [self.text]
def set(self, text): def set(self, text):
""" """
@ -117,29 +117,29 @@ class Note(BasicPrimaryObject):
@rtype: str @rtype: str
""" """
text = self.text text = self.text
#
if not markup and text.startswith(ROOT_START_TAG): # if not markup and text.startswith(ROOT_START_TAG):
text = self.delete_tags(text) # text = self.delete_tags(text)
return text
def delete_tags(self, markup_text):
"""
Create a plain text version of the note text by removing all pango
markup tags.
@param markup_text: Pango style markup text
@type markup_text: str
@return: Plain text
@rtype: str
"""
text = re.sub(r'(<.*?>)', '', markup_text)
text = text.replace('&amp;', '&')
text = text.replace('&lt;', '<')
text = text.replace('&gt;', '>')
return text return text
#
# def delete_tags(self, markup_text):
# """
# Create a plain text version of the note text by removing all pango
# markup tags.
#
# @param markup_text: Pango style markup text
# @type markup_text: str
# @return: Plain text
# @rtype: str
# """
# text = re.sub(r'(<.*?>)', '', markup_text)
#
# text = text.replace('&amp;', '&')
# text = text.replace('&lt;', '<')
# text = text.replace('&gt;', '>')
#
# return text
def append(self, text): def append(self, text):
""" """