Modify __init__ and close method to deal with registration process
This commit is contained in:
@ -16,13 +16,17 @@ from .dms cimport __OBIDMS_VIEW_CLASS__
|
||||
|
||||
from obitools3.utils cimport tobytes, \
|
||||
bytes2str
|
||||
|
||||
|
||||
from ..object cimport OBIObjectClosedInstance
|
||||
|
||||
|
||||
cdef class View :
|
||||
cdef class View(OBIObject) :
|
||||
|
||||
|
||||
def __init__(self,dms,int __internalCall__):
|
||||
|
||||
OBIObject.__init__(self)
|
||||
|
||||
if __internalCall__!=987654:
|
||||
raise RuntimeError('OBIView constructor cannot be called directly')
|
||||
|
||||
@ -55,6 +59,8 @@ cdef class View :
|
||||
% (str(self.name),
|
||||
bytes2str(view_name_b))
|
||||
)
|
||||
|
||||
self._dms.register(view)
|
||||
|
||||
return view
|
||||
|
||||
@ -85,6 +91,8 @@ cdef class View :
|
||||
message = "Error : Cannot create view %s" % bytes2str(view_name_b)
|
||||
raise RuntimeError(message)
|
||||
|
||||
dms.register(view)
|
||||
|
||||
return view
|
||||
|
||||
@staticmethod
|
||||
@ -101,16 +109,25 @@ cdef class View :
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot open view %s" % bytes2str(view_name_b))
|
||||
|
||||
dms.register(view)
|
||||
|
||||
return view
|
||||
|
||||
def close(self):
|
||||
if (self._pointer != NULL):
|
||||
cdef Obiview_p pointer = self._pointer
|
||||
|
||||
if (pointer != NULL):
|
||||
self._dms.unregister(self)
|
||||
OBIObject.close(self)
|
||||
|
||||
self._pointer = NULL
|
||||
|
||||
if obi_save_and_close_view(self._pointer) < 0 :
|
||||
raise Exception("Problem closing view %s" %
|
||||
bytes2str(self.name))
|
||||
else:
|
||||
raise OBIObjectClosedInstance()
|
||||
|
||||
def __dealloc__(self):
|
||||
self.close()
|
||||
|
||||
def __repr__(self) :
|
||||
cdef str s = "{name:s}\n{comments:s}\n{line_count:d} lines\n".format(name = str(self.name),
|
||||
|
Reference in New Issue
Block a user