AppleScript名:slider+buttonを作成 v3 |
— Created 2015-12-27 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" use framework "Carbon" — AEInteractWithUser() is in Carbon property windisp : false property wController : false property aSliderValMSG : "" if current application’s AEInteractWithUser(-1, missing value, missing value) is not equal to 0 then return set aMaxVal to 10 set aButtonMSG to "OK" set aSliderValMSG to "スライダーの設定値:" set aVal to getSliderValue(aMaxVal, aButtonMSG, aSliderValMSG) of me on getSliderValue(aMaxVal, aButtonMSG, aSliderValMSG) set (my windisp) to true set (my aSliderValMSG) to aSliderValMSG set aView to current application’s NSSplitView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, 360, 40)) aView’s setVertical:false –Sliderをつくる set aSlider to makeSider(aMaxVal) of me –Buttonをつくる set bButton to (current application’s NSButton’s alloc()’s init()) bButton’s setTitle:aButtonMSG bButton’s setTarget:me bButton’s setAction:("clicked:") bButton’s setKeyEquivalent:(return) –キーボードショートカット(リターンキー) aView’s addSubview:aSlider aView’s addSubview:bButton aView’s setNeedsDisplay:true –NSWindowControllerを作ってみた set aWin to (my makeWinWithView(aView, 400, 80, aSliderValMSG & (aMaxVal div 2) as string)) set wController to current application’s NSWindowController’s alloc() wController’s initWithWindow:aWin wController’s showWindow:me set aCount to 1800 repeat aCount times if (my windisp) = false then exit repeat end if delay 0.1 set aCount to aCount – 1 end repeat my closeWin:aWin set sVal to aSlider’s intValue() return sVal end getSliderValue on sliderChanged:aSender set aVal to aSender’s intValue() set parentWin to aSender’s |window|() parentWin’s setTitle:(my aSliderValMSG & (aVal as text)) end sliderChanged: on clicked:aSender set (my windisp) to false end clicked: –make Window for Display on makeWinWithView(aView, aWinWidth, aWinHeight, aTitle) set aScreen to current application’s NSScreen’s mainScreen() set aFrame to {{0, 0}, {aWinWidth, aWinHeight}} set aBacking to current application’s NSTitledWindowMask set aDefer to current application’s NSBackingStoreBuffered — Window set aWin to current application’s NSWindow’s alloc() (aWin’s initWithContentRect:aFrame styleMask:aBacking backing:aDefer defer:false screen:aScreen) –aWin’s setBackgroundColor:(current application’s NSColor’s whiteColor()) aWin’s setTitle:aTitle aWin’s setDelegate:me aWin’s setDisplaysWhenScreenProfileChanges:true aWin’s setHasShadow:true aWin’s setIgnoresMouseEvents:false aWin’s setLevel:(current application’s NSNormalWindowLevel) aWin’s setOpaque:false aWin’s setReleasedWhenClosed:true aWin’s |center|() –aWin’s makeKeyAndOrderFront:(me) aWin’s setContentView:aView return aWin end makeWinWithView –close win on closeWin:aWindow repeat with n from 10 to 1 by -1 (aWindow’s setAlphaValue:n / 10) delay 0.02 end repeat aWindow’s |close|() end closeWin: on makeSider(aMaxNum) set aSlider to current application’s NSSlider’s alloc()’s init() aSlider’s setMaxValue:aMaxNum aSlider’s setMinValue:1 aSlider’s setNumberOfTickMarks:aMaxNum aSlider’s setKnobThickness:50 aSlider’s setAllowsTickMarkValuesOnly:true aSlider’s setTickMarkPosition:(current application’s NSTickMarkBelow) aSlider’s setIntValue:(aMaxNum div 2) aSlider’s setTarget:me aSlider’s setAction:("sliderChanged:") return aSlider end makeSider |
More from my site
(Visited 31 times, 1 visits today)