foiegras r48 - in trunk: . src/foiegras/buffer
- From: denisw svn gnome org
- To: svn-commits-list gnome org
- Subject: foiegras r48 - in trunk: . src/foiegras/buffer
- Date: Tue, 29 Jan 2008 07:37:50 +0000 (GMT)
Author: denisw
Date: Tue Jan 29 07:37:50 2008
New Revision: 48
URL: http://svn.gnome.org/viewvc/foiegras?rev=48&view=rev
Log:
2008-01-28 Denis Washington <denisw svn gnome org>
* src/foiegras/buffer/*.py:
Add whitespace at many places to enhance readability.
Modified:
trunk/ChangeLog
trunk/src/foiegras/buffer/MallardTextView.py
trunk/src/foiegras/buffer/attribute_handler.py
trunk/src/foiegras/buffer/attribute_renderer.py
trunk/src/foiegras/buffer/block_handler.py
trunk/src/foiegras/buffer/buffer.py
trunk/src/foiegras/buffer/table_handler.py
trunk/src/foiegras/buffer/tagparser.py
trunk/src/foiegras/buffer/xmlparser.py
Modified: trunk/src/foiegras/buffer/MallardTextView.py
==============================================================================
--- trunk/src/foiegras/buffer/MallardTextView.py (original)
+++ trunk/src/foiegras/buffer/MallardTextView.py Tue Jan 29 07:37:50 2008
@@ -10,12 +10,14 @@
Customized implementation of gtk.TextView for Mallard.
"""
def __init__(self,buffer = None):
- gtk.TextView.__init__(self,buffer)
+ gtk.TextView.__init__(self,buffer)
+
#stores the total height of block tag height
self.block_tag_length = 0
+
#complete hight of the textview
self.height = 0
+
#whether textview contains block tags
self.is_block_container = False
-
-
\ No newline at end of file
+
Modified: trunk/src/foiegras/buffer/attribute_handler.py
==============================================================================
--- trunk/src/foiegras/buffer/attribute_handler.py (original)
+++ trunk/src/foiegras/buffer/attribute_handler.py Tue Jan 29 07:37:50 2008
@@ -20,7 +20,8 @@
#check for given attributes with valid attributes
for k,v in attribs.iteritems():
if k.strip() in tag_table:
- valid = [x.strip() for x in tag_table[k].split("|")]
+ valid = [x.strip() for x in tag_table[k].split("|")]
+
#Valid can be a UPPER CASED CONSTANT eg: PATH_STRING
#or can be a valid attrib set eg: image/png | image/gif | image/jpg
if len(valid) == 1 and valid[0].isupper():
@@ -55,4 +56,4 @@
def __init__(self, value):
self.value = value
def __str__(self):
- return repr(self.value)
\ No newline at end of file
+ return repr(self.value)
Modified: trunk/src/foiegras/buffer/attribute_renderer.py
==============================================================================
--- trunk/src/foiegras/buffer/attribute_renderer.py (original)
+++ trunk/src/foiegras/buffer/attribute_renderer.py Tue Jan 29 07:37:50 2008
@@ -12,11 +12,13 @@
def media(buffer,href,textview):
"""render media tags"""
- buffer.insert(buffer.get_end_iter(), "\n")
+ buffer.insert(buffer.get_end_iter(), "\n")
+
#insert image
image = gtk.Image()
image.set_from_file(href)
buffer.insert_pixbuf(buffer.get_end_iter(), image.get_pixbuf())
textview.height += image.get_pixbuf().get_height()
+
#start the new tag in a new line
- buffer.insert(buffer.get_end_iter(), "\n")
\ No newline at end of file
+ buffer.insert(buffer.get_end_iter(), "\n")
Modified: trunk/src/foiegras/buffer/block_handler.py
==============================================================================
--- trunk/src/foiegras/buffer/block_handler.py (original)
+++ trunk/src/foiegras/buffer/block_handler.py Tue Jan 29 07:37:50 2008
@@ -13,31 +13,38 @@
"""
#on tag start signal from xmlparser
if tag_start is True:
- #parent is the main text view
+ # parent is the main text view
parent = parser.main_buffer.main_textview
- #temp_buffer is the current buffer
+
+ # temp_buffer is the current buffer
parser.temp_buffer = gtk.TextBuffer( parser.main_buffer.get_tag_table() )
- #child is the new inner text view
+
+ # child is the new inner text view
child = textview.MallardTextView(parser.temp_buffer)
child.set_wrap_mode(gtk.WRAP_CHAR)
child.show()
- #if no itme in innder_textviews list parent = main_buffer
- #else choose the innermost buffer from innder_textviews list
+
+ # if no itme in innder_textviews list parent = main_buffer
+ # else choose the innermost buffer from innder_textviews list
if parser.main_buffer.inner_textviews:
parent = parser.main_buffer.inner_textviews[len(parser.main_buffer.inner_textviews)-1]
- #if parent is a block container
- #add the previous block's height to get the total heigh
+
+ # if parent is a block container
+ # add the previous block's height to get the total heigh
if parent.is_block_container:
parent.block_tag_length = parser.temp_block_height
parser.temp_block_height = 0
- #the parent tag is a block container
+
+ # the parent tag is a block container
parent.is_block_container = True
- #if width and height is defined in the tag, request a set_size
+
+ # if width and height is defined in the tag, request a set_size
if "width" and "height" in parser.main_buffer.tag_details[element].keys():
width = parser.main_buffer.tag_details[element]["width"]
height = parser.main_buffer.tag_details[element]["height"]
child.set_size_request(int(width),int(height))
- #if background is defined in the tag
+
+ # if background is defined in the tag
if "background" in parser.main_buffer.tag_details[element].keys():
try:
color = parser.main_buffer.tag_details[element]["background"]
@@ -46,10 +53,11 @@
print "Color is not recognizable"
exit()
- #get the text iter to position a new textview
+ # get the text iter to position a new textview
iter = parent.get_buffer().get_end_iter()
anchor = parent.get_buffer().create_child_anchor(iter)
- #if a border is defined use a frame
+
+ # if a border is defined use a frame
if parser.main_buffer.tag_details[element]["border"] != 0:
frame = gtk.Frame()
frame.add(child)
@@ -61,26 +69,29 @@
else:
parent.add_child_at_anchor(child,anchor)
- #add the new inner textview to the list
+ # add the new inner textview to the list
parser.main_buffer.inner_textviews.insert(len(parser.main_buffer.inner_textviews),child)
- #retreive the text iter of current focused text view
+
+ # retreive the text iter of current focused text view
iter1 = parser.temp_buffer.get_end_iter()
- #shows the tag if show_tags is true
+
+ # shows the tag if show_tags is true
if parser.show_tags:
parser.temp_buffer.insert_with_tags_by_name(iter1,"\n<"+tag+">\n", parser.main_buffer.tag_details["mal_tag"]["tag"] )
else:
parser.temp_buffer.insert_with_tags_by_name(iter1,"\n" )
- #on tag end signal from xmlparser
+ # on tag end signal from xmlparser
else:
- iter1 = parser.temp_buffer.get_end_iter()
- #shows the tag if show_tags is true
+ iter1 = parser.temp_buffer.get_end_iter()
+
+ # show the tag if show_tags is true
if parser.show_tags:
parser.temp_buffer.insert_with_tags_by_name(iter1,"\n</"+element+">\n", parser.main_buffer.tag_details["mal_tag"]["tag"] )
elif parser.show_tags is False:
parser.temp_buffer.insert_with_tags_by_name(iter1,"\n" )
- #change the focus to an outer textview
+ # change the focus to an outer textview
if parser.main_buffer.inner_textviews:
previous_textview = parser.main_buffer.inner_textviews.pop()
Modified: trunk/src/foiegras/buffer/buffer.py
==============================================================================
--- trunk/src/foiegras/buffer/buffer.py (original)
+++ trunk/src/foiegras/buffer/buffer.py Tue Jan 29 07:37:50 2008
@@ -17,12 +17,15 @@
#styles are respective tags are stored in this dict()
self.tag_details = dict()
self.inner_textviews = []
- self.main_textview = main_view
+ self.main_textview = main_view
+
#self.window = main.window
self.readTags()
self.read_page(show_tags=False)
#self.create_tag("em",weight = pango.WEIGHT_BOLD, foreground = "orange", style = pango.STYLE_ITALIC)
+
print "Len of inner: "+str(len(self.inner_textviews))
+
for x in self.inner_textviews:
print "Showing inner"
x.show_all()
Modified: trunk/src/foiegras/buffer/table_handler.py
==============================================================================
--- trunk/src/foiegras/buffer/table_handler.py (original)
+++ trunk/src/foiegras/buffer/table_handler.py Tue Jan 29 07:37:50 2008
@@ -35,7 +35,8 @@
if parser.table_status == parser.table_cons["TABLE_DEFINED"]:
#create a list store for each of column in str type
liststore = gtk.ListStore(*[str for x in range(parser.num_columns)])
- liststore.append(parser.last_row)
+ liststore.append(parser.last_row)
+
#create a treeview from list store
parser.current_table = gtk.TreeView(liststore)
parser.current_table.set_headers_visible(False)
@@ -43,9 +44,11 @@
parser.current_table.set_border_width(4)
# create the TreeViewColumns to display the data
- columns = [gtk.TreeViewColumn() for x in range(parser.num_columns)]
+ columns = [gtk.TreeViewColumn() for x in range(parser.num_columns)]
+
# create a list of cellrenders
- cell_renders = [gtk.CellRendererText() for x in range(parser.num_columns)]
+ cell_renders = [gtk.CellRendererText() for x in range(parser.num_columns)]
+
# add columns to treeview
# add cells to columns
# set the cell attributes to the appropriate liststore column
@@ -54,23 +57,26 @@
columns[x].pack_start(cell_renders[x],True)
columns[x].set_attributes(cell_renders[x],text=x)
- #get the text iter to position a new textview
+ # get the text iter to position a new textview
iter = parser.temp_buffer.get_end_iter()
anchor = parser.temp_buffer.create_child_anchor(iter)
current_textview.add_child_at_anchor(parser.current_table,anchor)
parser.current_table.show_all()
- parser.table_status = parser.table_cons["TABLE_DRAWN"]
- #if table is drawn, add each row as table processes
+ parser.table_status = parser.table_cons["TABLE_DRAWN"]
+
+ # if table is drawn, add each row as table processes
elif parser.table_status == parser.table_cons["TABLE_DRAWN"]:
- #append data to the list store to create a new row
- parser.current_table.get_model().append(parser.last_row)
- #increase the number of columns by 1 when td tag closed
+ # append data to the list store to create a new row
+ parser.current_table.get_model().append(parser.last_row)
+
+ # increase the number of columns by 1 when td tag closed
elif element == "td":
- parser.num_columns += 1
- #close table tag and status of table
+ parser.num_columns += 1
+
+ # close table tag and status of table
elif element == "table":
parser.table_status = parser.table_cons["NO_TABLE"]
width,height = parser.current_table.size_request()
parser.temp_block_height += height
-
\ No newline at end of file
+
Modified: trunk/src/foiegras/buffer/tagparser.py
==============================================================================
--- trunk/src/foiegras/buffer/tagparser.py (original)
+++ trunk/src/foiegras/buffer/tagparser.py Tue Jan 29 07:37:50 2008
@@ -15,26 +15,32 @@
def start_element(self,name,attrs):
"""whan a tag start occurse parser callse this handler"""
if name == "tag":
- #keep track of the parent tag
- self.tags_stack.append(attrs["name"])
- #keep track of last attribut passed
- #for the use of char_data function
+ # keep track of the parent tag
+ self.tags_stack.append(attrs["name"])
+
+ # keep track of last attribut passed
+ # for the use of char_data function
self.last_attrib = None
- #keep track of attribute list
- #for a parent tag
+
+ # keep track of attribute list
+ # for a parent tag
self.attr_list = {}
else:
- self.last_attrib = name.strip()
- #avoide duplicates
+ self.last_attrib = name.strip()
+
+ # avoid duplicates
if "name" in attrs and attrs["name"] not in self.buffer.tag_details:
name = attrs["name"]
self.buffer.tag_details[name] = attrs
+
if attrs["type"] != "special":
styles = eval( "dict(" + self.buffer.tag_details[name]["style"] + ")" )
else:
styles = {}
- #creates a tag in text_tag_table of the buffer
+
+ #creats a tag in text_tag_table of the buffer
self.buffer.create_tag("tag"+ str(self.tag_count),**styles )
+
#put the name of the tag in dict
self.buffer.tag_details[name]["tag"]= "tag"+ str(self.tag_count)
self.tag_count += 1
@@ -54,11 +60,13 @@
def __init__(self,buffer,page):
self.tag_count = 0;
- self.buffer = buffer
+ self.buffer = buffer
+
#track tag attributes
self.attr_list = {}
self.tags_stack = []
self.last_attrib = None
+
#creating a xmlparser
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = self.start_element
Modified: trunk/src/foiegras/buffer/xmlparser.py
==============================================================================
--- trunk/src/foiegras/buffer/xmlparser.py (original)
+++ trunk/src/foiegras/buffer/xmlparser.py Tue Jan 29 07:37:50 2008
@@ -15,16 +15,18 @@
Known tags are noted in orange
unknown tags are noted in green
"""
- #keeps the current loaded tags(eg: tag0, tag1, ...) and elements(eg: em, code,..)
+ # keeps the current loaded tags(eg: tag0, tag1, ...) and elements(eg: em, code,..)
tag_stack, elements = [], []
show_tags = False
- temp_block_height = 0
- #table variables
+ temp_block_height = 0
+
+ # table variables
current_table = None #keeps track of the current table
- ##Table constraints
- #NO_TABLE = No table tag is found
- #TABLE_FOUND = Table tag is found and collecting info about the table to draw the table
- #TABLE_DRAWN = Table tag is closed and table is fully drawn
+
+ ## Table constraints
+ # NO_TABLE = No table tag is found
+ # TABLE_FOUND = Table tag is found and collecting info about the table to draw the table
+ # TABLE_DRAWN = Table tag is closed and table is fully drawn
table_cons = {"NO_TABLE":0, "TABLE_DEFINED":1, "TABLE_DRAWN":2} #table constraints
table_status = table_cons["NO_TABLE"] #table status when parsing the document
num_columns = 0;
@@ -52,18 +54,21 @@
"""
whan a tag start occurse parser callse this handler
"""
- #create sentence using tag+attribute
+ # create sentence using tag+attribute
tag = name
if len(attrs) != 0 :
for k, v in attrs.iteritems():
- tag += " " + k + " = \" " + v + "\" "
- #if parsed tag is in the valid tag list (for known tags)
- if name in self.main_buffer.tag_details.keys():
- #add parsed tag to tag stack
- #at a given moment tag stack holds the tags until the current tag
+ tag += " " + k + " = \" " + v + "\" "
+
+ # if parsed tag is in the valid tag list (for known tags)
+ if name in self.main_buffer.tag_details.keys():
+
+ # add parsed tag to tag stack
+ # at a given moment tag stack holds the tags until the current tag
self.tag_stack.append(self.main_buffer.tag_details[name]["tag"])
- self.elements.append(name)
- #handling control according to the tag's statues-block or inline
+ self.elements.append(name)
+
+ # handling control according to the tag's statues-block or inline
if self.main_buffer.tag_details[name]["type"] == "table":
table_handler.handler(self, name, attrs, True, tag)
elif self.main_buffer.tag_details[name]["type"] == "block":
@@ -74,28 +79,29 @@
self.special_handler(name, attrs, True, tag)
- #choose the current focused text view
+ # choose the current focused text view
if self.main_buffer.inner_textviews:
current_textview = self.main_buffer.inner_textviews[len(self.main_buffer.inner_textviews)-1]
else:
current_textview = self.main_buffer.main_textview
- #validate tag attributes
+ # validate tag attributes
try:
- #check validity of attributes
+ # check validity of attributes
attribute_handler.attribute_handler(name, self.temp_buffer, self.main_buffer.tag_details[name]["attribs"], attrs, current_textview)
except KeyError, msg:
- #occur in an invalid key exception
+ # occur in an invalid key exception
print "No such tag as", msg
exit()
except attribute_handler.InvlidAttribute, msg:
- #occur in invalid value exception
+ # occur in invalid value exception
print msg
exit()
except Exception, msg:
print "Error:", msg
- exit()
- #for unknown tags
+ exit()
+
+ # for unknown tags
else:
print "Additional"
iter1 = self.temp_buffer.get_end_iter()
@@ -131,8 +137,8 @@
iter1 = self.temp_buffer.get_end_iter()
self.temp_buffer.insert_with_tags_by_name(iter1, data, *self.tag_stack)
else:
- #if a new column comes, append the column data to the array
- #which will be later added to the liststore of the table
+ # if a new column comes, append the column data to the array
+ # which will be later added to the liststore of the table
if self.last_row.__len__() < 4 and data.strip() != "":
self.last_row.append( data )
@@ -150,22 +156,24 @@
p.CharacterDataHandler = self.char_data
if buffer.__class__.__name__ == "MallardBuffer" :
- #main_buffer is the outmost textbuffer and the
- #buffer of main textview.
- #temp_buffer keeps current focused inner text buffer
+ # main_buffer is the outmost textbuffer and the
+ # buffer of main textview.
+ # temp_buffer keeps current focused inner text buffer
self.temp_buffer = self.main_buffer = buffer
self.x, self.y = 400, 10
+
#read the text in buffer
iter1, iter2 = self.main_buffer.get_bounds()
page = self.main_buffer.get_text(iter1, iter2)
#format the buffer
self.main_buffer.set_text("")
- #self.set_show_tags(False)
+ #self.set_show_tags(False)
+
try:
p.Parse(page)
except xml.parsers.expat.ExpatError, msg:
print "Foiegras Error: ", msg
- exit()
+ exit()
print "Title: "+str(self.title)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]