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