/gtk/prep-images

To get this branch, use:
bzr branch http://bzr.ed.am/gtk/prep-images
1 by edam
- initial commit, includes project and build setup
1
# prefs_dialog.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 sys
25
import os
26
import gobject
27
import pygtk
28
pygtk.require( '2.0' );
29
import gtk
30
from subprocess import call
31
from .preferences import *
32
33
34
class PreferencesDialog:
35
36
	def __init__( self, parent_window = None ):
37
		self.prefs = Preferences()
38
39
		# create window
40
		self.window = gtk.Window( gtk.WINDOW_TOPLEVEL )
41
		self.window.connect( "delete_event", self.destroy )
42
		self.window.connect( "destroy", self.destroy )
43
		self.window.set_title( "Add Copyright to Images Preferences" );
44
		self.window.set_border_width( 10 )
45
		self.window.set_modal( True )
46
		self.window.connect( "key-press-event", self.key_press_event )
47
		if parent_window != None:
48
			self.window.set_transient_for( parent_window )
49
		vbox = gtk.VBox( False, 10 )
50
		self.window.add( vbox )
51
52
		# copyright image frame
53
		copyright_frame = gtk.Frame()
54
		copyright_frame.set_shadow_type( gtk.SHADOW_NONE )
55
		label1 = gtk.Label( "<b>Copyright Overlay Image</b>" )
56
		label1.set_use_markup( True )
57
		copyright_frame.set_label_widget( label1 )
58
		vbox.pack_start( copyright_frame, False, False, 0 )
59
		alignment1 = gtk.Alignment( 0.5, 0.5, 1.0, 1.0 )
60
		alignment1.set_padding( 5, 0, 12, 0 )
61
		copyright_frame.add( alignment1 )
62
		hbox1 = gtk.HBox( False, 2 )
63
		alignment1.add( hbox1 )
64
		self.copyright_entry = gtk.Entry( 0 )
65
		self.copyright_entry.set_text( self.prefs.copyright_filename )
66
		hbox1.pack_start( self.copyright_entry, True, True, 0 )
67
		button1 = gtk.Button( stock = gtk.STOCK_OPEN )
68
		button1.connect( "clicked", self.open_button_pressed )
69
		hbox1.pack_end( button1, False, False, 0 )
70
71
		# resize frame
72
		resize_frame = gtk.Frame()
73
		resize_frame.set_shadow_type( gtk.SHADOW_NONE )
74
		label2 = gtk.Label( "<b>Resize Image</b>" )
75
		label2.set_use_markup( True )
76
		resize_frame.set_label_widget( label2 )
77
		vbox.pack_start( resize_frame, False, False, 0 )
78
		alignment2 = gtk.Alignment( 0.5, 0.5, 1.0, 1.0 )
79
		alignment2.set_padding( 5, 0, 12, 0 )
80
		resize_frame.add( alignment2 )
81
		vbox1 = gtk.VBox( False, 0 )
82
		alignment2.add( vbox1 )
83
		self.resize_check_button = gtk.CheckButton( \
84
				"Resize image when adding copyright overlay" )
85
		self.resize_check_button.set_active( self.prefs.resize )
86
		self.resize_check_button.connect( "clicked", \
87
				self.resize_check_button_pressed )
88
		vbox1.pack_start( self.resize_check_button, False, False, 0 )
89
		alignment3 = gtk.Alignment( 0.5, 0.5, 1.0, 1.0 )
90
		alignment3.set_padding( 5, 0, 12, 0 )
91
		vbox1.pack_start( alignment3, False, False, 0 )
92
		self.resize_hbox = gtk.HBox( False, 10 )
93
		alignment3.add( self.resize_hbox )
94
		label3 = gtk.Label( "Width:" )
95
		self.resize_hbox.pack_start( label3, False, False, 0 )
96
		adjustment1 = gtk.Adjustment( self.prefs.resize_width, \
97
				1, 9999999, 1 )
98
		self.resize_width_spin_button = gtk.SpinButton( adjustment1 )
99
		self.resize_width_spin_button.set_numeric( True )
100
		self.resize_hbox.pack_start( \
101
				self.resize_width_spin_button, True, True, 0 )
102
		label4 = gtk.Label( "Height:" )
103
		self.resize_hbox.pack_start( label4, False, False, 0 )
104
		adjustment2 = gtk.Adjustment( self.prefs.resize_height, \
105
				1, 9999999, 1 )
106
		self.resize_height_spin_button = gtk.SpinButton( adjustment2 )
107
		self.resize_height_spin_button.set_numeric( True )
108
		self.resize_hbox.pack_start( \
109
				self.resize_height_spin_button, True, True, 0 )
110
111
		# export frame
112
		export_frame = gtk.Frame()
113
		export_frame.set_shadow_type( gtk.SHADOW_NONE )
