~ubuntu-branches/debian/stretch/bibus/stretch

« back to all changes in this revision

Viewing changes to .pc/wxpy30-changes.patch/OOo.py

  • Committer: Package Import Robot
  • Author(s): Jan Beyer
  • Date: 2014-09-02 21:54:07 UTC
  • mfrom: (4.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20140902215407-0002tj24epm8y6u8
Tags: 1.5.2-4
* Add a patch for compatibility with python-wxgtk3.0 (Closes: #758943)
  - Reworked patching bibOOo/bibOOoBase.py as separate patch
* Standards-Version 3.9.5 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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.
 
18
 
 
19
import BIB
 
20
import wx
 
21
 
 
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
 
24
import 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
 
34
#
 
35
# strings to be translated in your program
 
36
# by overwriting them
 
37
# in bibOOoBase
 
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")
 
45
# in bibOOoPlus
 
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)")
 
51
#
 
52
 
 
53
 
 
54
from bibOOo.bibOOoPlus import *
 
55
 
 
56
class bibusOOo(bibOOoPlus):
 
57
        def __init__(self,db):
 
58
                self.db = 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] )
 
61
 
 
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"""
 
67
                #
 
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
 
72
                for ref in self:
 
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)
 
83
                                if tmpId != None:
 
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
 
91
                return newKeys
 
92
 
 
93
        def finalize(self):
 
94
                msg = ProgressWin()
 
95
                try:
 
96
                        bibOOoPlus.finalize(self,msg.Update)
 
97
                        msg.Destroy()
 
98
                except bibOOo_IOError:
 
99
                        msg.Destroy()
 
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
 
102
                        try:
 
103
                                self.saveDoc()
 
104
                                self.finalize()
 
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)
 
107
                                if url == '':
 
108
                                        return
 
109
                                else:
 
110
                                        self.saveDoc(url)
 
111
                                        self.finalize()
 
112
        
 
113
        def updateRef(self):
 
114
                """We redefine messages since now we can use wxPython widgets"""
 
115
                bibOOoPlus.updateRef(self,messages = lambda x:wx.LogWarning(x))
 
116
 
 
117
class ProgressWin(wx.ProgressDialog):
 
118
        def __init__(self):
 
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)
 
120
 
 
121
        def Update(self,value,message):
 
122
                wx.ProgressDialog.Update(self,value*100,message)
 
123