1
# Copyright 2004,2005 Pierre Martineau <pmartino@users.sourceforge.net>
2
# This file is part of Bibus, a bibliographic database that can
3
# work together with OpenOffice.org to generate bibliographic indexes.
5
# Bibus is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# Bibus is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with Bibus; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22
# setting some values for bibus. Copied from BIBbase to bibOOo.CONST
23
# this is to propagate modifications made by the user in BIBbase to bibOOo.CONST
25
bibOOo.CONST.SEP = BIB.SEP
26
bibOOo.CONST.bibOOo_cit_baseCharStyleName = BIB.bibOOo_cit_baseCharStyleName # base style for citations
27
bibOOo.CONST.bibOOo_index_baseCharStyleName = BIB.bibOOo_index_baseCharStyleName # base style for bibliography index
28
bibOOo.CONST.BIB_TYPE = BIB.BIB_TYPE
29
bibOOo.CONST.BIBLIOGRAPHIC_TYPE = BIB.BIBLIOGRAPHIC_TYPE
30
bibOOo.CONST.BIB_FIELDS = BIB.BIB_FIELDS[1:-1]
31
bibOOo.CONST.BIBLIOGRAPHIC_FIELDS = {}
32
for i in range(len(bibOOo.CONST.BIB_FIELDS)):
33
bibOOo.CONST.BIBLIOGRAPHIC_FIELDS[bibOOo.CONST.BIB_FIELDS[i]] = i
35
# strings to be translated in your program
38
bibOOo.CONST.msg1 = _("Making a copy of the current document ...")
39
bibOOo.CONST.msg2 = _("Creating styles ...")
40
bibOOo.CONST.msg3 = _("Updating references ...")
41
bibOOo.CONST.msg4 = _("Updating index ...")
42
bibOOo.CONST.msg5 = _("Deleting old index and citations ...")
43
bibOOo.CONST.msg6 = _("Done")
44
bibOOo.CONST.msg7 = _("Inserting citations in text")
46
bibOOo.CONST.msg8 = _("Formating citations ...")
47
bibOOo.CONST.msg9 = _("Looking for duplicates ...")
48
bibOOo.CONST.msg10 = _("Solving duplicates ... (%s series of duplicates)")
49
bibOOo.CONST.msg11 = _("Fusing citations ...")
50
bibOOo.CONST.msg12 = _("Inserting citations in text (%s ranges)")
54
from bibOOo.bibOOoPlus import *
56
class bibusOOo(bibOOoPlus):
57
def __init__(self,db):
59
bibOOoPlus.__init__(self,BIB.FORMAT_DICO,BIB.OO_CON_TYPE,BIB.OO_HOST,BIB.OO_PORT,BIB.OO_PIPE,\
60
lambda identifier: db.getRefFromIdentifier(identifier,collist=BIB.BIB_FIELDS[1:-1])[0] )
62
def storeUnknownRef(self):
63
"""Store in the database the unknown references found in the document
64
return a list of the stored Identifiers
65
The identifiers may be changed in order to be unique in the db
66
and they are updated accordingly in the current doc"""
68
newKeys = [] # list of the captured identifiers for return
69
old2New = {} # dictionary that give for old Identifier the New Identifier used in the db if changed
70
refs2 = [] # list of refs that cannot be stored directly
71
# we first try to store the refs that we can store without modifying the identifiers
73
identifier = ref.Identifier
74
if identifier in old2New.keys():
75
self.__changeIdentifier(ref,old2New[identifier]) # change to the new identifier in the text if already done for the
76
continue # same identifier
77
ref_id = self.db.getRefFromIdentifier(identifier,('Id',))
78
if not ref_id: # the identifier is not in the database => we must store it
79
tmpref = [ getattr(ref,field) for field in OO_BIB_FIELDS ]
80
tmpref.insert(0,None) # unknow Id
81
tmpref.append( '' ) # no Abstract in OOo
82
tmpId = self.db.writeRef(tmpref)
84
newIdentifier = self.db.getRef(tmpId,('Identifier',))[0][0]
85
if newIdentifier != identifier: # the identifier was in the db and dbBibBase.py has changed it
86
old2New[identifier] = newIdentifier
87
ref.Identifier = newIdentifier # change to the new identifier in the text
88
newKeys.append(newIdentifier)
89
if self.bib != None: self.updateIndex() # we update to take into account the new identifiers
90
else: self.model.getTextFields().refresh() # otherwise, just refresh the fields
96
bibOOoPlus.finalize(self,msg.Update)
98
except bibOOo_IOError:
100
ret = wx.MessageBox(_("You must first save the current document before using this function.\n Should I save it and proceed?"),_("Warning"),style = wx.YES_NO|wx.ICON_ERROR)
101
if ret == wx.NO: return
105
except bibOOo_IOError:
106
url = wx.FileSelector('Save as...',default_extension='odt',wildcard="%s (*.odt)|*.odt|%s (*.sxw)|*.sxw|%s (*.*)|*.*"%(_("OpenDocument Text"),_("OpenOffice.org Text Document"), _("All files")),flags=wx.SAVE|wx.OVERWRITE_PROMPT)
114
"""We redefine messages since now we can use wxPython widgets"""
115
bibOOoPlus.updateRef(self,messages = lambda x:wx.LogWarning(x))
117
class ProgressWin(wx.ProgressDialog):
119
wx.ProgressDialog.__init__(self,_('Finalize'),_('Finalizing the current document'),maximum=100,style = wx.PD_AUTO_HIDE|wx.PD_APP_MODAL|wx.PD_ELAPSED_TIME|wx.PD_ESTIMATED_TIME)
121
def Update(self,value,message):
122
wx.ProgressDialog.Update(self,value*100,message)