1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# prefs_dialog.py
#
# Copyright (C) 2011 Tim Marston <edam@waxworlds.org>
#
# This file is part of add-copyright-to-images (hereafter referred to as "this
# program").
# See http://www.waxworlds.org/edam/software/add-copyright-to-images for more
# information.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import os
import gobject
import pygtk
pygtk.require( '2.0' );
import gtk
from subprocess import call
from .preferences import *
class PreferencesDialog:
def __init__( self, parent_window = None ):
self.prefs = Preferences()
# create window
self.window = gtk.Window( gtk.WINDOW_TOPLEVEL )
self.window.connect( "delete_event", self.destroy )
self.window.connect( "destroy", self.destroy )
self.window.set_title( "Add Copyright to Images Preferences" );
self.window.set_border_width( 10 )
self.window.set_modal( True )
self.window.connect( "key-press-event", self.key_press_event )
if parent_window != None:
self.window.set_transient_for( parent_window )
vbox = gtk.VBox( False, 10 )
self.window.add( vbox )
# copyright image frame
copyright_frame = gtk.Frame()
copyright_frame.set_shadow_type( gtk.SHADOW_NONE )
label1 = gtk.Label( "<b>Copyright Overlay Image</b>" )
label1.set_use_markup( True )
copyright_frame.set_label_widget( label1 )
vbox.pack_start( copyright_frame, False, False, 0 )
alignment1 = gtk.Alignment( 0.5, 0.5, 1.0, 1.0 )
alignment1.set_padding( 5, 0, 12, 0 )
copyright_frame.add( alignment1 )
hbox1 = gtk.HBox( False, 2 )
alignment1.add( hbox1 )
self.copyright_entry = gtk.Entry( 0 )
self.copyright_entry.set_text( self.prefs.copyright_filename )
hbox1.pack_start( self.copyright_entry, True, True, 0 )
button1 = gtk.Button( stock = gtk.STOCK_OPEN )
button1.connect( "clicked", self.open_button_pressed )
hbox1.pack_end( button1, False, False, 0 )
# resize frame
resize_frame = gtk.Frame()
resize_frame.set_shadow_type( gtk.SHADOW_NONE )
label2 = gtk.Label( "<b>Resize Image</b>" )
label2.set_use_markup( True )
resize_frame.set_label_widget( label2 )
vbox.pack_start( resize_frame, False, False, 0 )
alignment2 = gtk.Alignment( 0.5, 0.5, 1.0, 1.0 )
alignment2.set_padding( 5, 0, 12, 0 )
resize_frame.add( alignment2 )
vbox1 = gtk.VBox( False, 0 )
alignment2.add( vbox1 )
self.resize_check_button = gtk.CheckButton( \
"Resize image when adding copyright overlay" )
self.resize_check_button.set_active( self.prefs.resize )
self.resize_check_button.connect( "clicked", \
self.resize_check_button_pressed )
vbox1.pack_start( self.resize_check_button, False, False, 0 )
alignment3 = gtk.Alignment( 0.5, 0.5, 1.0, 1.0 )
alignment3.set_padding( 5, 0, 12, 0 )
vbox1.pack_start( alignment3, False, False, 0 )
self.resize_hbox = gtk.HBox( False, 10 )
alignment3.add( self.resize_hbox )
label3 = gtk.Label( "Width:" )
self.resize_hbox.pack_start( label3, False, False, 0 )
adjustment1 = gtk.Adjustment( self.prefs.resize_width, \
1, 9999999, 1 )
self.resize_width_spin_button = gtk.SpinButton( adjustment1 )
self.resize_width_spin_button.set_numeric( True )
self.resize_hbox.pack_start( \
self.resize_width_spin_button, True, True, 0 )
label4 = gtk.Label( "Height:" )
self.resize_hbox.pack_start( label4, False, False, 0 )
adjustment2 = gtk.Adjustment( self.prefs.resize_height, \
1, 9999999, 1 )
self.resize_height_spin_button = gtk.SpinButton( adjustment2 )
self.resize_height_spin_button.set_numeric( True )
self.resize_hbox.pack_start( \
self.resize_height_spin_button, True, True, 0 )
# export frame
export_frame = gtk.Frame()
export_frame.set_shadow_type( gtk.SHADOW_NONE )
label5 = gtk.Label( "<b>Saving</b>" )
label5.set_use_markup( True )
export_frame.set_label_widget( label5 )
vbox.pack_start( export_frame, False, False, 0 )
alignment6 = gtk.Alignment( 0.5, 0.5, 1.0, 1.0 )
alignment6.set_padding( 5, 0, 12, 0 )
export_frame.add( alignment6 )
vbox2 = gtk.VBox( False, 0 )
alignment6.add( vbox2 )
self.export_radio_button = gtk.RadioButton( None, \
"Resize and add copyright to image in place" )
self.export_radio_button.set_active( self.prefs.export_inplace )
vbox2.pack_start( self.export_radio_button, False, False, 0 )
hbox3 = gtk.HBox( False, 10 )
vbox2.pack_start( hbox3, False, False, 0 )
radio_button1 = gtk.RadioButton( self.export_radio_button, \
"Append" )
radio_button1.set_active( not self.prefs.export_inplace )
hbox3.pack_start( radio_button1, False, False, 0 )
self.export_append_entry = gtk.Entry()
self.export_append_entry.set_width_chars( 10 )
self.export_append_entry.set_text( self.prefs.export_append )
hbox3.pack_start( self.export_append_entry, True, True, 0 )
label6 = gtk.Label( "to filename" )
hbox3.pack_start( label6, False, False, 0 )
# buttons
bbox1 = gtk.HButtonBox()
bbox1.set_layout( gtk.BUTTONBOX_END )
vbox.pack_end( bbox1, False, False, 0 )
ok_button = gtk.Button( stock = gtk.STOCK_OK )
ok_button.connect( "clicked", self.ok_button_pressed )
bbox1.pack_end( ok_button )
ok_button.set_flags( gtk.CAN_DEFAULT )
ok_button.grab_default()
# show it all
self.resize_check_button_pressed()
self.window.show_all()
def main( self ):
gtk.main()
def delete_event( self, widget, event, data = None ):
return False
def destroy( self, widget, data = None ):
gtk.main_quit()
def key_press_event( self, widget, event ):
if event.keyval == gtk.keysyms.Escape:
self.window.destroy()
else:
return False
return True
def ok_button_pressed( self, widget ):
self.prefs.copyright_filename = \
self.copyright_entry.get_text().strip()
self.prefs.resize = \
self.resize_check_button.get_active()
self.prefs.resize_width = \
int( self.resize_width_spin_button.get_value_as_int() )
self.prefs.resize_height = \
int( self.resize_height_spin_button.get_value_as_int() )
self.prefs.export_inplace = \
self.export_radio_button.get_active()
self.prefs.export_append = \
self.export_append_entry.get_text().strip()
self.prefs.save()
self.window.destroy()
def open_button_pressed( self, widget ):
dialog = gtk.FileChooserDialog( "Choose Copyright Overlay Image", \
self.window, gtk.FILE_CHOOSER_ACTION_OPEN, \
( gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, \
gtk.STOCK_OPEN, gtk.RESPONSE_OK) )
dialog.set_default_response(gtk.RESPONSE_OK)
filter = gtk.FileFilter()
filter.set_name( "Images" )
filter.add_mime_type( "image/png" )
filter.add_mime_type( "image/jpeg" )
filter.add_mime_type( "image/gif" )
filter.add_pattern( "*.jpg" )
filter.add_pattern( "*.png" )
filter.add_pattern( "*.jpg" )
filter.add_pattern( "*.gif" )
filter.add_pattern( "*.tif" )
filter.add_pattern( "*.xpm" )
dialog.add_filter( filter )
filter = gtk.FileFilter()
filter.set_name( "All files" )
filter.add_pattern( "*" )
dialog.add_filter( filter )
if dialog.run() == gtk.RESPONSE_OK:
self.copyright_entry.set_text( dialog.get_filename() )
dialog.destroy()
def resize_check_button_pressed( self, widget = None ):
self.resize_hbox.set_sensitive(
self.resize_check_button.get_active() )
|