-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'python3' of https://github.com/reubot/cropgui
- Loading branch information
Showing
5 changed files
with
52 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/python2 | ||
#!/usr/bin/python3 | ||
# cropgui, a graphical front-end for lossless jpeg cropping | ||
# Copyright (C) 2009 Jeff Epler <[email protected]> | ||
# This program is free software; you can redistribute it and/or modify | ||
|
@@ -19,9 +19,10 @@ | |
from cropgui_common import _ | ||
|
||
import gi | ||
from gi.repository import GObject as gobject | ||
#from gi.repository import GObject as gobject | ||
gi.require_version('Gtk', '3.0') | ||
from gi.repository import Gtk as gtk | ||
from gi.repository import GLib | ||
#import gtk.glade | ||
from gi.repository import Gdk as gdk | ||
import filechooser | ||
|
@@ -40,7 +41,7 @@ def excepthook(exc_type, exc_obj, exc_tb): | |
except NameError: | ||
w = None | ||
lines = traceback.format_exception(exc_type, exc_obj, exc_tb) | ||
print "".join(lines) | ||
print("".join(lines)) | ||
m = gtk.MessageDialog(w, | ||
gtk.DialogFlags.MODAL | gtk.DialogFlags.DESTROY_WITH_PARENT, | ||
gtk.MessageType.ERROR, gtk.ButtonsType.OK, | ||
|
@@ -146,7 +147,7 @@ def image_set(self): | |
|
||
def render(self): | ||
if self.idle is None: | ||
self.idle = gobject.idle_add(self.do_render) | ||
self.idle = GLib.idle_add(self.do_render) | ||
|
||
def do_render(self): | ||
if not self.idle: | ||
|
@@ -199,7 +200,7 @@ def do_render(self): | |
|
||
|
||
def wait(self): | ||
self.loop = gobject.MainLoop() | ||
self.loop = GLib.MainLoop() | ||
self.result = -1 | ||
self.loop.run() | ||
return self.result | ||
|
@@ -209,8 +210,8 @@ def wait(self): | |
|
||
class App: | ||
def __init__(self): | ||
self.builder = gtk.Builder() | ||
self.builder.add_from_file(gladefile) | ||
self.builder = gtk.Builder() | ||
self.builder.add_from_file(gladefile) | ||
#self.glade = gtk.glade.XML(gladefile) | ||
self.drag = DragManager(self) | ||
self.task = CropTask(self) | ||
|
@@ -248,7 +249,7 @@ def run(self): | |
scale = max (scale, (drag.w-1)/max_w+1) | ||
scale = max (scale, (drag.h-1)/max_h+1) | ||
i.thumbnail((drag.w/scale, drag.h/scale)) | ||
except (IOError,), detail: | ||
except (IOError,) as detail: | ||
m = gtk.MessageDialog(self['window1'], | ||
gtk.DialogFlags.MODAL | gtk.DialogFlags.DESTROY_WITH_PARENT, | ||
gtk.MessageType.ERROR, gtk.ButtonsType.OK, | ||
|
@@ -299,7 +300,7 @@ def run(self): | |
command = ['nice', 'convert'] | ||
if not rotation == "none": command.extend(['-rotate', rotation]) | ||
command.extend([image_name, '-crop', cropspec, target]) | ||
print " ".join(command) | ||
print(" ".join(command)) | ||
task.add(command, target) | ||
|
||
def image_names(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/python2 | ||
#!/usr/bin/python3 | ||
# cropgui, a graphical front-end for lossless jpeg cropping | ||
# Copyright (C) 2009 Jeff Epler <[email protected]> | ||
# This program is free software; you can redistribute it and/or modify | ||
|
@@ -18,60 +18,60 @@ | |
from cropgui_common import * | ||
from cropgui_common import _ | ||
|
||
import Tkinter | ||
import ImageTk | ||
import tkFileDialog | ||
import tkinter | ||
from PIL import ImageTk | ||
import tkinter.filedialog | ||
import sys | ||
import os | ||
import signal | ||
import log | ||
|
||
app = Tkinter.Tk() | ||
app = tkinter.Tk() | ||
app.wm_title(_("CropGUI -- lossless cropping and rotation of jpeg files")) | ||
app.wm_iconname(_("CropGUI")) | ||
|
||
preview = Tkinter.Label(app) | ||
preview = tkinter.Label(app) | ||
preview.pack(side="bottom") | ||
|
||
do_crop = Tkinter.Button(app, text="Crop") | ||
do_crop = tkinter.Button(app, text="Crop") | ||
do_crop.pack(side="left") | ||
|
||
crop169_button = Tkinter.Menubutton(app, text="16:9") | ||
crop169_button = tkinter.Menubutton(app, text="16:9") | ||
crop169_button.pack(side="left") | ||
crop169 = Tkinter.Menu(crop169_button) | ||
crop169 = tkinter.Menu(crop169_button) | ||
crop169_button.config(menu=crop169) | ||
|
||
crop85_button = Tkinter.Menubutton(app, text="8:5") | ||
crop85_button = tkinter.Menubutton(app, text="8:5") | ||
crop85_button.pack(side="left") | ||
crop85 = Tkinter.Menu(crop85_button) | ||
crop85 = tkinter.Menu(crop85_button) | ||
crop85_button.config(menu=crop85) | ||
|
||
crop32_button = Tkinter.Menubutton(app, text="3:2") | ||
crop32_button = tkinter.Menubutton(app, text="3:2") | ||
crop32_button.pack(side="left") | ||
crop32 = Tkinter.Menu(crop32_button) | ||
crop32 = tkinter.Menu(crop32_button) | ||
crop32_button.config(menu=crop32) | ||
|
||
crop43_button = Tkinter.Menubutton(app, text="4:3") | ||
crop43_button = tkinter.Menubutton(app, text="4:3") | ||
crop43_button.pack(side="left") | ||
crop43 = Tkinter.Menu(crop43_button) | ||
crop43 = tkinter.Menu(crop43_button) | ||
crop43_button.config(menu=crop43) | ||
|
||
crop11_button = Tkinter.Menubutton(app, text="1:1") | ||
crop11_button = tkinter.Menubutton(app, text="1:1") | ||
crop11_button.pack(side="left") | ||
crop11 = Tkinter.Menu(crop11_button) | ||
crop11 = tkinter.Menu(crop11_button) | ||
crop11_button.config(menu=crop11) | ||
|
||
crop34_button = Tkinter.Menubutton(app, text="3:4") | ||
crop34_button = tkinter.Menubutton(app, text="3:4") | ||
crop34_button.pack(side="left") | ||
crop34 = Tkinter.Menu(crop34_button) | ||
crop34 = tkinter.Menu(crop34_button) | ||
crop34_button.config(menu=crop34) | ||
|
||
crop23_button = Tkinter.Menubutton(app, text="2:3") | ||
crop23_button = tkinter.Menubutton(app, text="2:3") | ||
crop23_button.pack(side="left") | ||
crop23 = Tkinter.Menu(crop23_button) | ||
crop23 = tkinter.Menu(crop23_button) | ||
crop23_button.config(menu=crop23) | ||
|
||
info = Tkinter.Label(app) | ||
info = tkinter.Label(app) | ||
info.pack(side="left") | ||
|
||
task = CropTask(log) | ||
|
@@ -93,9 +93,9 @@ def __init__(self, w, b, inf): | |
app.bind("<Escape>", self.escape) | ||
w.bind("<Button1-Enter>", "#nothing") | ||
w.bind("<Button1-Leave>", "#nothing") | ||
dummy_image = Image.new('L', (max_w/2,max_h/2), 0xff) | ||
dummy_image = Image.new('L', (int(max_w/2),int(max_h/2)), 0xff) | ||
self.dummy_tkimage = ImageTk.PhotoImage(dummy_image) | ||
self.v = Tkinter.IntVar(app) | ||
self.v = tkinter.IntVar(app) | ||
DragManagerBase.__init__(self) | ||
|
||
def image_set(self): | ||
|
@@ -236,7 +236,7 @@ def image_names(): | |
for i in sys.argv[1:]: yield i | ||
else: | ||
while 1: | ||
names = tkFileDialog.askopenfilenames(master=app, | ||
names = tkinter.filedialog.askopenfilenames(master=app, | ||
defaultextension=".jpg", multiple=1, parent=app, | ||
filetypes=( | ||
(_("JPEG Image Files"), ".jpg .JPG .jpeg .JPEG"), | ||
|
@@ -297,7 +297,7 @@ def set_busy(new_busy=True): | |
cropspec = "%dx%d+%d+%d" % (r-l, b-t, l, t) | ||
target = base + "-crop" + ext | ||
command=['nice', 'jpegtran', '-copy', 'all', '-crop', cropspec, '-outfile', target, image_name] | ||
print " ".join(command) | ||
print(" ".join(command)) | ||
task.add(command, target) | ||
finally: | ||
task.done() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters