shenmegui 0.3.3 → 0.3.4
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 +5 -5
- data/lib/shenmegui/core.rb +15 -8
- data/lib/shenmegui/file_dialog.rb +2 -2
- data/lib/shenmegui/utils.rb +18 -51
- data/static/script.js +4 -4
- data/templates/body.erb +2 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f35798115e8f6d3bec99dc45df4d48b48d2a18e5
|
4
|
+
data.tar.gz: 5c0c4d7f0c220f66785e1ba351827a1cd0a137ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc2f7b20adb10653c15dfe216a622b49552284d59be3bcc8d8962c9036593c5dcfaf56731e2fae56fc14864d3b12e893a87a2ba2c035dfc51f5d3c98ae5d5200
|
7
|
+
data.tar.gz: bddf3a53791f9434da210e46b27a851ba2bc49a6c67958da1658b8816d673473d13b3a0b4502413dcb61188833c27a7fa1c4e03e6670fe00ce551692d87994c4
|
data/lib/shenmegui/controls.rb
CHANGED
@@ -81,7 +81,7 @@ module ShenmeGUI
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def render(material = {})
|
84
|
-
gem_path =
|
84
|
+
gem_path = __FILE__.match(/(.*)\/lib/)[1]
|
85
85
|
template_path = gem_path + "/templates"
|
86
86
|
type = self.class.name.match(/(?:.*::)(.+)/)[1].downcase
|
87
87
|
template = ::ERB.new File.read("#{template_path}/#{type}.erb")
|
@@ -97,12 +97,12 @@ module ShenmeGUI
|
|
97
97
|
end
|
98
98
|
|
99
99
|
class Body < Base
|
100
|
-
def render
|
101
|
-
gem_path =
|
100
|
+
def render(material = {})
|
101
|
+
gem_path = __FILE__.match(/(.*)\/lib/)[1]
|
102
102
|
static_path = gem_path + "/static"
|
103
103
|
style = %w{style}.collect{|x| File.read("#{static_path}/#{x}.css")}.join("\n")
|
104
104
|
script = File.read("#{static_path}/script.js")
|
105
|
-
super({style: style, script: script})
|
105
|
+
super({style: style, script: script}.merge(material))
|
106
106
|
end
|
107
107
|
|
108
108
|
end
|
@@ -154,7 +154,7 @@ module ShenmeGUI
|
|
154
154
|
|
155
155
|
class Checkbox < Base
|
156
156
|
property :options, :checked, :arrange
|
157
|
-
shortcut :options
|
157
|
+
shortcut :options
|
158
158
|
end
|
159
159
|
|
160
160
|
class Progress < Base
|
data/lib/shenmegui/core.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
1
3
|
module ShenmeGUI
|
2
4
|
|
3
5
|
@elements = []
|
@@ -28,7 +30,12 @@ module ShenmeGUI
|
|
28
30
|
|
29
31
|
def app(params={}, &block)
|
30
32
|
body(params, &block)
|
31
|
-
|
33
|
+
#找一个空闲的端口,不太好看
|
34
|
+
temp_server = TCPServer.open('localhost', 0)
|
35
|
+
@port = temp_server.addr[1]
|
36
|
+
temp_server.close
|
37
|
+
app_dir = File.expand_path($PROGRAM_NAME).match(/(.+)\/.+/)[1]
|
38
|
+
File.open("#{app_dir}/index.html", 'w'){ |f| f.write @elements[0].render(port: @port) }
|
32
39
|
nil
|
33
40
|
end
|
34
41
|
|
@@ -44,7 +51,7 @@ module ShenmeGUI
|
|
44
51
|
def get_save_file_name(params={})
|
45
52
|
FileDialog.get_save_file_name(params)
|
46
53
|
end
|
47
|
-
|
54
|
+
|
48
55
|
def enable_debugging
|
49
56
|
Thread.new do
|
50
57
|
ShenmeGUI.instance_eval do
|
@@ -66,7 +73,7 @@ module ShenmeGUI
|
|
66
73
|
def start!
|
67
74
|
ws_thread = Thread.new do
|
68
75
|
EM.run do
|
69
|
-
EM::WebSocket.run(:host => "0.0.0.0", :port =>
|
76
|
+
EM::WebSocket.run(:host => "0.0.0.0", :port => @port) do |ws|
|
70
77
|
ws.onopen do
|
71
78
|
puts "WebSocket connection open"
|
72
79
|
@elements.each do |e|
|
@@ -81,22 +88,22 @@ module ShenmeGUI
|
|
81
88
|
puts "Recieved message: #{msg}"
|
82
89
|
handle msg
|
83
90
|
end
|
84
|
-
|
91
|
+
|
85
92
|
@socket = ws
|
86
93
|
end
|
87
94
|
end
|
88
95
|
end
|
89
|
-
|
90
96
|
begin
|
91
|
-
|
97
|
+
app_dir = File.expand_path($PROGRAM_NAME).match(/(.+)\/.+/)[1]
|
98
|
+
index_path = "#{app_dir}/index.html"
|
92
99
|
`start file:///#{index_path}`
|
93
100
|
rescue
|
94
101
|
end
|
95
|
-
|
102
|
+
|
96
103
|
ws_thread.join
|
97
104
|
rescue Interrupt
|
98
105
|
puts 'bye~'
|
99
106
|
end
|
100
107
|
|
101
108
|
end
|
102
|
-
end
|
109
|
+
end
|
@@ -70,7 +70,7 @@ module ShenmeGUI
|
|
70
70
|
def self.get_open_file_name(params={})
|
71
71
|
ofn, path = construct_OPENFILENAME(params)
|
72
72
|
GetOpenFileName(ofn)
|
73
|
-
ofn
|
73
|
+
Fiddle.free(ofn.to_i)
|
74
74
|
path = path.split("\0")
|
75
75
|
path = path[1..-1].collect{|x| "#{path[0]}\\#{x}"} if path.size > 1
|
76
76
|
path.collect{|x| x.force_encoding('GBK').encode('UTF-8')}
|
@@ -80,7 +80,7 @@ module ShenmeGUI
|
|
80
80
|
def self.get_save_file_name(params={})
|
81
81
|
ofn, path = construct_OPENFILENAME(params)
|
82
82
|
GetSaveFileName(ofn)
|
83
|
-
ofn
|
83
|
+
Fiddle.free(ofn.to_i)
|
84
84
|
path.force_encoding('GBK').encode('UTF-8')
|
85
85
|
end
|
86
86
|
|
data/lib/shenmegui/utils.rb
CHANGED
@@ -1,59 +1,26 @@
|
|
1
1
|
module ShenmeGUI
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
define_method(k) do |*arr, &block|
|
14
|
-
result = v.bind(self).call(*arr, &block)
|
15
|
-
@owner.sync
|
16
|
-
result
|
2
|
+
@unhook_methods = {
|
3
|
+
array: %i{<< []= clear collect! compact! concat delete delete_at delete_if fill flatten! replace insert keep_if map map! pop push reject! replace rotate! select! shift shuffle! slice! sort! sort_by! uniq! unshift},
|
4
|
+
string: %i{<< []= capitalize! chomp! chop! clear concat delete! downcase! encode! force_encoding gsub! insert lstrip! succ! next! prepend replace reverse! rstrip! slice! squeeze! strip! sub! swapcase! tr! tr_s! upcase!},
|
5
|
+
hash: %i{[]= clear delete delete_if keep_if merge! update rehash reject! replace select! shift}
|
6
|
+
}
|
7
|
+
@unhook_methods.each do |k, v|
|
8
|
+
const_set("Hooked#{k.to_s.capitalize}", Class.new(const_get(k.to_s.capitalize)))
|
9
|
+
const_get("Hooked#{k.to_s.capitalize}").class_eval do
|
10
|
+
def initialize(obj, owner)
|
11
|
+
@owner = owner
|
12
|
+
super(obj)
|
17
13
|
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
class HookedString < String
|
23
|
-
@unhook_methods = %i{<< []= capitalize! chomp! chop! clear concat delete! downcase! encode! force_encoding gsub! insert lstrip! succ! next! prepend replace reverse! rstrip! slice! squeeze! strip! sub! swapcase! tr! tr_s! upcase!}
|
24
|
-
@unhook_methods = Hash[@unhook_methods.collect{|x| [x, String.instance_method(x)]}]
|
25
|
-
|
26
|
-
def initialize(str, owner)
|
27
|
-
@owner = owner
|
28
|
-
super(str)
|
29
|
-
end
|
30
14
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
15
|
+
methods = Hash[v.collect{|x| [x, const_get(k.to_s.capitalize).instance_method(x)]}]
|
16
|
+
methods.each do |k, v|
|
17
|
+
define_method(k) do |*arr, &block|
|
18
|
+
result = v.bind(self).call(*arr, &block)
|
19
|
+
@owner.sync
|
20
|
+
result
|
21
|
+
end
|
36
22
|
end
|
37
|
-
end
|
38
23
|
|
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
24
|
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
25
|
end
|
59
26
|
end
|
data/static/script.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
var websocket =
|
1
|
+
var websocket =
|
2
2
|
(function configureWebSocket(){
|
3
|
-
var wsUrl = "ws://localhost/";
|
3
|
+
var wsUrl = "ws://localhost:" + wsPort + "/";
|
4
4
|
|
5
5
|
var websocket = new WebSocket(wsUrl);
|
6
6
|
websocket.onopen = function(evt){
|
@@ -166,7 +166,7 @@ var syncHandlers = {
|
|
166
166
|
}
|
167
167
|
}
|
168
168
|
}
|
169
|
-
|
169
|
+
|
170
170
|
}),
|
171
171
|
|
172
172
|
radio: (function(target, data){
|
@@ -231,4 +231,4 @@ function handleMessage(msg){
|
|
231
231
|
target.focus();
|
232
232
|
break;
|
233
233
|
}
|
234
|
-
}
|
234
|
+
}
|
data/templates/body.erb
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.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CicholGricenchos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-websocket
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.5.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.5.1
|
27
27
|
description: a simple HTML GUI for Ruby
|
28
28
|
email: cichol@live.cn
|
29
29
|
executables: []
|