114
		label5 = gtk.Label( "<b>Saving</b>" )
115
		label5.set_use_markup( True )
116
		export_frame.set_label_widget( label5 )
117
		vbox.pack_start( export_frame, False, False, 0 )
118
		alignment6 = gtk.Alignment( 0.5, 0.5, 1.0, 1.0 )
119
		alignment6.set_padding( 5, 0, 12, 0 )
120
		export_frame.add( alignment6 )
121
		vbox2 = gtk.VBox( False, 0 )
122
		alignment6.add( vbox2 )
123
		self.export_radio_button = gtk.RadioButton( None, \
124
				"Resize and add copyright to image in place" )
125
		self.export_radio_button.set_active( self.prefs.export_inplace )
126
		vbox2.pack_start( self.export_radio_button, False, False, 0 )
127
		hbox3 = gtk.HBox( False, 10 )
128
		vbox2.pack_start( hbox3, False, False, 0 )
129
		radio_button1 = gtk.RadioButton( self.export_radio_button, \
130
				"Append" )
131
		radio_button1.set_active( not self.prefs.export_inplace )
132
		hbox3.pack_start( radio_button1, False, False, 0 )
133
		self.export_append_entry = gtk.Entry()
134
		self.export_append_entry.set_width_chars( 10 )
135
		self.export_append_entry.set_text( self.prefs.export_append )
136
		hbox3.pack_start( self.export_append_entry, True, True, 0 )
137
		label6 = gtk.Label( "to filename" )
138
		hbox3.pack_start( label6, False, False, 0 )
139
140
		# buttons
141
		bbox1 = gtk.HButtonBox()
142
		bbox1.set_layout( gtk.BUTTONBOX_END )
143
		vbox.pack_end( bbox1, False, False, 0 )
144
		ok_button = gtk.Button( stock = gtk.STOCK_OK )
145
		ok_button.connect( "clicked", self.ok_button_pressed )
146
		bbox1.pack_end( ok_button )
147
		ok_button.set_flags( gtk.CAN_DEFAULT )
148
		ok_button.grab_default()
149
150
		# show it all
151
		self.resize_check_button_pressed()
152
		self.window.show_all()
153
154
	def main( self ):
155
		gtk.main()
156
157
	def delete_event( self, widget, event, data = None ):
158
		return False
159
160
	def destroy( self, widget, data = None ):
161
		gtk.main_quit()
162
163
	def key_press_event( self, widget, event ):
164
		if event.keyval == gtk.keysyms.Escape:
165
			self.window.destroy()
166
		else:
167
			return False
168
169
		return True
170
171
	def ok_button_pressed( self, widget ):
172
		self.prefs.copyright_filename = \
173
				self.copyright_entry.get_text().strip()
174
		self.prefs.resize = \
175
				self.resize_check_button.get_active()
176
		self.prefs.resize_width = \
177
				int( self.resize_width_spin_button.get_value_as_int() )
178
		self.prefs.resize_height = \
179
				int( self.resize_height_spin_button.get_value_as_int() )
180
		self.prefs.export_inplace = \
181
				self.export_radio_button.get_active()
182
		self.prefs.export_append = \
183
				self.export_append_entry.get_text().strip()
184
		self.prefs.save()
185
		self.window.destroy()
186
187
	def open_button_pressed( self, widget ):
188
		dialog = gtk.FileChooserDialog( "Choose Copyright Overlay Image", \
189
				self.window, gtk.FILE_CHOOSER_ACTION_OPEN, \
190
				( gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, \
191
				gtk.STOCK_OPEN, gtk.RESPONSE_OK) )
192
		dialog.set_default_response(gtk.RESPONSE_OK)
193
		filter = gtk.FileFilter()
194
		filter.set_name( "Images" )
195
		filter.add_mime_type( "image/png" )
196
		filter.add_mime_type( "image/jpeg" )
197
		filter.add_mime_type( "image/gif" )
198
		filter.add_pattern( "*.jpg" )
199
		filter.add_pattern( "*.png" )
200
		filter.add_pattern( "*.jpg" )
201
		filter.add_pattern( "*.gif" )
202
		filter.add_pattern( "*.tif" )
203
		filter.add_pattern( "*.xpm" )
204
		dialog.add_filter( filter )
205
		filter = gtk.FileFilter()
206
		filter.set_name( "All files" )
207
		filter.add_pattern( "*" )
208
		dialog.add_filter( filter )
209
		if dialog.run() == gtk.RESPONSE_OK:
210
			self.copyright_entry.set_text( dialog.get_filename() )
211
		dialog.destroy()
212
213
	def resize_check_button_pressed( self, widget = None ):
214
		self.resize_hbox.set_sensitive(
215
				self.resize_check_button.get_active() )