troshka 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/troshka +5 -3
- data/lib/shirka/app.rb +41 -0
- data/lib/shirka/components.rb +31 -0
- data/lib/shirka/controller.rb +57 -0
- data/lib/shirka/eventalk.rb +41 -0
- data/lib/shirka/qt.rb +4 -0
- data/lib/shirka/qt/app.rb +21 -0
- data/lib/shirka/qt/list/controller.rb +38 -0
- data/lib/shirka/qt/list/view.rb +23 -0
- data/lib/shirka/qt/list_item/controller.rb +31 -0
- data/lib/shirka/qt/list_item/view.rb +19 -0
- data/lib/shirka/qt/multipanel/controller.rb +8 -0
- data/lib/shirka/qt/multipanel/view.rb +31 -0
- data/lib/shirka/qt/tab/view.rb +16 -0
- data/lib/shirka/qt/tree/controller.rb +40 -0
- data/lib/shirka/qt/tree/view.rb +26 -0
- data/lib/shirka/qt/tree_item/controller.rb +51 -0
- data/lib/shirka/qt/tree_item/view.rb +23 -0
- data/lib/shirka/shirka.rb +8 -0
- data/lib/shirka/view.rb +47 -0
- data/lib/troshka/app.rb +12 -52
- data/lib/troshka/detail/controller.rb +25 -0
- data/lib/troshka/detail/view.rb +5 -0
- data/lib/troshka/detail_panel_enumerable/controller.rb +14 -0
- data/lib/troshka/detail_panel_enumerable/view.rb +5 -0
- data/lib/troshka/detail_panel_hash/controller.rb +14 -0
- data/lib/troshka/detail_panel_hash/view.rb +5 -0
- data/lib/troshka/detail_panel_item_enumerable/controller.rb +14 -0
- data/lib/troshka/detail_panel_item_enumerable/view.rb +10 -0
- data/lib/troshka/detail_panel_item_hash/controller.rb +14 -0
- data/lib/troshka/detail_panel_item_hash/view.rb +10 -0
- data/lib/troshka/detail_panel_item_object/controller.rb +4 -0
- data/lib/troshka/detail_panel_item_object/view.rb +6 -0
- data/lib/troshka/detail_panel_object/controller.rb +5 -0
- data/lib/troshka/detail_panel_object/view.rb +9 -0
- data/lib/troshka/editor/bond_completer.rb +14 -0
- data/lib/troshka/editor/completer.rb +4 -0
- data/lib/troshka/editor/controller.rb +71 -0
- data/lib/troshka/editor/line.rb +43 -0
- data/lib/troshka/editor/qscintilla_view.rb +56 -0
- data/lib/troshka/editor/qtextedit_view.rb +28 -0
- data/lib/troshka/editor/qxscintilla.rb +98 -0
- data/lib/troshka/editor/shell.rb +30 -0
- data/lib/troshka/main/controller.rb +16 -0
- data/lib/troshka/main/view.rb +50 -0
- data/lib/troshka/methods/controller.rb +16 -0
- data/lib/troshka/methods/view.rb +13 -0
- data/lib/troshka/methods_item/controller.rb +4 -0
- data/lib/troshka/methods_item/view.rb +5 -0
- data/lib/troshka/output/controller.rb +13 -0
- data/lib/troshka/output/view.rb +11 -0
- data/lib/troshka/output_item/controller.rb +15 -0
- data/lib/troshka/output_item/view.rb +9 -0
- data/lib/troshka/output_item_code/controller.rb +5 -0
- data/lib/troshka/output_item_code/view.rb +5 -0
- data/lib/troshka/output_item_exception/controller.rb +2 -0
- data/lib/troshka/output_item_exception/view.rb +6 -0
- data/lib/troshka/output_item_obj/controller.rb +2 -0
- data/lib/troshka/output_item_obj/view.rb +2 -0
- data/lib/troshka/output_item_output/controller.rb +5 -0
- data/lib/troshka/output_item_output/view.rb +5 -0
- data/resources/logo.png +0 -0
- metadata +63 -27
- data/lib/troshka.rb +0 -15
- data/lib/troshka/detail.rb +0 -25
- data/lib/troshka/detail_anything.rb +0 -9
- data/lib/troshka/detail_array_hash.rb +0 -86
- data/lib/troshka/editor.rb +0 -113
- data/lib/troshka/output.rb +0 -58
- data/lib/troshka/qt_editor.rb +0 -27
- data/lib/troshka/shell.rb +0 -27
@@ -0,0 +1,51 @@
|
|
1
|
+
module Shirka
|
2
|
+
module Qt
|
3
|
+
|
4
|
+
class TreeItemController < ::Shirka::Controller
|
5
|
+
def initialize(app, parent=nil, data=nil)
|
6
|
+
@app = app
|
7
|
+
@parent = parent
|
8
|
+
@components = Components.new
|
9
|
+
@root = data[:root]
|
10
|
+
@data = data[:text]
|
11
|
+
watch @app
|
12
|
+
init @data
|
13
|
+
end
|
14
|
+
|
15
|
+
def init(data)
|
16
|
+
data.each { |i| add_item i } if data.respond_to? :each
|
17
|
+
end
|
18
|
+
|
19
|
+
def view_class
|
20
|
+
name = self.class.to_s.sub(/Controller$/, 'View')
|
21
|
+
Object.const_get name rescue ::Shirka::Qt::TreeItemView
|
22
|
+
end
|
23
|
+
|
24
|
+
def view
|
25
|
+
@view ||= view_class.new self, data
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_item(text='', controller_class=nil)
|
29
|
+
controller_class ||= item_controller_class
|
30
|
+
comp = controller_class.new app, self, {text: text, root: @root}
|
31
|
+
add_component comp
|
32
|
+
end
|
33
|
+
|
34
|
+
def item_controller_class
|
35
|
+
self.class rescue ::Shirka::Qt::TreeItemController
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_component_adding(data=nil)
|
39
|
+
@root.on_component_added self, id
|
40
|
+
end
|
41
|
+
|
42
|
+
def id
|
43
|
+
view.id
|
44
|
+
end
|
45
|
+
|
46
|
+
def on_double_clicked
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Shirka
|
2
|
+
module Qt
|
3
|
+
|
4
|
+
class TreeItemView < ::Shirka::View
|
5
|
+
def widget_class
|
6
|
+
::Qt::TreeWidgetItem
|
7
|
+
end
|
8
|
+
|
9
|
+
def build(widget)
|
10
|
+
widget.setText 0, data.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def id
|
14
|
+
widget.object_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_view_adding(view, slot=nil)
|
18
|
+
widget.insertChild widget.childCount, view.widget
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/shirka/view.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Shirka
|
2
|
+
class View
|
3
|
+
include Eventalk
|
4
|
+
|
5
|
+
attr_reader :controller
|
6
|
+
attr_reader :data
|
7
|
+
attr_reader :label
|
8
|
+
|
9
|
+
def initialize(controller, data=nil)
|
10
|
+
@controller = controller
|
11
|
+
@data = data
|
12
|
+
watch @controller
|
13
|
+
init data
|
14
|
+
end
|
15
|
+
|
16
|
+
def init(data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_view_adding(view, slot=nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
def on_view_added(view, slot=nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
def widget_class
|
26
|
+
end
|
27
|
+
|
28
|
+
def widget
|
29
|
+
return @widget unless @widget.nil?
|
30
|
+
|
31
|
+
@widget = widget_class.new
|
32
|
+
build @widget
|
33
|
+
style @widget
|
34
|
+
@widget
|
35
|
+
end
|
36
|
+
|
37
|
+
def on_component_added(data=nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
def build(widget)
|
41
|
+
end
|
42
|
+
|
43
|
+
def style(widget)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/troshka/app.rb
CHANGED
@@ -1,59 +1,19 @@
|
|
1
|
-
|
1
|
+
%w{ shirka qt }.each {|lib| require_relative "../shirka/#{lib}"}
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
@editor.app = self
|
9
|
-
|
10
|
-
@output = Output.new
|
11
|
-
@output.app = self
|
12
|
-
|
13
|
-
@detail = Detail.new
|
14
|
-
@detail.app = self
|
15
|
-
|
16
|
-
@splitterh = Qt::Splitter.new
|
17
|
-
@splitterv = Qt::Splitter.new
|
18
|
-
@shell = Shell.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def complete(word, line)
|
22
|
-
Bond.agent.call word, line
|
23
|
-
end
|
24
|
-
|
25
|
-
def run(text)
|
26
|
-
out = @shell.run text
|
27
|
-
@editor.text = ""
|
28
|
-
out[:text] = text
|
29
|
-
@output.add out
|
30
|
-
@output.scrollToBottom
|
31
|
-
@detail.view out[:obj]
|
32
|
-
end
|
33
|
-
|
34
|
-
def replace_code(text)
|
35
|
-
@editor.text = text
|
36
|
-
@editor.move_to_end
|
37
|
-
@editor.setFocus
|
3
|
+
module Troshka
|
4
|
+
|
5
|
+
class App < ::Shirka::Qt::App
|
6
|
+
def components
|
7
|
+
@components ||= {}
|
38
8
|
end
|
39
|
-
|
40
|
-
def start
|
41
|
-
Bond.start
|
42
|
-
|
43
|
-
@splitterv.set_orientation Qt::Horizontal
|
44
|
-
@splitterh.set_orientation Qt::Vertical
|
45
|
-
@splitterh.resize 600,400
|
46
|
-
|
47
|
-
@splitterh.add_widget @splitterv
|
48
|
-
@splitterv.add_widget @output
|
49
|
-
@splitterv.add_widget @detail
|
50
|
-
|
51
|
-
@splitterh.add_widget @editor
|
52
|
-
@editor.setFocus
|
53
|
-
@splitterh.show
|
54
9
|
|
55
|
-
|
10
|
+
def self.last_result
|
11
|
+
@@last_result
|
56
12
|
end
|
13
|
+
|
14
|
+
def self.last_result=(result)
|
15
|
+
@@last_result = result
|
16
|
+
end
|
57
17
|
end
|
58
18
|
|
59
19
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class DetailController < Shirka::Qt::MultipanelController
|
2
|
+
def init(data)
|
3
|
+
add_item "", DetailPanelObjectController
|
4
|
+
end
|
5
|
+
|
6
|
+
def on_starting(e)
|
7
|
+
watch app.components[:editor]
|
8
|
+
end
|
9
|
+
|
10
|
+
def on_code_evaluated(e)
|
11
|
+
obj = e.msg[:obj]
|
12
|
+
|
13
|
+
#controller_class = if obj.respond_to? :each
|
14
|
+
# DetailPanelEnumerableController
|
15
|
+
#else
|
16
|
+
# DetailPanelController
|
17
|
+
#end
|
18
|
+
|
19
|
+
name = obj.class.ancestors
|
20
|
+
.map{|i| "DetailPanel#{i}Controller"}
|
21
|
+
.find {|i| Object.const_get i rescue false}
|
22
|
+
|
23
|
+
add_item obj, Object.const_get(name) unless name.nil?
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DetailPanelEnumerableController < Shirka::Qt::TreeController
|
2
|
+
def init(data)
|
3
|
+
@item_ids = {}
|
4
|
+
data.each_with_index {|obj, i| add_item [i, obj], item_class(obj)}
|
5
|
+
end
|
6
|
+
|
7
|
+
def item_class(obj)
|
8
|
+
name = obj.class.ancestors
|
9
|
+
.map {|i| "DetailPanelItem#{i}Controller"}
|
10
|
+
.find {|i| Object.const_get i rescue false}
|
11
|
+
|
12
|
+
Object.const_get(name)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DetailPanelHashController < Shirka::Qt::TreeController
|
2
|
+
def init(data)
|
3
|
+
@item_ids = {}
|
4
|
+
data.each {|k, v| add_item [k, v], item_class(v)}
|
5
|
+
end
|
6
|
+
|
7
|
+
def item_class(obj)
|
8
|
+
name = obj.class.ancestors
|
9
|
+
.map {|i| "DetailPanelItem#{i}Controller"}
|
10
|
+
.find {|i| Object.const_get i rescue false}
|
11
|
+
|
12
|
+
Object.const_get(name)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DetailPanelItemEnumerableController < ::Shirka::Qt::TreeItemController
|
2
|
+
def init(data)
|
3
|
+
@item_ids = {}
|
4
|
+
data[1].each_with_index {|i, index| add_item [index, i], item_class(i)}
|
5
|
+
end
|
6
|
+
|
7
|
+
def item_class(obj)
|
8
|
+
name = obj.class.ancestors
|
9
|
+
.map {|i| "DetailPanelItem#{i}Controller"}
|
10
|
+
.find {|i| Object.const_get i rescue false}
|
11
|
+
|
12
|
+
Object.const_get(name)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class DetailPanelItemEnumerableView < ::Shirka::Qt::TreeItemView
|
2
|
+
def build(widget)
|
3
|
+
index, value = data
|
4
|
+
widget.setText 0, index.to_s
|
5
|
+
|
6
|
+
widget.setText 1, "#{value.class} #{value.count} items"
|
7
|
+
widget.setForeground 0, Qt::Brush.new(Qt::Color.new 128, 128, 128)
|
8
|
+
widget.setForeground 1, Qt::Brush.new(Qt::Color.new 128, 128, 128)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DetailPanelItemHashController < ::Shirka::Qt::TreeItemController
|
2
|
+
def init(data)
|
3
|
+
@item_ids = {}
|
4
|
+
data[1].each {|key, value| add_item [key, value], item_class(value)}
|
5
|
+
end
|
6
|
+
|
7
|
+
def item_class(obj)
|
8
|
+
name = obj.class.ancestors
|
9
|
+
.map {|i| "DetailPanelItem#{i}Controller"}
|
10
|
+
.find {|i| Object.const_get i rescue false}
|
11
|
+
|
12
|
+
Object.const_get(name)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class DetailPanelItemHashView < ::Shirka::Qt::TreeItemView
|
2
|
+
def build(widget)
|
3
|
+
index, value = data
|
4
|
+
widget.setText 0, index.to_s
|
5
|
+
|
6
|
+
widget.setText 1, "#{value.class} #{value.count} items"
|
7
|
+
widget.setForeground 0, Qt::Brush.new(Qt::Color.new 128, 128, 128)
|
8
|
+
widget.setForeground 1, Qt::Brush.new(Qt::Color.new 128, 128, 128)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative 'shell'
|
2
|
+
require_relative 'line'
|
3
|
+
|
4
|
+
class EditorController < Shirka::Controller
|
5
|
+
def on_starting(e)
|
6
|
+
watch app.components[:output]
|
7
|
+
end
|
8
|
+
|
9
|
+
def shell
|
10
|
+
@shell ||= Shell.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def completer
|
14
|
+
if @completer.nil?
|
15
|
+
begin
|
16
|
+
require_relative 'bond_completer'
|
17
|
+
rescue LoadError
|
18
|
+
require_relative 'completer'
|
19
|
+
ensure
|
20
|
+
@completer = Completer.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
@completer
|
24
|
+
end
|
25
|
+
|
26
|
+
def view_class
|
27
|
+
if @view_class.nil?
|
28
|
+
begin
|
29
|
+
require_relative 'qscintilla_view'
|
30
|
+
rescue LoadError
|
31
|
+
require_relative 'qtextedit_view'
|
32
|
+
ensure
|
33
|
+
@view_class = EditorView
|
34
|
+
end
|
35
|
+
end
|
36
|
+
@view_class
|
37
|
+
end
|
38
|
+
|
39
|
+
#Events
|
40
|
+
|
41
|
+
def code_entering(text)
|
42
|
+
time_begin = Time.now
|
43
|
+
result = shell.run text
|
44
|
+
time_end = Time.now
|
45
|
+
result[:time] = (time_end - time_begin) * 1000
|
46
|
+
fire :code_evaluated, result
|
47
|
+
end
|
48
|
+
|
49
|
+
def autocompletion_list_requesting(text, cursor)
|
50
|
+
@line = Line.new text, cursor
|
51
|
+
list = completer.complete @line.text(@line.word), @line.text
|
52
|
+
|
53
|
+
unless list.empty?
|
54
|
+
prefix = list.first.dup
|
55
|
+
prefix.chop! while @line.text.rindex(prefix).nil?
|
56
|
+
@line.selection = [cursor - prefix.size, cursor]
|
57
|
+
|
58
|
+
view.autocompletion_list_requested list, @line.selection
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def autocompletion_item_selecting(item)
|
63
|
+
@line.replace_selection_text item
|
64
|
+
view.autocompletion_item_selected @line.text, @line.cursor
|
65
|
+
end
|
66
|
+
|
67
|
+
def on_code_selected(e)
|
68
|
+
view.replace_code e.msg
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|