-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoxy.rb
125 lines (92 loc) · 3.98 KB
/
foxy.rb
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env ruby
%w{ rubygems fox16 fox16/colors yaml }.each {|gem| require gem}
include Fox
BLURB = <<END
GeoCommons Badger uploader!
END
class DataTargetWindow < FXMainWindow
def initialize(app)
# Initialize base class
super(app, "GeoCommons Foxy Badger!", :opts => DECOR_ALL, :x => 20, :y => 20, :width => 700, :height => 460)
# Create a data target with an integer value
@intTarget = FXDataTarget.new(0)
@user = FXDataTarget.new("admin")
# Create a data target with a floating point value
@password = FXDataTarget.new("password")
# Create a data target with a string value
@finder = FXDataTarget.new("http://finder.local")
# Create a data target with a color value
@dataDirectory = FXDataTarget.new("data")
# Create another integer data target to track the "progress"
@progressTarget = FXDataTarget.new(0)
# Menubar
menubar = FXMenuBar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X)
# File menu
filemenu = FXMenuPane.new(self)
FXMenuCommand.new(filemenu, "&Quit\tCtl-Q", nil, getApp(), FXApp::ID_QUIT)
FXMenuTitle.new(menubar, "&File", nil, filemenu)
# Lone progress bar at the bottom
FXProgressBar.new(self, @progressTarget, FXDataTarget::ID_VALUE,
LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|FRAME_SUNKEN|FRAME_THICK)
FXHorizontalSeparator.new(self,
LAYOUT_SIDE_TOP|SEPARATOR_GROOVE|LAYOUT_FILL_X)
horframe = FXHorizontalFrame.new(self, LAYOUT_SIDE_TOP | LAYOUT_FILL_X)
FXLabel.new(horframe, BLURB, nil, LAYOUT_SIDE_TOP | JUSTIFY_LEFT)
FXHorizontalSeparator.new(self,
LAYOUT_SIDE_TOP|SEPARATOR_GROOVE|LAYOUT_FILL_X)
# Arrange nicely
infoFrame = FXHorizontalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y)
infoMatrix = FXMatrix.new(infoFrame, 2, MATRIX_BY_COLUMNS|LAYOUT_FILL_X|LAYOUT_FILL_Y)
FXLabel.new(infoMatrix, "Username:")
FXTextField.new(infoMatrix, 20, @user, FXDataTarget::ID_VALUE, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN)
FXLabel.new(infoMatrix, "Password:")
FXTextField.new(infoMatrix, 20, @password, FXDataTarget::ID_VALUE, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN)
FXLabel.new(infoMatrix, "Finder url:")
FXTextField.new(infoMatrix, 20, @finder, FXDataTarget::ID_VALUE, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN)
FXLabel.new(infoMatrix, "Data directory:")
FXTextField.new(infoMatrix, 20, @dataDirectory, FXDataTarget::ID_VALUE, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN)
btn = FXButton.new(infoMatrix, "Upload", :opts => BUTTON_NORMAL|LAYOUT_RIGHT)
btn.connect(SEL_COMMAND) do
File.open("geocommons.yml", "w") do |file|
file << {:user => @user.to_s, :pass => @password.to_s, :finder => @finder.to_s, :data => @dataDirectory.to_s}.to_yaml
end
# Kick off the timer
getApp().addTimeout(80, method(:onTimeout))
end
@status = FXText.new(infoMatrix, :opts => TEXT_READONLY|LAYOUT_FILL_X|LAYOUT_FILL_Y)
# Install an accelerator
self.accelTable.addAccel(fxparseAccel("Ctl-Q"), getApp(), FXSEL(SEL_COMMAND, FXApp::ID_QUIT))
end
# Timer expired; update the progress
def onTimeout(sender, sel, ptr)
# Increment the progress modulo 100
@progressTarget.value = (@progressTarget.value + 1) % 100
# # Reset the timer for next time
getApp().addTimeout(80, method(:onTimeout))
end
# Quit
def onCmdQuit(sender, sel, ptr)
getApp.exit(0)
end
# Start
def create
# Create window
super
# Show the main window
show(PLACEMENT_SCREEN)
end
end
if __FILE__ == $0
# Make an application
application = FXApp.new("GeoCommons Badger", "GeoCommons Badger")
# Current threads implementation causes problems for this example, so disable
application.threadsEnabled = false
# Create main window
window = DataTargetWindow.new(application)
# Handle interrupts to quit application gracefully
application.addSignal("SIGINT", window.method(:onCmdQuit))
# Create the application
application.create
# Run
application.run
end