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