@@ -103,69 +103,92 @@ def createWidgets(self):
103103        self .canvas .bind ('<ButtonRelease-1>' , self .canvas_mouseup1_callback )
104104        self .canvas .bind ('<B1-Motion>' , self .canvas_mouseb1move_callback )
105105
106-         self .resetButton  =  tk .Button (self , text = 'Reset ' ,
107-                                           activebackground = '#F00' ,  command = self .reset )
106+         self .countourButton  =  tk .Checkbutton (self , text = 'X ' ,
107+                                                command = self .countour_mode )
108108
109-         self .dpiLabel  =  tk .Label (self , text = 'DPI' )
110-         self .dpiBox  =  tk .Text (self , height = 1 , width = 4 )
109+         self .workFrame  =  tk .LabelFrame (self )
110+ 
111+         self .outputFrame  =  tk .LabelFrame (self .workFrame , text = 'Output' )
112+ 
113+         self .dpiLabel  =  tk .Label (self .outputFrame , text = 'DPI' )
114+         self .dpiBox  =  tk .Text (self .outputFrame , height = 1 , width = 4 )
111115        self .dpiBox .insert (1.0 , str (default_dpi ))
112116
113-         self .formatLabel  =  tk .Label (self , text = 'F' )
114-         self .formatBox  =  tk .Text (self , height = 1 , width = 4 )
117+         self .formatLabel  =  tk .Label (self . outputFrame , text = 'F' )
118+         self .formatBox  =  tk .Text (self . outputFrame , height = 1 , width = 4 )
115119        self .formatBox .insert (1.0 , default_format )
116120
117-         self .divLabel  =  tk .Label (self , text = 'div' )
118-         self .divBox  =  tk .Text (self , height = 1 , width = 2 )
121+         self .divLabel  =  tk .Label (self . outputFrame , text = 'div' )
122+         self .divBox  =  tk .Text (self . outputFrame , height = 1 , width = 2 )
119123        self .divBox .insert (1.0 , str (default_div ))
120124
121-         self .undoButton  =  tk .Button (self , text = 'Undo' ,
122-                                          activebackground = '#FF0' , command = self .undo_last )
125+         self .dpiLabel .grid (row = 0 , column = 0 )
126+         self .dpiBox .grid (row = 0 , column = 1 )
127+         self .formatLabel .grid (row = 0 , column = 2 )
128+         self .formatBox .grid (row = 0 , column = 3 )
123129
124-         self .countourButton  =  tk .Checkbutton (self , text = 'X' ,
125-                                               command = self .countour_mode )
130+         self .zoomFrame  =  tk .LabelFrame (self .workFrame , text = 'Zooming' )
126131
127-         self .zoomButton  =  tk .Checkbutton (self , text = 'Zoom' ,
132+         self .zoomButton  =  tk .Checkbutton (self . zoomFrame , text = 'Zoom' ,
128133                                              command = self .zoom_mode )
129134
130-         self .unzoomButton  =  tk .Button (self , text = '<-|->' ,
135+         self .unzoomButton  =  tk .Button (self . zoomFrame , text = '<-|->' ,
131136                                           activebackground = '#00F' , command = self .unzoom_image )
132137
133-         self .plusButton  =  tk .Button (self , text = '+' , command = self .plus_box )
138+         self .zoomButton .grid (row = 0 , column = 0 )
139+         self .unzoomButton .grid (row = 0 , column = 1 )
140+ 
141+         self .autoFrame  =  tk .LabelFrame (self .workFrame , text = 'AutoCrop' )
134142
135-         self .autoButton  =  tk .Button (self , text = 'Auto' , command = self .autocrop )
143+         self .autoButton  =  tk .Button (self . autoFrame , text = 'Auto' , command = self .autocrop )
136144
137-         self .acbwButton  =  tk .Checkbutton (self , text = 'BW' ,
145+         self .acbwButton  =  tk .Checkbutton (self . autoFrame , text = 'BW' ,
138146                                              command = self .ac_bw_mode )
139147
140-         self .cleanmarginLabel  =  tk .Label (self , text = '[]' )
141-         self .cleanmarginBox  =  tk .Text (self , height = 1 , width = 2 )
148+         self .autoButton .grid (row = 0 , column = 0 )
149+         self .acbwButton .grid (row = 0 , column = 1 )
150+ 
151+         self .marginFrame  =  tk .LabelFrame (self .workFrame , text = 'Margin' )
152+ 
153+         self .cleanmarginLabel  =  tk .Label (self .marginFrame , text = '[]' )
154+         self .cleanmarginBox  =  tk .Text (self .marginFrame , height = 1 , width = 2 )
142155        self .cleanmarginBox .insert (1.0 , str (default_cleanmargin ))
143156
144-         self .goButton  =  tk .Button (self , text = 'Crops' ,
157+         self .cleanmarginLabel .grid (row = 0 , column = 0 )
158+         self .cleanmarginBox .grid (row = 0 , column = 1 )
159+ 
160+         self .plusButton  =  tk .Button (self .workFrame , text = '+' , command = self .plus_box )
161+ 
162+         self .outputFrame .grid (row = 0 , column = 0 , padx = 5 )
163+         self .zoomFrame .grid (row = 0 , column = 1 , padx = 5 )
164+         self .autoFrame .grid (row = 0 , column = 2 , padx = 5 )
165+         self .marginFrame .grid (row = 0 , column = 3 , padx = 5 )
166+         self .plusButton .grid (row = 0 , column = 4 , padx = 5 )
167+ 
168+ 
169+         self .ActionFrame  =  tk .LabelFrame (self , text = 'Action' )
170+ 
171+         self .resetButton  =  tk .Button (self .ActionFrame , text = 'Reset' ,
172+                                           activebackground = '#F00' , command = self .reset )
173+ 
174+         self .undoButton  =  tk .Button (self .ActionFrame , text = 'Undo' ,
175+                                          activebackground = '#FF0' , command = self .undo_last )
176+ 
177+         self .goButton  =  tk .Button (self .ActionFrame , text = 'Crops' ,
145178                                       activebackground = '#0F0' , command = self .start_cropping )
146179
147-         self .quitButton  =  tk .Button (self , text = 'Quit' ,
180+         self .quitButton  =  tk .Button (self . ActionFrame , text = 'Quit' ,
148181                                         activebackground = '#F00' , command = self .quit )
149182
150-         self .canvas .grid (row = 0 , columnspan = 18 )
151-         self .resetButton .grid (row = 1 , column = 0 )
152-         self .countourButton .grid (row = 1 , column = 1 )
153-         self .dpiLabel .grid (row = 1 , column = 2 )
154-         self .dpiBox .grid (row = 1 , column = 3 )
155-         self .formatLabel .grid (row = 1 , column = 4 )
156-         self .formatBox .grid (row = 1 , column = 5 )
157-         self .divLabel .grid (row = 1 , column = 6 )
158-         self .divBox .grid (row = 1 , column = 7 )
159-         self .undoButton .grid (row = 1 , column = 8 )
160-         self .zoomButton .grid (row = 1 , column = 9 )
161-         self .unzoomButton .grid (row = 1 , column = 10 )
162-         self .plusButton .grid (row = 1 , column = 11 )
163-         self .autoButton .grid (row = 1 , column = 12 )
164-         self .acbwButton .grid (row = 1 , column = 13 )
165-         self .cleanmarginLabel .grid (row = 1 , column = 14 )
166-         self .cleanmarginBox .grid (row = 1 , column = 15 )
167-         self .goButton .grid (row = 1 , column = 16 )
168-         self .quitButton .grid (row = 1 , column = 17 )
183+         self .resetButton .grid (row = 0 , column = 0 )
184+         self .undoButton .grid (row = 0 , column = 1 )
185+         self .goButton .grid (row = 0 , column = 2 )
186+         self .quitButton .grid (row = 0 , column = 3 )
187+ 
188+         self .canvas .grid (row = 0 , columnspan = 3 )
189+         self .countourButton .grid (row = 1 , column = 0 )
190+         self .workFrame .grid (row = 1 , column = 1 )
191+         self .ActionFrame .grid (row = 1 , column = 2 )
169192
170193    def  verify_params (self ):
171194        self .dpi  =  int (self .dpiBox .get ('1.0' , tk .END ))
@@ -283,11 +306,12 @@ def redraw_rect(self):
283306            self .drawrect (croparea .rescale_rect (self .scale , self .x0 , self .y0 ))
284307
285308    def  undo_last (self ):
286-         if  self .canvas_rects :
287-             r  =  self .canvas_rects .pop ()
288-             self .canvas .delete (r )
289-         if  self .crop_rects :
290-             self .crop_rects .pop ()
309+         if  (self .n  >  0 ):
310+             if  self .canvas_rects :
311+                 r  =  self .canvas_rects .pop ()
312+                 self .canvas .delete (r )
313+             if  self .crop_rects :
314+                 self .crop_rects .pop ()
291315            self .n  =  self .n  -  1 
292316
293317    def  drawrect (self , rect ):
0 commit comments