3 # GPytage subfile 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 ############################################################################
24 import pygtk
; pygtk
.require("2.0")
28 from window
import title
, unsavedDialog
, window
29 from save
import SaveFile
30 from helper
import folder_scan
, folder_walk
31 from config
import get_config_path
, config_files
34 """ Spawn the new subfile dialog """
35 gladefile
= "glade/newsubfile.glade"
36 wTree
= gtk
.glade
.XML(gladefile
)
37 newd
= wTree
.get_widget("newfile")
38 dirs
,files
= folder_scan()
39 cb
= wTree
.get_widget("ncb")
41 model
= gtk
.ListStore(str)
43 cell
= gtk
.CellRendererText()
45 cb
.add_attribute(cell
, 'text', 0)
52 ftext
= wTree
.get_widget("aentry")
54 addb
= wTree
.get_widget("addb")
55 closeb
= wTree
.get_widget("closeb")
57 addb
.connect("clicked", add_subfile
, cb
, ftext
, newd
, window
)
58 closeb
.connect("clicked", close_subfile
, newd
)
61 sbar
= wTree
.get_widget("sbar")
62 smsg
= sbar
.get_context_id("standard message")
64 sbar
.push(smsg
, "Error: No parent directories found")
70 def close_subfile(arg
, newd
):
71 """ Close subfile dialog """
74 def add_subfile(arg
, cb
, ftext
, newd
, window
):
75 model
= cb
.get_model()
76 index
= cb
.get_active()
77 if index
>= 0: # prevent index errors
78 # next line gets an index error when trying to add a subfile to a non existent sets dir. (Or if selection is blank)
79 cbselection
= model
[index
][0] #current selection
80 ftextselection
= ftext
.get_text()
82 if len(ftextselection
):
83 addToMemory(cbselection
, ftextselection
)
86 def addToMemory(parent
, filename
):
87 """ Adds new subfile to memory """
88 datastore
.datastore
.foreach(findMatch
, [parent
, filename
])
89 msg
= '#This file was created by GPytage'
90 datastore
.lists
[filename
] = gtk
.ListStore(str, str, bool, str)
91 datastore
.lists
[filename
].append([msg
, None, True, parent
]) #rightpanel stuff
94 def findMatch(model
, path
, iter, user_data
):
95 print user_data
[0], user_data
[1]
96 print model
.get_value(iter, 0).strip('*')
97 if model
.get_value(iter, 0).strip('*') == user_data
[0]:
98 edited_file
= "*%s" % user_data
[1]
99 model
.append(iter, [edited_file
, None, False, user_data
[0]])
102 """ Spawn the convert file dialog """
103 gladefile
= "glade/convertfile.glade"
104 wTree
= gtk
.glade
.XML(gladefile
)
105 convertd
= wTree
.get_widget("convertd")
107 dirs
,files
= folder_scan()
108 cb
= wTree
.get_widget("ncb")
110 model
= gtk
.ListStore(str)
112 cell
= gtk
.CellRendererText()
114 cb
.add_attribute(cell
, 'text', 0)
120 ftext
= wTree
.get_widget("aentry")
122 convertb
= wTree
.get_widget("convertb")
123 closeb
= wTree
.get_widget("closeb")
125 convertb
.connect("clicked", convertFile
, cb
, ftext
, convertd
, window
)
126 closeb
.connect("clicked", close_subfile
, convertd
)
129 sbar
= wTree
.get_widget("sbar")
130 smsg
= sbar
.get_context_id("standard message")
132 sbar
.push(smsg
, "Error: No files detected")
138 def convertFile(arg
, cb
, ftext
, convertd
, window
):
139 """ Convert Top level file to directory with subfile """
140 #Currently I don't see how to do such a change "in memory", so the change must be done live and probably call the evil reload() nuke
141 model
= cb
.get_model()
142 index
= cb
.get_active()
143 if index
>= 0: # prevent index errors
144 cbselection
= model
[index
][0] #current selected item
145 ftextselection
= ftext
.get_text()
146 if window
.get_title() != "GPytage":
147 status
, uD
= unsavedDialog()
156 if len(ftextselection
):
158 nfile
= ftextselection
159 from shutil
import move
161 from config
import get_config_path
162 from helper
import reload
163 pconfig
= get_config_path()
164 move(pconfig
+cbselection
, pconfig
+nfile
) #rename the file
165 mkdir(pconfig
+cbselection
) #create the parent directory
166 move(pconfig
+nfile
, "%s/%s" %(pconfig
+cbselection
,nfile
))
171 """ Spawn the delete subfile dialog """
172 gladefile
= "glade/deletefile.glade"
173 wTree
= gtk
.glade
.XML(gladefile
)
174 deld
= wTree
.get_widget("deld")
176 dirs
,files
= folder_scan()
178 cb
= wTree
.get_widget("ncb")
180 model
= gtk
.ListStore(str)
182 cell
= gtk
.CellRendererText()
184 cb
.add_attribute(cell
, 'text', 0)
188 data
= folder_walk(i
)
197 sbar
= wTree
.get_widget("sbar")
198 smsg
= sbar
.get_context_id("standard message")
200 sbar
.push(smsg
, "Error: No files detected")
203 remb
= wTree
.get_widget("delb")
204 closeb
= wTree
.get_widget("closeb")
206 remb
.connect("clicked", deleteFile
, cb
, deld
, window
)
207 closeb
.connect("clicked", close_subfile
, deld
)
212 def deleteFile(arg
, cb
, deld
, window
):
213 """ Delete subfile """
214 model
= cb
.get_model()
215 index
= cb
.get_active()
216 if index
>= 0: # prevent index errors
217 if window
.get_title() != "GPytage":
218 status
, uD
= unsavedDialog()
227 from os
import remove
228 from config
import get_config_path
229 from helper
import reload
230 pconfig
= get_config_path() # /
234 def findMatch(model
, path
, iter, user_data
):
235 """ Get path, iter for the file to be deleted """
236 if model
.get_value(iter, 0).strip('*') == user_data
[0]:
238 ddata
= [model
, path
, iter]
240 datastore
.datastore
.foreach(findMatch
, [model
[index
][0]])
245 filePath
= pconfig
+model
.get_value(iter, 3)+'/'+model
.get_value(iter, 0).strip('*')
247 print "deleteFILE: %s DELETED" % filePath