gyrus r326 - in branches/gyrus-python: . src



Author: avaldes
Date: Tue Mar  4 14:15:03 2008
New Revision: 326
URL: http://svn.gnome.org/viewvc/gyrus?rev=326&view=rev

Log:
M    AUTHORS
M    src/gyrus.py
M    src/gyrus_constant.py
M    src/gyrus_print.py
M    ChangeLog
M    setup.py


Modified:
   branches/gyrus-python/AUTHORS
   branches/gyrus-python/ChangeLog
   branches/gyrus-python/setup.py
   branches/gyrus-python/src/gyrus.py
   branches/gyrus-python/src/gyrus_constant.py
   branches/gyrus-python/src/gyrus_print.py

Modified: branches/gyrus-python/AUTHORS
==============================================================================
--- branches/gyrus-python/AUTHORS	(original)
+++ branches/gyrus-python/AUTHORS	Tue Mar  4 14:15:03 2008
@@ -1 +1,2 @@
 Alejandro ValdÃs Jimenez <avaldes utalca cl>
+Francisco Rojas <frojas alumnos utalca cl>

Modified: branches/gyrus-python/setup.py
==============================================================================
--- branches/gyrus-python/setup.py	(original)
+++ branches/gyrus-python/setup.py	Tue Mar  4 14:15:03 2008
@@ -3,7 +3,7 @@
 from distutils.core import setup
 
 setup(name         = 'gyrus.py',
-	version      = '0.4',
+	version      = '0.4.1',
         description  = 'GNOME Cyrus/IMAP Administrator',
 	author       = 'Alejandro Valdes Jimenez',
 	author_email = '<avaldes utalca cl>',

Modified: branches/gyrus-python/src/gyrus.py
==============================================================================
--- branches/gyrus-python/src/gyrus.py	(original)
+++ branches/gyrus-python/src/gyrus.py	Tue Mar  4 14:15:03 2008
@@ -181,7 +181,7 @@
                 self.about.show()
 
         def create_about_dialog (self):
-                authors = ('Alejandro Valdes Jimenez','')
+                authors = ('Alejandro Valdes Jimenez','Francisco Rojas')
                 translator_credits = ('Alejandro Valdes Jimenez')
                 logo =  gtk.gdk.pixbuf_new_from_file (LOGO)
 
@@ -309,9 +309,6 @@
 		admin.treeview_acl.show()
 		admin.table_page.show()
 
-		page = self.notebook.append_page(admin.table_page,hbox_b)
-		self.notebook.set_current_page(page)
-
 		if admin.session_tls:
 			admin.image_secure.set_from_stock (gtk.STOCK_DIALOG_AUTHENTICATION,gtk.ICON_SIZE_BUTTON)
 			admin.image_secure.show()
@@ -321,6 +318,10 @@
 		# add new table at main array
 		table = admin.table_page
 		self.imap_server[table] = admin
+		
+		#add new page to notebook
+		page = self.notebook.append_page(admin.table_page,hbox_b)
+		self.notebook.set_current_page(page)
 
 	
 	def get_current_gyrus_admin (self):
@@ -333,7 +334,7 @@
 
 	def on_report_action (self,action):
 		admin = self.get_current_gyrus_admin()
-		gyrus_print.show_dialog_print(admin)
+		report = gyrus_print.GyrusReport(admin)
 
 
 	def on_find_action (self,action):

Modified: branches/gyrus-python/src/gyrus_constant.py
==============================================================================
--- branches/gyrus-python/src/gyrus_constant.py	(original)
+++ branches/gyrus-python/src/gyrus_constant.py	Tue Mar  4 14:15:03 2008
@@ -12,7 +12,7 @@
 	DIRLOCALE = join(os.path.abspath(os.curdir),'locale')
 
 APPNAME ="gyrus"
-VERSION = "0.4"
+VERSION = "0.4.1"
 
 # width and high of main window
 DEFAULT_WIDTH = 750

Modified: branches/gyrus-python/src/gyrus_print.py
==============================================================================
--- branches/gyrus-python/src/gyrus_print.py	(original)
+++ branches/gyrus-python/src/gyrus_print.py	Tue Mar  4 14:15:03 2008
@@ -5,7 +5,10 @@
 import cairo
 import pango
 import gettext
+import datetime
 import gyrus_admin_mailbox
+import gobject
+from math import ceil
 
 from gyrus_constant import *
 
@@ -16,90 +19,139 @@
 gtk.glade.bindtextdomain(APPNAME,DIRLOCALE)
 gtk.glade.textdomain(APPNAME)
 
-def show_dialog_print(admin):
-	settings = gtk.PrintSettings()
-
-	op = gtk.PrintOperation()
-	op.set_print_settings(settings)
-	op.set_unit(gtk.UNIT_MM)
-
-	op.connect("begin_print",begin_print,admin)
-	op.connect("draw_page",draw_page,admin)
-
-	response = op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG)
+MAX_USER_PAGE = 60
+SPACE_PER_LINE = 4	
+PAGE_POS_COLUMN_2 = 40
+PAGE_POS_COLUMN_3 = 80
+PAGE_POS_COLUMN_4 = 120
+PAGE_POS_COLUMN_5 = 150
+		
+
+
+class GyrusReport:
+	def __init__(self, admin):
+		self.admin = admin
+		self.settings = gtk.PrintSettings()
+		self.op = gtk.PrintOperation()
+		self.n_page = 0
+		
+		# signals
+		
+		self.op.connect('begin_print', self.begin_print, self.admin)
+		self.op.connect('draw_page', self.draw_page, self.admin)
+		
+		self.do_print()
 	
