2008-02-19 Douglas S. Blank <dblank@cs.brynmawr.edu>
* src/plugins/DefaultGramplets.py: News renders text with styles * src/DataViews/GrampletView.py (GuiGramplet.render_text): First draft of a TextBuffer with markup svn: r10073
This commit is contained in:
parent
977c9d8013
commit
65951d6722
@ -1,3 +1,8 @@
|
|||||||
|
2008-02-19 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||||
|
* src/plugins/DefaultGramplets.py: News renders text with styles
|
||||||
|
* src/DataViews/GrampletView.py (GuiGramplet.render_text):
|
||||||
|
First draft of a TextBuffer with markup
|
||||||
|
|
||||||
2008-02-19 Benny Malengier <benny.malengier@gramps-project.org>
|
2008-02-19 Benny Malengier <benny.malengier@gramps-project.org>
|
||||||
* src/ViewManager.py: #1559, CTRL+N/P also if no sidebar
|
* src/ViewManager.py: #1559, CTRL+N/P also if no sidebar
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class LinkTag(gtk.TextTag):
|
|||||||
LinkTag.lid += 1
|
LinkTag.lid += 1
|
||||||
gtk.TextTag.__init__(self, str(LinkTag.lid))
|
gtk.TextTag.__init__(self, str(LinkTag.lid))
|
||||||
tag_table = buffer.get_tag_table()
|
tag_table = buffer.get_tag_table()
|
||||||
self.set_property('foreground', "#0000ff")
|
self.set_property('foreground', "blue")
|
||||||
#self.set_property('underline', pango.UNDERLINE_SINGLE)
|
#self.set_property('underline', pango.UNDERLINE_SINGLE)
|
||||||
tag_table.add(self)
|
tag_table.add(self)
|
||||||
|
|
||||||
@ -234,37 +234,33 @@ class Gramplet(object):
|
|||||||
self._tags.append(link_data)
|
self._tags.append(link_data)
|
||||||
buffer.apply_tag(link_data[0], start, end)
|
buffer.apply_tag(link_data[0], start, end)
|
||||||
|
|
||||||
|
# Shortcuts to the gui functionality:
|
||||||
|
|
||||||
def get_text(self):
|
def get_text(self):
|
||||||
start = self.gui.buffer.get_start_iter()
|
return self.gui.get_text()
|
||||||
end = self.gui.buffer.get_end_iter()
|
|
||||||
return self.gui.buffer.get_text(start, end)
|
|
||||||
|
|
||||||
def insert_text(self, text):
|
def insert_text(self, text):
|
||||||
self.gui.buffer.insert_at_cursor(text)
|
self.gui.insert_text(text)
|
||||||
|
|
||||||
|
def render_text(self, text):
|
||||||
|
self.gui.render_text(text)
|
||||||
|
|
||||||
def clear_text(self):
|
def clear_text(self):
|
||||||
self.gui.buffer.set_text('')
|
self.gui.clear_text()
|
||||||
|
|
||||||
def set_text(self, text, scroll_to='start'):
|
def set_text(self, text, scroll_to='start'):
|
||||||
self.gui.buffer.set_text('')
|
self.gui.set_text(text, scroll_to)
|
||||||
self.append_text(text, scroll_to)
|
|
||||||
|
|
||||||
def append_text(self, text, scroll_to="end"):
|
def append_text(self, text, scroll_to="end"):
|
||||||
enditer = self.gui.buffer.get_end_iter()
|
self.gui.append_text(text, scroll_to)
|
||||||
start = self.gui.buffer.create_mark(None, enditer, True)
|
|
||||||
self.gui.buffer.insert(enditer, text)
|
def render_text(self, text):
|
||||||
if scroll_to == "end":
|
self.gui.render_text(text)
|
||||||
enditer = self.gui.buffer.get_end_iter()
|
|
||||||
end = self.gui.buffer.create_mark(None, enditer, True)
|
def set_use_markup(self, value):
|
||||||
self.gui.textview.scroll_to_mark(end, 0.0, True, 0, 0)
|
self.gui.set_use_markup(value)
|
||||||
elif scroll_to == "start": # beginning of this append
|
|
||||||
self.gui.textview.scroll_to_mark(start, 0.0, True, 0, 0)
|
# Other functions of the gramplet:
|
||||||
elif scroll_to == "begin": # beginning of this append
|
|
||||||
begin_iter = self.gui.buffer.get_start_iter()
|
|
||||||
begin = self.gui.buffer.create_mark(None, begin_iter, True)
|
|
||||||
self.gui.textview.scroll_to_mark(begin, 0.0, True, 0, 0)
|
|
||||||
else:
|
|
||||||
raise AttributeError, ("no such cursor position: '%s'" % scroll_to)
|
|
||||||
|
|
||||||
def load_data_to_text(self, pos=0):
|
def load_data_to_text(self, pos=0):
|
||||||
if len(self.gui.data) >= pos + 1:
|
if len(self.gui.data) >= pos + 1:
|
||||||
@ -419,6 +415,7 @@ class GuiGramplet:
|
|||||||
self.state = kwargs.get("state", "maximized")
|
self.state = kwargs.get("state", "maximized")
|
||||||
self.data = kwargs.get("data", [])
|
self.data = kwargs.get("data", [])
|
||||||
##########
|
##########
|
||||||
|
self.use_markup = False
|
||||||
self.pui = None # user code
|
self.pui = None # user code
|
||||||
self.tooltips = None
|
self.tooltips = None
|
||||||
self.tooltips_text = None
|
self.tooltips_text = None
|
||||||
@ -509,14 +506,94 @@ class GuiGramplet:
|
|||||||
expand,fill,padding,pack = column.query_child_packing(self.mainframe)
|
expand,fill,padding,pack = column.query_child_packing(self.mainframe)
|
||||||
column.set_child_packing(self.mainframe,self.expand,fill,padding,pack)
|
column.set_child_packing(self.mainframe,self.expand,fill,padding,pack)
|
||||||
|
|
||||||
def append_text(self, text):
|
def append_text(self, text, scroll_to="end"):
|
||||||
self.buffer.insert_at_cursor(text)
|
enditer = self.buffer.get_end_iter()
|
||||||
|
start = self.buffer.create_mark(None, enditer, True)
|
||||||
|
self.buffer.insert(enditer, text)
|
||||||
|
if scroll_to == "end":
|
||||||
|
enditer = self.buffer.get_end_iter()
|
||||||
|
end = self.buffer.create_mark(None, enditer, True)
|
||||||
|
self.textview.scroll_to_mark(end, 0.0, True, 0, 0)
|
||||||
|
elif scroll_to == "start": # beginning of this append
|
||||||
|
self.textview.scroll_to_mark(start, 0.0, True, 0, 0)
|
||||||
|
elif scroll_to == "begin": # beginning of this append
|
||||||
|
begin_iter = self.buffer.get_start_iter()
|
||||||
|
begin = self.buffer.create_mark(None, begin_iter, True)
|
||||||
|
self.textview.scroll_to_mark(begin, 0.0, True, 0, 0)
|
||||||
|
else:
|
||||||
|
raise AttributeError, ("no such cursor position: '%s'" % scroll_to)
|
||||||
|
|
||||||
def clear_text(self):
|
def clear_text(self):
|
||||||
self.buffer.set_text('')
|
self.buffer.set_text('')
|
||||||
|
|
||||||
def set_text(self, text):
|
def get_text(self):
|
||||||
self.buffer.set_text(text)
|
start = self.buffer.get_start_iter()
|
||||||
|
end = self.buffer.get_end_iter()
|
||||||
|
return self.buffer.get_text(start, end)
|
||||||
|
|
||||||
|
def insert_text(self, text):
|
||||||
|
self.buffer.insert_at_cursor(text)
|
||||||
|
|
||||||
|
def render_text(self, text):
|
||||||
|
markup_pos = {"B": [], "I": [], "U": []}
|
||||||
|
retval = ""
|
||||||
|
i = 0
|
||||||
|
r = 0
|
||||||
|
while i < len(text):
|
||||||
|
if text[i] == "<":
|
||||||
|
if text[i+1] == "/" and text[i+3] == ">":
|
||||||
|
markup = text[i+2].upper()
|
||||||
|
markup_pos[markup][-1].append(r)
|
||||||
|
i += 4
|
||||||
|
elif text[i+2] == ">":
|
||||||
|
markup = text[i+1].upper()
|
||||||
|
markup_pos[markup].append([r])
|
||||||
|
i += 3
|
||||||
|
else:
|
||||||
|
retval += text[i]
|
||||||
|
r += 1
|
||||||
|
i += 1
|
||||||
|
elif text[i] == "\\":
|
||||||
|
retval += text[i+1]
|
||||||
|
r += 1
|
||||||
|
i += 2
|
||||||
|
elif ord(text[i]) > 126:
|
||||||
|
while ord(text[i]) > 126:
|
||||||
|
retval += text[i]
|
||||||
|
i += 1
|
||||||
|
r += 1
|
||||||
|
else:
|
||||||
|
retval += text[i]
|
||||||
|
r += 1
|
||||||
|
i += 1
|
||||||
|
self.set_text(retval)
|
||||||
|
for (a,b) in markup_pos["B"]:
|
||||||
|
start = self.buffer.get_iter_at_offset(a)
|
||||||
|
stop = self.buffer.get_iter_at_offset(b)
|
||||||
|
self.buffer.apply_tag_by_name("bold", start, stop)
|
||||||
|
for (a,b) in markup_pos["I"]:
|
||||||
|
start = self.buffer.get_iter_at_offset(a)
|
||||||
|
stop = self.buffer.get_iter_at_offset(b)
|
||||||
|
self.buffer.apply_tag_by_name("italic", start, stop)
|
||||||
|
for (a,b) in markup_pos["U"]:
|
||||||
|
start = self.buffer.get_iter_at_offset(a)
|
||||||
|
stop = self.buffer.get_iter_at_offset(b)
|
||||||
|
self.buffer.apply_tag_by_name("underline", start, stop)
|
||||||
|
|
||||||
|
def set_use_markup(self, value):
|
||||||
|
if self.use_markup == value: return
|
||||||
|
self.use_markup = value
|
||||||
|
if value:
|
||||||
|
self.buffer.create_tag("bold",weight=pango.WEIGHT_HEAVY)
|
||||||
|
self.buffer.create_tag("italic",style=pango.STYLE_ITALIC)
|
||||||
|
self.buffer.create_tag("underline",underline=pango.UNDERLINE_SINGLE)
|
||||||
|
else:
|
||||||
|
tag_table = self.buffer.get_tag_table()
|
||||||
|
tag_table.foreach(lambda tag, data: tag_table.remove(tag))
|
||||||
|
|
||||||
|
def set_text(self, text, scroll_to='start'):
|
||||||
|
self.buffer.set_text('')
|
||||||
|
self.append_text(text, scroll_to)
|
||||||
|
|
||||||
def get_source_widget(self):
|
def get_source_widget(self):
|
||||||
"""
|
"""
|
||||||
|
@ -26,7 +26,7 @@ from BasicUtils import name_displayer
|
|||||||
from Utils import media_path_full
|
from Utils import media_path_full
|
||||||
from QuickReports import run_quick_report_by_name
|
from QuickReports import run_quick_report_by_name
|
||||||
import DateHandler
|
import DateHandler
|
||||||
from gettext import gettext as _
|
from TransUtils import sgettext as _
|
||||||
import Config
|
import Config
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -549,7 +549,7 @@ class PythonGramplet(Gramplet):
|
|||||||
self.env = {"dbstate": self.gui.dbstate,
|
self.env = {"dbstate": self.gui.dbstate,
|
||||||
"uistate": self.gui.uistate,
|
"uistate": self.gui.uistate,
|
||||||
"self": self,
|
"self": self,
|
||||||
"Date": gen.lib.Date,
|
_("class name|Date"): gen.lib.Date,
|
||||||
}
|
}
|
||||||
# GUI setup:
|
# GUI setup:
|
||||||
self.gui.textview.set_editable(True)
|
self.gui.textview.set_editable(True)
|
||||||
@ -676,7 +676,6 @@ def make_welcome_content(gui):
|
|||||||
)
|
)
|
||||||
gui.set_text(text)
|
gui.set_text(text)
|
||||||
|
|
||||||
|
|
||||||
class NewsGramplet(Gramplet):
|
class NewsGramplet(Gramplet):
|
||||||
URL = "http://www.gramps-project.org/wiki/index.php?title=%s&action=raw"
|
URL = "http://www.gramps-project.org/wiki/index.php?title=%s&action=raw"
|
||||||
|
|
||||||
@ -688,7 +687,7 @@ class NewsGramplet(Gramplet):
|
|||||||
retval = True
|
retval = True
|
||||||
while retval:
|
while retval:
|
||||||
retval, text = continuation.next()
|
retval, text = continuation.next()
|
||||||
self.cleanup(text)
|
self.set_text(text)
|
||||||
yield True
|
yield True
|
||||||
self.cleanup(text)
|
self.cleanup(text)
|
||||||
yield False
|
yield False
|
||||||
@ -699,7 +698,26 @@ class NewsGramplet(Gramplet):
|
|||||||
while "\n\n\n" in text:
|
while "\n\n\n" in text:
|
||||||
text = text.replace("\n\n\n", "\n\n")
|
text = text.replace("\n\n\n", "\n\n")
|
||||||
text = text.strip()
|
text = text.strip()
|
||||||
self.set_text(text)
|
## Wiki text:
|
||||||
|
pattern = re.compile('\[\[(.*?)\|(.*?)\]\]')
|
||||||
|
matches = pattern.findall(text)
|
||||||
|
for (g1, g2) in matches:
|
||||||
|
text = text.replace("[[%s|%s]]" % (g1, g2), "<U>%s</U>" % g2)
|
||||||
|
pattern = re.compile('\[\[(.*?)\]\]')
|
||||||
|
matches = pattern.findall(text)
|
||||||
|
for match in matches:
|
||||||
|
text = text.replace("[[%s]]" % match, "<U>%s</U>" % match)
|
||||||
|
pattern = re.compile('\[(.*?) (.*?)\]')
|
||||||
|
matches = pattern.findall(text)
|
||||||
|
for (g1, g2) in matches:
|
||||||
|
text = text.replace("[%s %s]" % (g1, g2), "<U>%s</U>" % g2)
|
||||||
|
pattern = re.compile("'''(.*?)'''")
|
||||||
|
matches = pattern.findall(text)
|
||||||
|
for match in matches:
|
||||||
|
text = text.replace("'''%s'''" % match, "<B>%s</B>" % match)
|
||||||
|
text = "News from <I>www.gramps-project.org</I>:\n\n" + text
|
||||||
|
self.set_use_markup(True)
|
||||||
|
self.render_text(text)
|
||||||
|
|
||||||
def process(self, title):
|
def process(self, title):
|
||||||
#print "processing '%s'..." % title
|
#print "processing '%s'..." % title
|
||||||
|
Loading…
Reference in New Issue
Block a user