3 # GPytage save.py module
5 ############################################################################
6 # Copyright (C) 2008 by Kenneth Prugh #
9 # This program is free software; you can redistribute it and#or modify #
10 # it under the terms of the GNU General Public License as published by #
11 # the Free Software Foundation under version 2 of the license. #
13 # This program is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16 # GNU General Public License for more details. #
18 # You should have received a copy of the GNU General Public License #
19 # along with this program; if not, write to the #
20 # Free Software Foundation, Inc., #
21 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
22 ############################################################################
27 from helper
import reload
28 from config
import get_config_path
29 from window
import title
, window
, createMessageDialog
31 from leftpanel
import leftview
40 lists
= datastore
.lists
41 for name
,store
in lists
.iteritems():
43 if name
== store
[0][3]:#I'm a main file
48 datarow
= self
.assemblerow(row
)
50 self
.savefile(parent
, file, data
)
51 model
= leftview
.get_model()
52 model
.foreach(self
.findMatch
, name
)
53 else: #we have a subfile
54 parent
= store
[0][3] #main dir
58 datarow
= self
.assemblerow(row
)
60 self
.savefile(parent
, file, data
)
61 model
= leftview
.get_model()
62 model
.foreach(self
.findMatch
, name
)
64 #when a file is "blank" and a save is attempted it fails here. This should be the only case...
66 model
= leftview
.get_model()
67 model
.foreach(self
.findMatch
, name
)
68 piter
= model
.iter_parent(self
.fiter
)
71 parent
= model
.get_value(piter
, 0)
76 self
.savefile(parent
, name
, data
)
81 err
= ',\n'.join(self
.errors
)
82 message
= "The following files failed to save:\n\n%s. \n\nPossible causes may include insufficient privileges to write to these files." %err
83 createMessageDialog(None, gtk
.DIALOG_DESTROY_WITH_PARENT
, gtk
.MESSAGE_ERROR
, gtk
.BUTTONS_OK
, "Error Saving...", message
)
85 def assemblerow(self
, child
):
86 """ Assemble data columns for saving """
97 datarow
= text1
+ " " + text2
+ '\n'
100 def savefile(self
, parent
, file, data
):
101 """ Write data to file """
102 config_path
= get_config_path()
103 if parent
is None: #main file
105 f
=open(config_path
+ file, 'w')
110 self
.errors
.append("%s%s" % (config_path
, file))
114 f
=open(config_path
+ parent
+ '/' + file, 'w')
119 self
.errors
.append("%s%s/%s" %(config_path
, parent
, file))
122 def findMatch(self
, model
, path
, iter, user_data
):
123 if model
.get_value(iter, 0).strip('*') == user_data
:
124 model
.set_value(iter, 0, user_data
)