-	if response == gtk.PRINT_OPERATION_RESULT_APPLY:
-		settings = op.get_print_settings()
-
+	def do_print(self):		
+		# set some values
+		self.op.set_print_settings(self.settings)
+		self.op.set_unit(gtk.UNIT_MM)
+
+		try:
+			response = self.op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG)
+		except gobject.GError, ex:
+			error_dialog = gtk.MessageDialog(None,
+					 gtk.DIALOG_DESTROY_WITH_PARENT,
+					 gtk._MESSAGE_ERROR,
+					 gtk.BUTTONS_CLOSE,
+					 ("Error printing file:\n%s" % str(ex)))
+			error_dialog.connect("response", gtk.Widget.destroy)
+			error_dialog.show()
+	
+		if response == gtk.PRINT_OPERATION_RESULT_APPLY:
+			settings = self.op.get_print_settings()
 
-def begin_print(operation,context,admin):
-	operation.set_n_pages(5)
 
+	def begin_print(self,operation,context,admin):
+		model = admin.treeview_users.get_model()
+		n = float(len(model))
+		self.n_pages =int (ceil (n/MAX_USER_PAGE))
+		operation.set_n_pages(self.n_pages)
+
+	def draw_page(self,operation,context,page,admin):
+		
+		cairo_context = context.get_cairo_context()
+		width = context.get_width()
+		page_setup = context.get_page_setup()
+		left_margin = page_setup.get_left_margin(gtk.UNIT_MM)
+		right_margin = page_setup.get_right_margin(gtk.UNIT_MM)
+		top_margin = page_setup.get_top_margin(gtk.UNIT_MM)
+		bottom_margin = page_setup.get_bottom_margin(gtk.UNIT_MM)
+		page_width = page_setup.get_page_width(gtk.UNIT_MM)
+		page_height = page_setup.get_page_height(gtk.UNIT_MM)
+		x = left_margin
+
+		layout = context.create_pango_layout()
+		desc = pango.FontDescription("Sans 10") 
+		layout.set_font_description(desc) 
+
+		# print header
+		self.print_header(cairo_context,layout,left_margin,page_width,right_margin,top_margin)
+
+		model = admin.treeview_users.get_model()
+		if(len(model)==0):
+			return
+		
+		y = top_margin + (SPACE_PER_LINE * 2)
+		
+		index = ( page * MAX_USER_PAGE ) 
+		end = index + MAX_USER_PAGE
+		
+		if end >= len(model):
+			end = len(model)-1
+			
+		iter = model.get_iter(index)
+		count = index
+		
+		while (iter and count < end):
+			usr = model.get(iter,COLUMN_MAILBOX)[0]
+			res,msg,free,quota = gyrus_admin_mailbox.get_quota_of_mailbox (admin,usr)
+		
+			self.print_string(cairo_context,layout,x,y,usr)
+			self.print_string(cairo_context,layout,x + PAGE_POS_COLUMN_2,y,str(quota))
+			self.print_string(cairo_context,layout,x + PAGE_POS_COLUMN_3,y,str(quota-free))
+			self.print_string(cairo_context,layout,x + PAGE_POS_COLUMN_4,y,str(free))
+			if (quota == 0):
+				self.print_string(cairo_context,layout,x + PAGE_POS_COLUMN_5,y, str('%     0')) 
+			else:
+				self.print_string(cairo_context,layout,x + PAGE_POS_COLUMN_5,y, str('%% %3.0f' % ((free*1.0/quota)*100) )) 
+			y = y + SPACE_PER_LINE
+			
+			iter = model.iter_next(iter)
+			count = count + 1 
+		# print footer
+		self.print_footer(cairo_context,layout,x,page_width,right_margin,page_height,page+1)
+
+		
+		
+	def print_line(self,cairo_context,width_line,x,width,y):
+		cairo_context.move_to(x,y)
+		cairo_context.line_to(width,y)
+		cairo_context.set_line_join(cairo.LINE_JOIN_ROUND)
+		cairo_context.set_line_width(width_line)
+		cairo_context.stroke()
+
+	def print_string(self,cairo_context,layout,x,y,string):
+		cairo_context.move_to(x,y)
+		layout.set_text(string)
+		cairo_context.show_layout(layout) 
+
+	def print_header(self,cairo_context,layout,left_margin,page_width,right_margin,top_margin):		
+		self.print_line(cairo_context,WIDTH_LINE,left_margin,page_width - right_margin,top_margin)
+		self.print_string(cairo_context,layout,left_margin,top_margin + WIDTH_LINE,_("Mailbox"))
+		self.print_string(cairo_context,layout,left_margin + PAGE_POS_COLUMN_2,top_margin + WIDTH_LINE,_("Quota assigned"))
+		self.print_string(cairo_context,layout,left_margin + PAGE_POS_COLUMN_3,top_margin + WIDTH_LINE,_("Quota used"))
+		self.print_string(cairo_context,layout,left_margin + PAGE_POS_COLUMN_4,top_margin + WIDTH_LINE,_("Quota free"))
+		self.print_string(cairo_context,layout,left_margin + PAGE_POS_COLUMN_5,top_margin + WIDTH_LINE,_("Percentage"))
+		self.print_line(cairo_context,WIDTH_LINE,left_margin,page_width - right_margin,top_margin + (WIDTH_LINE *2)+ SPACE_PER_LINE)
+		
+	def print_footer(self,cairo_context,layout,x,page_width,right_margin,page_height,page):
+		now= datetime.datetime.now()
+		date = now.strftime(_('%H:%M:%S %m-%d-%Y'))
+		self.print_line(cairo_context,WIDTH_LINE,x,page_width - right_margin,page_height-10)
+		self.print_string(cairo_context,layout,x,page_height - (SPACE_PER_LINE * 2),date)
+		self.print_string(cairo_context,layout,x + PAGE_POS_COLUMN_5, page_height - (SPACE_PER_LINE * 2),_("Page %d" %page))
+		
+		
+		
 
