Package Camelot :: Package camelot :: Package view :: Package controls :: Module view
[frames] | no frames]

Source Code for Module Camelot.camelot.view.controls.view

  1  #  ============================================================================ 
  2  # 
  3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved. 
  4  #  www.conceptive.be / project-camelot@conceptive.be 
  5  # 
  6  #  This file is part of the Camelot Library. 
  7  # 
  8  #  This file may be used under the terms of the GNU General Public 
  9  #  License version 2.0 as published by the Free Software Foundation 
 10  #  and appearing in the file LICENSE.GPL included in the packaging of 
 11  #  this file.  Please review the following information to ensure GNU 
 12  #  General Public Licensing requirements will be met: 
 13  #  http://www.trolltech.com/products/qt/opensource.html 
 14  # 
 15  #  If you are unsure which license is appropriate for your use, please 
 16  #  review the following information: 
 17  #  http://www.trolltech.com/products/qt/licensing.html or contact 
 18  #  project-camelot@conceptive.be. 
 19  # 
 20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 
 21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 
 22  # 
 23  #  For use of this library in commercial applications, please contact 
 24  #  project-camelot@conceptive.be 
 25  # 
 26  #  ============================================================================ 
 27   
 28  """Functionallity common to TableViews and FormViews 
 29  """ 
 30   
 31  from PyQt4 import QtCore, QtGui 
 32   
 33  from camelot.view.model_thread import post, gui_function, model_function 
34 35 -class AbstractView(QtGui.QWidget):
36 """A string used to format the title of the view :: 37 38 title_format = 'Movie rental overview' 39 40 .. attribute:: header_widget 41 42 The widget class to be used as a header in the table view:: 43 44 header_widget = None 45 """ 46 47 title_format = '' 48 header_widget = None 49 50 title_changed_signal = QtCore.SIGNAL('titleChanged(const QString&)') 51 52 @gui_function
53 - def change_title(self, new_title):
54 """Will emit the title_changed_signal""" 55 import sip 56 if not sip.isdeleted(self): 57 self.emit(self.title_changed_signal, unicode(new_title))
58 59 @model_function
60 - def to_html(self):
61 pass
62 63 @model_function
64 - def export_to_word(self):
68 69 @model_function
70 - def export_to_excel(self):
71 from camelot.view.export.excel import open_data_with_excel 72 title = self.getTitle() 73 columns = self.getColumns() 74 data = [d for d in self.getData()] 75 open_data_with_excel(title, columns, data)
76 77 @model_function
78 - def export_to_mail(self):
82
83 -class TabView(AbstractView):
84 """Class to combine multiple views in Tabs and let them behave as one view. This class can be 85 used when defining custom create_table_view methods on an ObjectAdmin class to group multiple 86 table views together in one view. 87 """ 88
89 - def __init__(self, parent, views=[], admin=None):
90 """ 91 :param views: a list of the views to combine 92 """ 93 AbstractView.__init__(self, parent) 94 layout = QtGui.QVBoxLayout() 95 if self.header_widget: 96 self.header = self.header_widget(self, admin) 97 else: 98 self.header = None 99 layout.addWidget(self.header) 100 self.tab_widget = QtGui.QTabWidget(self) 101 layout.addWidget(self.tab_widget) 102 self.setLayout(layout) 103 104 def get_views_and_titles(): 105 return [(view, view.get_title()) for view in views]
106 107 post(get_views_and_titles, self.set_views_and_titles ) 108 post(lambda:self.title_format, self.change_title )
109
110 - def set_views_and_titles(self, views_and_titles):
111 for view, title in views_and_titles: 112 self.tab_widget.addTab(view, title)
113
114 - def export_to_excel(self):
115 return self.tab_widget.currentWidget().export_to_excel()
116
117 - def export_to_word(self):
118 return self.tab_widget.currentWidget().export_to_word()
119
120 - def export_to_mail(self):
121 return self.tab_widget.currentWidget().export_to_mail()
122
123 - def to_html(self):
124 return self.tab_widget.currentWidget().to_html()
125