00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 from Koo.Common import Common
00029 import FormWidget
00030
00031 from PyQt4.QtCore import *
00032 from PyQt4.QtGui import *
00033 from PyQt4.uic import *
00034
00035 (AttachmentDialogUi, AttachmentDialogBase) = loadUiType( Common.uiPath('win_attach.ui') )
00036
00037 class AttachmentDialog(QMainWindow, AttachmentDialogUi):
00038
00039 def __init__(self, model, id, parent = None ):
00040 QMainWindow.__init__(self, parent)
00041 AttachmentDialogUi.__init__(self)
00042 self.setupUi( self )
00043
00044
00045 rect = QApplication.desktop().screenGeometry()
00046 centerh = rect.width() / 2
00047 centerv = rect.height() / 2
00048 self.setGeometry( centerh - self.width() / 2, centerv - self.height() / 2, self.width(), self.height() )
00049
00050 self.model = model
00051 self.id = id
00052
00053 context = {
00054 'default_res_model': self.model,
00055 'default_res_id': self.id,
00056 }
00057 self.form = FormWidget.FormWidget( 'ir.attachment', view_type=['tree','form'], domain=[('res_model','=',self.model), ('res_id', '=', self.id)], context=context)
00058 self.form.setAllowOpenInNewWindow( False )
00059
00060 self.layout = self.centralWidget().layout()
00061 self.layout.addWidget( self.form )
00062
00063
00064 size = self.form.sizeHint()
00065 self.setMinimumSize( size.width()+100, min(600, size.height()+25) )
00066 size = QApplication.desktop().availableGeometry( self ).size()
00067 size -= QSize( 50, 50 )
00068 self.setMaximumSize( size )
00069
00070
00071
00072
00073
00074
00075 self.actions = [ 'New', 'Save', 'Delete', 'Next', 'Previous', 'Switch' ]
00076 for x in self.actions:
00077 action = eval('self.action' + x)
00078 self.connect( action, SIGNAL('triggered()'), self.callChildView )
00079 self.connect( self.actionClose, SIGNAL('triggered()'), self.slotClose )
00080 self.updateEnabledActions()
00081
00082 def updateEnabledActions(self):
00083 for x in self.actions:
00084 action = eval( 'self.action' + x )
00085 action.setEnabled( x in self.form.handlers )
00086
00087 def callChildView( self ):
00088 o = self.sender()
00089 action = str( o.objectName() ).replace( 'action', '' )
00090 res = True
00091 if action in self.form.handlers:
00092 res = self.form.handlers[action]()
00093
00094 def slotClose( self ):
00095 if self.form.canClose():
00096 self.close()
00097
00098
00099
00100 self.deleteLater()
00101