forked from autoplot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateScreenShot.jy
More file actions
107 lines (83 loc) · 3.08 KB
/
createScreenShot.jy
File metadata and controls
107 lines (83 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# label: Take Screenshot
# title: Built-in tool for creating screenshots
# the caps lock key can be used as a shutter release.
from org.virbo.autoplot import ScreenshotsTool
from java.awt import Toolkit
from java.awt.event import KeyEvent
import time
kit=Toolkit.getDefaultToolkit()
if ( kit.getLockingKeyState(KeyEvent.VK_CAPS_LOCK )==1 ):
doCountDown=False
setStatus( 'Release Caps Lock to take screenshot' )
while ( kit.getLockingKeyState(KeyEvent.VK_CAPS_LOCK ) ):
time.sleep(.1)
setStatus( '' )
time.sleep(.1)
setStatus( 'Release Caps Lock to take screenshot' )
else:
doCountDown=True
if doCountDown:
for i in xrange(50):
if ( kit.getLockingKeyState(KeyEvent.VK_CAPS_LOCK )==1 ):
while ( kit.getLockingKeyState(KeyEvent.VK_CAPS_LOCK ) ):
time.sleep(.1)
setStatus( '' )
time.sleep(.1)
setStatus( 'Release Caps Lock to take screenshot' )
doCountDown= False
if ( doCountDown==False ): break
setStatus( 'screenshot in %.1f... Caps Lock will skip...' % ( 5-i/10. ) )
time.sleep(.1)
setStatus('')
time.sleep(.3)
ss= ScreenshotsTool.getScreenShot()
from org.autoplot.pngwalk import ImageResize
thumb= ImageResize.getScaledInstance( ss, 400 )
from javax.swing import JLabel, JPanel, JOptionPane, JButton, JCheckBox
from javax.swing import ImageIcon
from java.awt import BorderLayout
from java.awt import Toolkit
label= JLabel( ImageIcon(thumb) )
panel= JPanel()
panel.setLayout( BorderLayout() )
trim= JCheckBox('Trim')
trim.selected=True
panel.add( label, BorderLayout.CENTER )
copypanel= JPanel()
copypanel.add( JLabel( 'Save or Copy Screenshot' ), BorderLayout.WEST )
copypanel.add( trim, BorderLayout.CENTER )
def copyClip(evt):
from org.virbo.autoplot.transferrable import ImageSelection
iss= ImageSelection()
if ( trim.selected ):
iss.setImage( ScreenshotsTool.trim(ss) )
else:
iss.setImage( ss )
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
clipboard.setContents( iss, ImageSelection.getNullClipboardOwner() )
button= JButton( "Copy to Clipboard", actionPerformed=copyClip )
copypanel.add( button, BorderLayout.EAST )
panel.add( copypanel, BorderLayout.SOUTH )
from javax.swing import JFileChooser
jf= JFileChooser()
jf.setAccessory(panel)
from java.io import File
from java.io import FileOutputStream
from java.lang import Class
clas= Class.forName('org.virbo.autoplot.ScreenshotsTool')
from java.util.prefs import Preferences
prefs= Preferences.userNodeForPackage( clas )
f= prefs.get( 'screenshotFile', '$Y$m$d_$H$M$S.png' )
tp= TimeParser.create( '$Y$m$d_$H$M$S.png' )
if ( f!='' ):
jf.setSelectedFile( File( File(f).getParent(), tp.format( TimeUtil.now(), None ) ) )
r= jf.showSaveDialog( getViewWindow() )
if ( r==JFileChooser.APPROVE_OPTION ):
from javax.imageio import ImageIO
fn= jf.getSelectedFile()
prefs.put( 'screenshotFile', fn.toString() )
fo= FileOutputStream( fn )
if ( trim.selected ):
ss= ScreenshotsTool.trim(ss)
ImageIO.write( ss, 'png', fo )
fo.close()