from
AppKit
import
*
import
signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
PATH
=
'P1012925.RW2'
RECT
=
NSMakeRect(
0
,
0
,
600
,
400
)
wins
=
[]
class
RawView(NSView):
def
initWithFrame_(
self
, rect):
objc.
super
(RawView,
self
).initWithFrame_(RECT)
self
.image
=
NSImage.alloc().initWithContentsOfFile_(PATH)
self
.draw_size
=
1
return
self
def
acceptsFirstResponder(
self
):
return
True
def
magnifyWithEvent_(
self
, event):
print
(event.magnification())
if
event.magnification() !
=
0
:
self
.draw_size
=
event.magnification()
+
1
self
.display()
def
swipeWithEvent_(
self
, event):
print
(
'swipe'
)
def
keyDown_(
self
, event):
print
(
'key down test'
)
def
mouseDown_(
self
, event):
print
(
'mouse down test'
)
def
drawRect_(
self
, rect):
NSColor.blackColor().
set
()
NSRectFill(rect)
aw
=
rect.size.width
*
self
.draw_size
ah
=
rect.size.height
*
self
.draw_size
w
=
self
.image.size().width
h
=
self
.image.size().height
if
aw
*
h > ah
*
w:
width
=
w
*
ah
/
h
height
=
ah
x
=
(aw
-
width)
/
2
y
=
0
else
:
width
=
aw
height
=
h
*
aw
/
w
x
=
0
y
=
(ah
-
height)
/
2
r1
=
NSMakeRect(x, y, width, height)
self
.image.drawInRect_(r1)
class
MyWindow(NSWindow):
def
init(
self
):
objc.
super
(MyWindow,
self
).initWithContentRect_styleMask_backing_defer_(
RECT,
NSTitledWindowMask | NSClosableWindowMask |
NSResizableWindowMask | NSMiniaturizableWindowMask,
NSBackingStoreBuffered,
False
)
self
.rawview
=
RawView.alloc().initWithFrame_(RECT)
self
.contentView().addSubview_(
self
.rawview)
self
.setTitle_(
'RAW image Viewer'
)
return
self
class
AppDelegate(NSObject):
def
applicationDidFinishLaunching_(
self
, notification):
window
=
MyWindow.new()
window.makeKeyAndOrderFront_(window)
wins.append(window)
NSApp.activateIgnoringOtherApps_(
True
)
class
AppMenu(NSMenu):
def
init(
self
):
objc.
super
(AppMenu,
self
).init()
item_app
=
NSMenuItem.new().autorelease()
self
.addItem_(item_app)
menu_app
=
NSMenu.new().autorelease()
item_app.setSubmenu_(menu_app)
item_quit
=
NSMenuItem.new().autorelease()
item_quit.initWithTitle_action_keyEquivalent_(
'Quit App'
,
'terminate:'
,
'q'
)
menu_app.addItem_(item_quit)
return
self
pool
=
NSAutoreleasePool.new()
NSApplication.sharedApplication()
NSApp.setMainMenu_(AppMenu.new().autorelease())
NSApp.setDelegate_(AppDelegate.new().autorelease())
NSApp.run()