-def draw_page(operation,context,page,admin):
-	print page
-
-	cairo_context = context.get_cairo_context()
-	width = context.get_width()
-
-	page_setup = context.get_page_setup()
-	left_margin = page_setup.get_left_margin(gtk.UNIT_MM)
-	right_margin = page_setup.get_right_margin(gtk.UNIT_MM)
-	top_margin = page_setup.get_top_margin(gtk.UNIT_MM)
-	bottom_margin = page_setup.get_bottom_margin(gtk.UNIT_MM)
-	page_width = page_setup.get_page_width(gtk.UNIT_MM)
-	page_height = page_setup.get_page_height(gtk.UNIT_MM)
-	x = left_margin
-
-	layout = context.create_pango_layout()
-	desc = pango.FontDescription("Sans 10") 
-	layout.set_font_description(desc) 
-
-	# print header
-	print_header(cairo_context,layout,x,page_width,right_margin,top_margin)
-
-	model = admin.treeview_users.get_model()
-
-	yini = top_margin + 8
-	y = yini
-
-	iter = model.get_iter_first()
-	while iter:
-		mb = model.get(iter,COLUMN_MAILBOX)
-		res,msg,free,quota = gyrus_admin_mailbox.get_quota_of_mailbox (admin,mb[0])
-
-		print_string(cairo_context,layout,x,y,mb[0])
-		print_string(cairo_context,layout,x + 40,y,str(quota))
-		print_string(cairo_context,layout,x + 80,y,str(0))
-		print_string(cairo_context,layout,x + 120,y,str(free))
-		print_string(cairo_context,layout,x + 150,y,"%")
-
-		iter = model.iter_next(iter)
-		if iter:
-			y = y + 4
-
-			if y > page_height:
-				print_header(cairo_context,layout,x,page_width,right_margin,top_margin)
-				y = yini
-
-
-def print_line(cairo_context,width_line,x,width,y):
-	cairo_context.move_to(x,y)
-	cairo_context.line_to(width,y)
-	cairo_context.set_line_join(cairo.LINE_JOIN_ROUND)
-	cairo_context.set_line_width(width_line)
-	cairo_context.stroke()
-
-def print_string(cairo_context,layout,x,y,string):
-	cairo_context.move_to(x,y)
-	layout.set_text(string)
-	cairo_context.show_layout(layout) 
-
-def print_header(cairo_context,layout,x,page_width,right_margin,top_margin):
-	print_line(cairo_context,WIDTH_LINE,x,page_width - right_margin,top_margin)
-	print_string(cairo_context,layout,x,top_margin + 1,_("Mailbox"))
-	print_string(cairo_context,layout,x + 40,top_margin + 1,_("Quota assigned"))
-	print_string(cairo_context,layout,x + 80,top_margin + 1,_("Quota used"))
-	print_string(cairo_context,layout,x + 120,top_margin + 1,_("Quota free"))
-	print_string(cairo_context,layout,x + 150,top_margin + 1,_("Percentage"))
-	print_line(cairo_context,WIDTH_LINE,x,page_width - right_margin,top_margin + 6)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]