Skip to content

Commit 6ade15d

Browse files
committed
0.20200501: fix Undo (n)
1 parent ff267ab commit 6ade15d

File tree

3 files changed

+119
-74
lines changed

3 files changed

+119
-74
lines changed

CHANGE.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ author: zvezdochiot [https://github.com/zvezdochiot]
44
0.20200501
55
AUTOCROP
66

7+
new design
8+
fix Undo (n)
79
Added BW mode in autocrop
810

911
0.20200424

croppertk.py

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,45 +90,61 @@ def createWidgets(self):
9090
self.canvas.bind('<ButtonRelease-1>', self.canvas_mouseup1_callback)
9191
self.canvas.bind('<B1-Motion>', self.canvas_mouseb1move_callback)
9292

93-
self.resetButton = tk.Button(self, text='Reset',
94-
activebackground='#F00', command=self.reset)
95-
96-
self.undoButton = tk.Button(self, text='Undo',
97-
activebackground='#FF0', command=self.undo_last)
98-
9993
self.countourButton = tk.Checkbutton(self, text='X',
10094
command=self.countour_mode)
10195

102-
self.zoomButton = tk.Checkbutton(self, text='Zoom',
96+
self.workFrame = tk.LabelFrame(self)
97+
98+
self.zoomFrame = tk.LabelFrame(self.workFrame, text='Zooming')
99+
100+
self.zoomButton = tk.Checkbutton(self.zoomFrame, text='Zoom',
103101
command=self.zoom_mode)
104102

105-
self.unzoomButton = tk.Button(self, text='<-|->',
103+
self.unzoomButton = tk.Button(self.zoomFrame, text='<-|->',
106104
activebackground='#00F', command=self.unzoom_image)
107105

108-
self.plusButton = tk.Button(self, text='+', command=self.plus_box)
106+
self.zoomButton.grid(row=0, column=0)
107+
self.unzoomButton.grid(row=0, column=1)
108+
109+
self.autoFrame = tk.LabelFrame(self.workFrame, text='AutoCrop')
109110

110-
self.autoButton = tk.Button(self, text='Auto', command=self.autocrop)
111+
self.autoButton = tk.Button(self.autoFrame, text='Auto', command=self.autocrop)
111112

112-
self.acbwButton = tk.Checkbutton(self, text='BW',
113+
self.acbwButton = tk.Checkbutton(self.autoFrame, text='BW',
113114
command=self.ac_bw_mode)
114115

115-
self.goButton = tk.Button(self, text='Crops',
116+
self.autoButton.grid(row=0, column=0)
117+
self.acbwButton.grid(row=0, column=1)
118+
119+
self.plusButton = tk.Button(self.workFrame, text='+', command=self.plus_box)
120+
121+
self.zoomFrame.grid(row=0, column=0, padx=5)
122+
self.autoFrame.grid(row=0, column=1, padx=5)
123+
self.plusButton.grid(row=0, column=2, padx=5)
124+
125+
self.ActionFrame = tk.LabelFrame(self, text='Action')
126+
127+
self.resetButton = tk.Button(self.ActionFrame, text='Reset',
128+
activebackground='#F00', command=self.reset)
129+
130+
self.undoButton = tk.Button(self.ActionFrame, text='Undo',
131+
activebackground='#FF0', command=self.undo_last)
132+
133+
self.goButton = tk.Button(self.ActionFrame, text='Crops',
116134
activebackground='#0F0', command=self.start_cropping)
117135

118-
self.quitButton = tk.Button(self, text='Quit',
136+
self.quitButton = tk.Button(self.ActionFrame, text='Quit',
119137
activebackground='#F00', command=self.quit)
120138

121-
self.canvas.grid(row=0, columnspan=10)
122-
self.resetButton.grid(row=1, column=0)
123-
self.undoButton.grid(row=1, column=1)
124-
self.countourButton.grid(row=1, column=2)
125-
self.zoomButton.grid(row=1, column=3)
126-
self.unzoomButton.grid(row=1, column=4)
127-
self.plusButton.grid(row=1, column=5)
128-
self.autoButton.grid(row=1, column=6)
129-
self.acbwButton.grid(row=1, column=7)
130-
self.goButton.grid(row=1, column=8)
131-
self.quitButton.grid(row=1, column=9)
139+
self.resetButton.grid(row=0, column=0)
140+
self.undoButton.grid(row=0, column=1)
141+
self.goButton.grid(row=0, column=2)
142+
self.quitButton.grid(row=0, column=3)
143+
144+
self.canvas.grid(row=0, columnspan=3)
145+
self.countourButton.grid(row=1, column=0)
146+
self.workFrame.grid(row=1, column=1)
147+
self.ActionFrame.grid(row=1, column=2)
132148

133149
def canvas_mouse1_callback(self, event):
134150
self.croprect_start = (event.x, event.y)
@@ -218,11 +234,13 @@ def redraw_rect(self):
218234
self.drawrect(croparea.rescale_rect(self.scale, self.x0, self.y0))
219235

220236
def undo_last(self):
221-
if self.canvas_rects:
222-
r = self.canvas_rects.pop()
223-
self.canvas.delete(r)
224-
if self.crop_rects:
225-
self.crop_rects.pop()
237+
if (self.n > 0):
238+
if self.canvas_rects:
239+
r = self.canvas_rects.pop()
240+
self.canvas.delete(r)
241+
if self.crop_rects:
242+
self.crop_rects.pop()
243+
self.n = self.n - 1
226244

227245
def drawrect(self, rect):
228246
bbox = (rect.left, rect.top, rect.right, rect.bottom)
@@ -267,6 +285,7 @@ def reset(self):
267285
self.canvas_rects = []
268286
self.crop_rects = []
269287
self.region_rect = Rect((0, 0), (self.w, self.h))
288+
self.n = 0
270289
self.x0 = 0
271290
self.y0 = 0
272291

croppertktopdf.py

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)