shenmegui 0.2.1 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shenmegui/controls.rb +22 -12
- data/lib/shenmegui/core.rb +7 -4
- data/lib/shenmegui/file_dialog.rb +6 -3
- data/lib/shenmegui/utils.rb +19 -0
- data/static/script.js +10 -4
- data/static/style.css +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76f49e57833803f7d6359cefd0ede3e57f5c492a
|
4
|
+
data.tar.gz: 10ea23f6a66f9d535c7862a66e1b8df4de6aa57f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d87c7220e9d410870899e94651ac8b8c3d74b7964a034770eec0d308378698ba303adc05bb8cb984d2cf91db8ca0629bfcf7733d55dbbf547b9aac24dfe0d62
|
7
|
+
data.tar.gz: 29c16632cd4ddde9e85c850944171737456e5a4ed6a04473db3cb3a0d0ef46e87cd04c095618ac75c657224506832965effa803b060d90190eadd6430d9ab44c
|
data/lib/shenmegui/controls.rb
CHANGED
@@ -5,12 +5,14 @@ module ShenmeGUI
|
|
5
5
|
class Base
|
6
6
|
attr_accessor :id, :properties, :events, :children, :parent
|
7
7
|
|
8
|
-
def
|
8
|
+
def add_hook(obj)
|
9
9
|
case obj
|
10
10
|
when String
|
11
11
|
HookedString.new(obj, self)
|
12
12
|
when Array
|
13
13
|
HookedArray.new(obj, self)
|
14
|
+
when Hash
|
15
|
+
HookedHash.new(obj, self)
|
14
16
|
else
|
15
17
|
obj
|
16
18
|
end
|
@@ -23,8 +25,7 @@ module ShenmeGUI
|
|
23
25
|
end
|
24
26
|
|
25
27
|
define_method("#{x}=") do |v|
|
26
|
-
|
27
|
-
@properties[x] = v
|
28
|
+
update_properties({x => v})
|
28
29
|
sync
|
29
30
|
end
|
30
31
|
end
|
@@ -32,14 +33,13 @@ module ShenmeGUI
|
|
32
33
|
|
33
34
|
def self.shortcut(prop)
|
34
35
|
define_method(:initialize) do |x=nil, params={}|
|
35
|
-
x = hook x
|
36
36
|
params.merge!({prop => x})
|
37
37
|
super(params)
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
41
41
|
|
42
|
-
available_events = %w{click input dblclick mouseover mouseout blur focus mousedown mouseup change
|
42
|
+
available_events = %w{click input dblclick mouseover mouseout blur focus mousedown mouseup change select}.collect(&:to_sym)
|
43
43
|
available_events.each do |x|
|
44
44
|
define_method("on#{x}") do |&block|
|
45
45
|
return events[x] if block.nil?
|
@@ -60,19 +60,20 @@ module ShenmeGUI
|
|
60
60
|
ShenmeGUI.socket.send(msg)
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
64
|
-
data = Hash[data.keys.collect(&:to_sym).zip(data.values.collect{|x|
|
63
|
+
def update_properties(data)
|
64
|
+
data = Hash[data.keys.collect(&:to_sym).zip(data.values.collect{|x| add_hook(x)})]
|
65
65
|
@properties.update(data)
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
68
|
+
def sync_events
|
69
69
|
data = @events.keys
|
70
70
|
msg = "add_event:#{@id}->#{data.to_json}"
|
71
71
|
ShenmeGUI.socket.send(msg)
|
72
72
|
end
|
73
73
|
|
74
74
|
def initialize(params={})
|
75
|
-
@properties =
|
75
|
+
@properties = {}
|
76
|
+
update_properties(params)
|
76
77
|
@id = ShenmeGUI.elements.size
|
77
78
|
ShenmeGUI.elements << self
|
78
79
|
@children = []
|
@@ -117,18 +118,27 @@ module ShenmeGUI
|
|
117
118
|
end
|
118
119
|
|
119
120
|
class Textline < Base
|
120
|
-
property :text, :
|
121
|
+
property :text, :selection
|
121
122
|
shortcut :text
|
122
123
|
|
124
|
+
def text=(v)
|
125
|
+
update_properties({text: v, selection: [v.size]*2 })
|
126
|
+
sync
|
127
|
+
end
|
123
128
|
end
|
124
129
|
|
125
130
|
class Textarea < Base
|
126
|
-
property :text, :
|
131
|
+
property :text, :selection
|
127
132
|
shortcut :text
|
128
133
|
|
129
134
|
def <<(t)
|
130
135
|
text << "\n#{t}"
|
131
136
|
end
|
137
|
+
|
138
|
+
def text=(v)
|
139
|
+
update_properties({text: v, selection: [v.size]*2 })
|
140
|
+
sync
|
141
|
+
end
|
132
142
|
end
|
133
143
|
|
134
144
|
class Stack < Base
|
@@ -144,7 +154,7 @@ module ShenmeGUI
|
|
144
154
|
|
145
155
|
class Checkbox < Base
|
146
156
|
property :options, :checked, :arrange
|
147
|
-
shortcut :options
|
157
|
+
shortcut :options
|
148
158
|
end
|
149
159
|
|
150
160
|
class Progress < Base
|
data/lib/shenmegui/core.rb
CHANGED
@@ -15,7 +15,7 @@ module ShenmeGUI
|
|
15
15
|
data = JSON.parse(match_data[3]) if match_data[3]
|
16
16
|
case command
|
17
17
|
when :sync
|
18
|
-
target.
|
18
|
+
target.update_properties(data)
|
19
19
|
else
|
20
20
|
event_lambda = target.events[command]
|
21
21
|
@this = @elements[id]
|
@@ -45,14 +45,14 @@ module ShenmeGUI
|
|
45
45
|
FileDialog.get_save_file_name(params)
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def enable_debugging
|
49
49
|
Thread.new do
|
50
50
|
ShenmeGUI.instance_eval do
|
51
51
|
bind = binding
|
52
52
|
while true
|
53
53
|
begin
|
54
54
|
command = $stdin.gets.chomp
|
55
|
-
result = eval command
|
55
|
+
result = bind.eval command
|
56
56
|
puts "=> #{result}"
|
57
57
|
rescue
|
58
58
|
puts "#{$!}"
|
@@ -69,7 +69,10 @@ module ShenmeGUI
|
|
69
69
|
EM::WebSocket.run(:host => "0.0.0.0", :port => 80) do |ws|
|
70
70
|
ws.onopen do
|
71
71
|
puts "WebSocket connection open"
|
72
|
-
@elements.each
|
72
|
+
@elements.each do |e|
|
73
|
+
e.sync_events
|
74
|
+
e.sync
|
75
|
+
end
|
73
76
|
end
|
74
77
|
|
75
78
|
ws.onclose { puts "Connection closed" }
|
@@ -37,8 +37,9 @@ module ShenmeGUI
|
|
37
37
|
filter = params[:filter] ? "#{params[:filter]}\0#{params[:filter]}\0\0" : 0
|
38
38
|
title = params[:title] || 0
|
39
39
|
flags = 0x00880000
|
40
|
-
flags += 0x00000200 if params[:
|
41
|
-
flags += 0x10000000 if params[:
|
40
|
+
flags += 0x00000200 if params[:multi_select]
|
41
|
+
flags += 0x10000000 if params[:show_hidden]
|
42
|
+
initial_path = params[:initial_path] ? params[:initial_path] : 0
|
42
43
|
|
43
44
|
path = "\0" * 1024
|
44
45
|
ofn = Struct_OPENFILENAME.malloc
|
@@ -52,7 +53,7 @@ module ShenmeGUI
|
|
52
53
|
ofn.nMaxFile = path.size
|
53
54
|
ofn.lpstrFileTitle = 0
|
54
55
|
ofn.nMaxFileTitle = 0
|
55
|
-
ofn.lpstrInitialDir =
|
56
|
+
ofn.lpstrInitialDir = initial_path
|
56
57
|
ofn.lpstrTitle = title
|
57
58
|
ofn.nFileOffset = 0
|
58
59
|
ofn.nFileExtension = 0
|
@@ -85,3 +86,5 @@ module ShenmeGUI
|
|
85
86
|
|
86
87
|
end
|
87
88
|
end
|
89
|
+
|
90
|
+
#ShenmeGUI::FileDialog.get_open_file_name(initial_path: 'C:\\')
|
data/lib/shenmegui/utils.rb
CHANGED
@@ -37,4 +37,23 @@ module ShenmeGUI
|
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
40
|
+
|
41
|
+
class HookedHash < Hash
|
42
|
+
@unhook_methods = %i{[]= clear delete delete_if keep_if merge! update rehash reject! replace select! shift}
|
43
|
+
@unhook_methods = Hash[@unhook_methods.collect{|x| [x, Hash.instance_method(x)]}]
|
44
|
+
|
45
|
+
def initialize(hsh, owner)
|
46
|
+
@owner = owner
|
47
|
+
super(hsh)
|
48
|
+
end
|
49
|
+
|
50
|
+
@unhook_methods.each do |k, v|
|
51
|
+
define_method(k) do |*arr, &block|
|
52
|
+
result = v.bind(self).call(*arr, &block)
|
53
|
+
@owner.sync
|
54
|
+
result
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
40
59
|
end
|
data/static/script.js
CHANGED
@@ -25,8 +25,7 @@ var changeListeners = {
|
|
25
25
|
event: ['input','select'],
|
26
26
|
function: (function(){
|
27
27
|
this.properties.text = this.value;
|
28
|
-
this.properties.
|
29
|
-
this.properties.selection_end = this.selectionEnd;
|
28
|
+
this.properties.selection = [this.selectionStart, this.selectionEnd];
|
30
29
|
sync(this);
|
31
30
|
})
|
32
31
|
},
|
@@ -35,8 +34,7 @@ var changeListeners = {
|
|
35
34
|
event: ['input','select'],
|
36
35
|
function: (function(){
|
37
36
|
this.properties.text = this.value;
|
38
|
-
this.properties.
|
39
|
-
this.properties.selection_end = this.selectionEnd;
|
37
|
+
this.properties.selection = [this.selectionStart, this.selectionEnd];
|
40
38
|
sync(this);
|
41
39
|
})
|
42
40
|
},
|
@@ -119,10 +117,18 @@ var syncHandlers = {
|
|
119
117
|
|
120
118
|
textline: (function(target, data){
|
121
119
|
target.value = data.text;
|
120
|
+
if(data.selection){
|
121
|
+
target.selectionStart = data.selection[0];
|
122
|
+
target.selectionEnd = data.selection[1];
|
123
|
+
}
|
122
124
|
}),
|
123
125
|
|
124
126
|
textarea: (function(target, data){
|
125
127
|
target.value = data.text;
|
128
|
+
if(data.selection){
|
129
|
+
target.selectionStart = data.selection[0];
|
130
|
+
target.selectionEnd = data.selection[1];
|
131
|
+
}
|
126
132
|
}),
|
127
133
|
|
128
134
|
image: (function(target, data){
|
data/static/style.css
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shenmegui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CicholGricenchos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-websocket
|