bzr branch
http://bzr.ed.am/gtk/prep-images
1
by edam
- initial commit, includes project and build setup |
1 |
# preferences.py |
2 |
# |
|
3 |
# Copyright (C) 2011 Tim Marston <edam@waxworlds.org> |
|
4 |
# |
|
5 |
# This file is part of add-copyright-to-images (hereafter referred to as "this |
|
6 |
# program"). |
|
7 |
# See http://www.waxworlds.org/edam/software/add-copyright-to-images for more |
|
8 |
# information. |
|
9 |
# |
|
10 |
# This program is free software: you can redistribute it and/or modify |
|
11 |
# it under the terms of the GNU Lesser General Public License as published |
|
12 |
# by the Free Software Foundation, either version 3 of the License, or |
|
13 |
# (at your option) any later version. |
|
14 |
# |
|
15 |
# This program is distributed in the hope that it will be useful, |
|
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
# GNU Lesser General Public License for more details. |
|
19 |
# |
|
20 |
# You should have received a copy of the GNU Lesser General Public License |
|
21 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22 |
||
23 |
||
24 |
import os |
|
25 |
import pygtk |
|
26 |
pygtk.require( '2.0' ); |
|
27 |
import gtk |
|
28 |
||
29 |
||
30 |
class Preferences: |
|
31 |
||
32 |
RCFILE = '~/.config/add-copyright-to-images.rc' |
|
33 |
||
34 |
def __init__( self ): |
|
35 |
||
36 |
# default values |
|
37 |
self.copyright_filename = '' |
|
38 |
self.resize = False |
|
39 |
self.resize_width = 1000 |
|
40 |
self.resize_height = 1000 |
|
41 |
self.export_inplace = False |
|
42 |
self.export_append = ".publish" |
|
43 |
||
44 |
# load preferences |
|
45 |
rclines = [] |
|
46 |
try: |
|
47 |
f = open( os.path.expanduser( self.RCFILE ), 'r' ) |
|
48 |
try: |
|
49 |
rclines = f.readlines() |
|
50 |
except IOError as e: |
|
51 |
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, \ |
|
52 |
gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, \ |
|
53 |
e.strerror ) |
|
54 |
dialog.run() |
|
55 |
dialog.destroy() |
|
56 |
exit( 1 ) |
|
57 |
except IOError as e: |
|
58 |
pass |
|
59 |
||
60 |
# parse prefs |
|
61 |
for line in rclines: |
|
62 |
parts = line.strip().split( ' ', 2 ) |
|
63 |
if len( parts ) == 2: |
|
64 |
if parts[ 0 ] == 'copyright-filename': |
|
65 |
self.copyright_filename = parts[ 1 ].strip() |
|
66 |
elif parts[ 0 ] == 'resize': |
|
67 |
self.resize = bool( int( parts[ 1 ] ) ) |
|
68 |
elif parts[ 0 ] == 'resize-width': |
|
69 |
self.resize_width = int( parts[ 1 ] ) |
|
70 |
elif parts[ 0 ] == 'resize-height': |
|
71 |
self.resize_height = int( parts[ 1 ] ) |
|
72 |
elif parts[ 0 ] == 'export-inplace': |
|
73 |
self.export_inplace = bool( int( parts[ 1 ] ) ) |
|
74 |
elif parts[ 0 ] == 'export-append': |
|
75 |
self.export_append = parts[ 1 ].strip() |
|
76 |
||
77 |
def save( self ): |
|
78 |
try: |
|
79 |
f = open( os.path.expanduser( self.RCFILE ), 'w' ) |
|
80 |
f.write( "copyright-filename " + self.copyright_filename + "\n" ) |
|
81 |
f.write( "resize " + str( int( self.resize ) ) + "\n" ) |
|
82 |
f.write( "resize-width " + str( self.resize_width ) + "\n" ) |
|
83 |
f.write( "resize-height " + str( self.resize_height ) + "\n" ) |
|
84 |
f.write( "export-inplace " + str( int( self.export_inplace ) ) + \ |
|
85 |
"\n" ) |
|
86 |
f.write( "export-append " + self.export_append + "\n" ) |
|
87 |
except IOError as e: |
|
88 |
dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, \ |
|
89 |
gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, e.strerror ) |
|
90 |
dialog.run() |
|
91 |
dialog.destroy() |
|
92 |
exit( 1 ) |