troshka 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/bin/troshka +5 -3
  2. data/lib/shirka/app.rb +41 -0
  3. data/lib/shirka/components.rb +31 -0
  4. data/lib/shirka/controller.rb +57 -0
  5. data/lib/shirka/eventalk.rb +41 -0
  6. data/lib/shirka/qt.rb +4 -0
  7. data/lib/shirka/qt/app.rb +21 -0
  8. data/lib/shirka/qt/list/controller.rb +38 -0
  9. data/lib/shirka/qt/list/view.rb +23 -0
  10. data/lib/shirka/qt/list_item/controller.rb +31 -0
  11. data/lib/shirka/qt/list_item/view.rb +19 -0
  12. data/lib/shirka/qt/multipanel/controller.rb +8 -0
  13. data/lib/shirka/qt/multipanel/view.rb +31 -0
  14. data/lib/shirka/qt/tab/view.rb +16 -0
  15. data/lib/shirka/qt/tree/controller.rb +40 -0
  16. data/lib/shirka/qt/tree/view.rb +26 -0
  17. data/lib/shirka/qt/tree_item/controller.rb +51 -0
  18. data/lib/shirka/qt/tree_item/view.rb +23 -0
  19. data/lib/shirka/shirka.rb +8 -0
  20. data/lib/shirka/view.rb +47 -0
  21. data/lib/troshka/app.rb +12 -52
  22. data/lib/troshka/detail/controller.rb +25 -0
  23. data/lib/troshka/detail/view.rb +5 -0
  24. data/lib/troshka/detail_panel_enumerable/controller.rb +14 -0
  25. data/lib/troshka/detail_panel_enumerable/view.rb +5 -0
  26. data/lib/troshka/detail_panel_hash/controller.rb +14 -0
  27. data/lib/troshka/detail_panel_hash/view.rb +5 -0
  28. data/lib/troshka/detail_panel_item_enumerable/controller.rb +14 -0
  29. data/lib/troshka/detail_panel_item_enumerable/view.rb +10 -0
  30. data/lib/troshka/detail_panel_item_hash/controller.rb +14 -0
  31. data/lib/troshka/detail_panel_item_hash/view.rb +10 -0
  32. data/lib/troshka/detail_panel_item_object/controller.rb +4 -0
  33. data/lib/troshka/detail_panel_item_object/view.rb +6 -0
  34. data/lib/troshka/detail_panel_object/controller.rb +5 -0
  35. data/lib/troshka/detail_panel_object/view.rb +9 -0
  36. data/lib/troshka/editor/bond_completer.rb +14 -0
  37. data/lib/troshka/editor/completer.rb +4 -0
  38. data/lib/troshka/editor/controller.rb +71 -0
  39. data/lib/troshka/editor/line.rb +43 -0
  40. data/lib/troshka/editor/qscintilla_view.rb +56 -0
  41. data/lib/troshka/editor/qtextedit_view.rb +28 -0
  42. data/lib/troshka/editor/qxscintilla.rb +98 -0
  43. data/lib/troshka/editor/shell.rb +30 -0
  44. data/lib/troshka/main/controller.rb +16 -0
  45. data/lib/troshka/main/view.rb +50 -0
  46. data/lib/troshka/methods/controller.rb +16 -0
  47. data/lib/troshka/methods/view.rb +13 -0
  48. data/lib/troshka/methods_item/controller.rb +4 -0
  49. data/lib/troshka/methods_item/view.rb +5 -0
  50. data/lib/troshka/output/controller.rb +13 -0
  51. data/lib/troshka/output/view.rb +11 -0
  52. data/lib/troshka/output_item/controller.rb +15 -0
  53. data/lib/troshka/output_item/view.rb +9 -0
  54. data/lib/troshka/output_item_code/controller.rb +5 -0
  55. data/lib/troshka/output_item_code/view.rb +5 -0
  56. data/lib/troshka/output_item_exception/controller.rb +2 -0
  57. data/lib/troshka/output_item_exception/view.rb +6 -0
  58. data/lib/troshka/output_item_obj/controller.rb +2 -0
  59. data/lib/troshka/output_item_obj/view.rb +2 -0
  60. data/lib/troshka/output_item_output/controller.rb +5 -0
  61. data/lib/troshka/output_item_output/view.rb +5 -0
  62. data/resources/logo.png +0 -0
  63. metadata +63 -27
  64. data/lib/troshka.rb +0 -15
  65. data/lib/troshka/detail.rb +0 -25
  66. data/lib/troshka/detail_anything.rb +0 -9
  67. data/lib/troshka/detail_array_hash.rb +0 -86
  68. data/lib/troshka/editor.rb +0 -113
  69. data/lib/troshka/output.rb +0 -58
  70. data/lib/troshka/qt_editor.rb +0 -27
  71. data/lib/troshka/shell.rb +0 -27
@@ -0,0 +1,43 @@
1
+ class Line
2
+ attr_accessor :cursor
3
+ attr_accessor :selection
4
+
5
+ def initialize(text, cursor=0)
6
+ @text = text
7
+ @cursor = cursor
8
+ end
9
+
10
+ def word(separator=/[ ,();]/)
11
+ word_begin = @text.rindex(separator, cursor-1)+1 rescue 0
12
+ word_begin = 0 if word_begin.nil?
13
+ word_end = @text.index(separator, cursor)
14
+ word_end = size if word_end.nil?
15
+
16
+ [word_begin, word_end]
17
+ end
18
+
19
+ def text(range=nil)
20
+ if range.nil?
21
+ @text
22
+ else
23
+ if range[0]==range[1]
24
+ ""
25
+ else
26
+ @text[range[0]..range[1]-1]
27
+ end
28
+ end
29
+ end
30
+
31
+ def replace_selection_text(text)
32
+ pre = self.text [0, selection.first]
33
+ post = self.text [selection[1], size]
34
+
35
+ @text = "#{pre}#{text}#{post}"
36
+ @cursor = selection[1] + text.size
37
+ @selection = nil
38
+ end
39
+
40
+ def size
41
+ @text.size
42
+ end
43
+ end
@@ -0,0 +1,56 @@
1
+ require_relative 'qxscintilla'
2
+
3
+ class EditorView < Shirka::View
4
+ def widget_class
5
+ Qx::Scintilla
6
+ end
7
+
8
+ def build(widget)
9
+ widget.setAutoIndent true
10
+ widget.setIndentationGuides true
11
+ widget.setIndentationWidth 2
12
+ widget.setFolding ::Qsci::Scintilla::PlainFoldStyle
13
+ widget.setLexer ::Qsci::LexerRuby.new
14
+ widget.setMarginWidth 1, 0
15
+
16
+ # Events
17
+ widget.key_pressed do |e|
18
+ # Autocompletion hotkey
19
+ if e.key==Qt::Key_Space && e.modifiers==Qt::Control_Modifier
20
+ controller.autocompletion_list_requesting \
21
+ widget.current_line_text, widget.current_column_number rescue pust $!
22
+ e.continue = false
23
+ # Enter code hotkey
24
+ elsif e.key==Qt::Key_Return && e.modifiers==Qt::Control_Modifier
25
+ controller.code_entering widget.text
26
+ e.continue = false
27
+ end
28
+ end #key_pressed
29
+
30
+ widget.user_list_activated do |id, text|
31
+ controller.autocompletion_item_selecting text
32
+ end
33
+
34
+ end #build
35
+
36
+ def autocompletion_list_requested(list, selection)
37
+ widget.move_cursor(column: selection.first)
38
+ widget.show_user_list 1, list
39
+ widget.move_cursor(column: selection[1])
40
+ end
41
+
42
+ def autocompletion_item_selected(line, cursor)
43
+ widget.replace_line line
44
+ widget.move_cursor(column: cursor)
45
+ end
46
+
47
+ def on_code_evaluated(e)
48
+ widget.text = ""
49
+ end
50
+
51
+ def replace_code(code)
52
+ widget.text = code
53
+ widget.move_cursor_to_end
54
+ widget.setFocus
55
+ end
56
+ end
@@ -0,0 +1,28 @@
1
+ class EditorView < Shirka::View
2
+ def widget_class
3
+ Qt::TextEdit
4
+ end
5
+
6
+ def build(widget)
7
+ v = self
8
+
9
+ widget.define_singleton_method :keyPressEvent do |evt|
10
+ if evt.key==Qt::Key_Return && evt.modifiers==Qt::Control_Modifier
11
+ v.controller.code_entering toPlainText
12
+ else
13
+ super evt
14
+ end
15
+ end #kewyPressEvent
16
+ end
17
+
18
+ def on_code_evaluated(e)
19
+ widget.setPlainText ""
20
+ end
21
+
22
+ def replace_code(code)
23
+ widget.setPlainText code
24
+ widget.moveCursor Qt::TextCursor::End
25
+ widget.setFocus
26
+ end
27
+
28
+ end
@@ -0,0 +1,98 @@
1
+ require "qscintilla"
2
+
3
+ module Qx
4
+ class Scintilla < ::Qsci::Scintilla
5
+
6
+ def initialize
7
+ super
8
+ connect(SIGNAL "userListActivated(int, const QString)") do |id, text|
9
+ @autocompletion_activated.(id, text) rescue nil
10
+ end
11
+ end
12
+
13
+ def keyPressEvent(event)
14
+ e = OpenStruct.new
15
+ e.key = event.key
16
+ e.modifiers = event.modifiers
17
+ e.continue = true
18
+
19
+ @key_pressed.(e) rescue nil
20
+ super event if e.continue
21
+ end
22
+
23
+ #Events
24
+ def user_list_activated(&block)
25
+ @autocompletion_activated = block
26
+ end
27
+
28
+ def key_pressed(&blk)
29
+ @key_pressed = blk
30
+ end
31
+
32
+ # Operations
33
+ def current_line_number
34
+ # SCI_LINEFROMPOSITION
35
+ SendScintilla(2166,pos,0)
36
+ end
37
+
38
+ def current_column_number
39
+ # SCI_GETCOLUMN = 2129
40
+ SendScintilla(2129,pos,0)
41
+ end
42
+
43
+ def line_length(line)
44
+ # SCI_GETLINEENDPOSITION
45
+ SendScintilla(2136, line, 0)
46
+ end
47
+
48
+ def line_text(line_number)
49
+ text line_number
50
+ end
51
+
52
+ def current_line_text
53
+ line_text current_line_number
54
+ end
55
+
56
+ def select_line(line_number=nil)
57
+ line ||= current_line_number
58
+ setSelection line, 0, line, line_length(line)
59
+ end
60
+
61
+ def replace_line(text, line_number=nil)
62
+ select_line
63
+ replaceSelectedText text
64
+ end
65
+
66
+ def move_cursor(position)
67
+ line, column = position[:line], position[:column]
68
+ line ||= current_line_number
69
+ column ||= current_column_number
70
+
71
+ setCursorPosition line, column
72
+ end
73
+
74
+ def number_of_lines
75
+ lines
76
+ end
77
+
78
+ def move_cursor_to_end
79
+ setCursorPosition number_of_lines, line_length(number_of_lines)
80
+ end
81
+
82
+ def current_position
83
+ {line: current_line_number, column: current_column_number}
84
+ end
85
+
86
+ def current_line
87
+ {text: current_line_text, line_number: current_line_number}
88
+ end
89
+
90
+ private
91
+
92
+ def pos
93
+ # SCI_GETCURRENTPOS
94
+ SendScintilla(2008, 0, 0)
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,30 @@
1
+ require 'stringio'
2
+
3
+ class Shell
4
+ attr_accessor :result
5
+
6
+ def initialize
7
+ @binding = TOPLEVEL_BINDING
8
+ $stdout = StringIO.new
9
+ end
10
+
11
+ def run(str)
12
+ result = eval(str, @binding, "(troshka)")
13
+ ::Troshka::App.last_result = result
14
+ eval("_ = Troshka::App.last_result", @binding)
15
+
16
+ exception = nil
17
+
18
+ $stdout.rewind
19
+ output = $stdout.read
20
+ $stdout.truncate(0)
21
+ $stdout.rewind
22
+ rescue Exception => e
23
+ output = nil
24
+ obj = nil
25
+ exception = e
26
+ ensure
27
+ return {code: str, output: output, obj: result, exception: exception}
28
+ end
29
+
30
+ end
@@ -0,0 +1,16 @@
1
+ class MainController < Shirka::Controller
2
+ def start
3
+ view.show
4
+ end
5
+
6
+ def init(data)
7
+ app.components[:output] = OutputController.new(app, self, [])
8
+ add_component app.components[:output], :main
9
+
10
+ add_component DetailController.new(app, self, []), :info
11
+ add_component MethodsController.new(app, self, []), :info2
12
+
13
+ app.components[:editor] = EditorController.new(app, self, [])
14
+ add_component app.components[:editor], :editor
15
+ end
16
+ end
@@ -0,0 +1,50 @@
1
+ class MainView < ::Shirka::View
2
+ def widget
3
+ return @widget unless @widget.nil?
4
+
5
+ @widget = Qt::MainWindow.new
6
+
7
+ @splitter1 = Qt::Splitter.new
8
+ @splitter1.set_orientation Qt::Horizontal
9
+
10
+ @splitter2 = Qt::Splitter.new
11
+ @splitter2.set_orientation Qt::Vertical
12
+
13
+ @splitter3 = Qt::Splitter.new
14
+ @splitter3.set_orientation Qt::Vertical
15
+
16
+ #@main = Qt::TabWidget.new
17
+ #@info = Qt::TabWidget.new
18
+
19
+
20
+ @splitter1.add_widget @splitter2
21
+ #@splitter2.add_widget @main
22
+
23
+ @splitter1.add_widget @splitter3
24
+ #@splitter3.add_widget @info
25
+
26
+ @widget.setCentralWidget @splitter1
27
+ @widget
28
+ end
29
+
30
+
31
+ def on_view_adding(view, slot=nil)
32
+ widget
33
+ case slot
34
+ when :editor
35
+ @splitter2.add_widget view.widget
36
+ view.widget.setFocus
37
+ when :info
38
+ #@info.addTab view.widget, view.label
39
+ @splitter3.add_widget view.widget
40
+ when :main
41
+ @splitter2.add_widget view.widget
42
+ when :info2
43
+ @splitter3.add_widget view.widget
44
+ end
45
+ end
46
+
47
+ def show
48
+ widget.show
49
+ end
50
+ end
@@ -0,0 +1,16 @@
1
+ class MethodsController < Shirka::Qt::TreeController
2
+ def on_starting(e)
3
+ watch app.components[:editor]
4
+ end
5
+
6
+ def on_code_evaluated(e)
7
+ view.clear
8
+ obj = e.msg[:obj]
9
+ #obj.methods.sort.each {|m| puts m.to_s}
10
+ #obj.methods.sort.each {|m| add_item m.to_s}
11
+ add_item ["class", obj.class.to_s]
12
+ add_item ["object_id", obj.object_id.to_s]
13
+ add_item ["methods", obj.methods.size.to_s]
14
+ add_item ["count", obj.count.to_s] rescue nil
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ class MethodsView < Shirka::Qt::TreeView
2
+ def label
3
+ "Methods"
4
+ end
5
+
6
+ def clear
7
+ widget.clear
8
+ end
9
+
10
+ def style(widget)
11
+ widget.setHeaderLabels ["Property", "Value"]
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ class MethodsItemController < ::Shirka::Qt::TreeItemController
2
+ def init(data)
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ class MethodsItemView < ::Shirka::Qt::TreeItemView
2
+ def build(widget)
3
+ data.each_with_index {|item, i| widget.setText i, item}
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ class OutputController < Shirka::Qt::TreeController
2
+ def on_starting(e)
3
+ watch app.components[:editor]
4
+ end
5
+
6
+ def on_code_evaluated(e)
7
+ add_item e.msg
8
+ end
9
+
10
+ def on_code_selected(e)
11
+ forward e
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class OutputView < Shirka::Qt::TreeView
2
+ def on_view_adding(view, slot=nil)
3
+ super
4
+ view.widget.setExpanded true
5
+ widget.scrollToBottom
6
+ end
7
+
8
+ def label
9
+ "Output"
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class OutputItemController < Shirka::Qt::TreeItemController
2
+ def init(data)
3
+ add_item data[:code], OutputItemCodeController
4
+ if data[:exception].nil?
5
+ add_item data[:obj].inspect, OutputItemObjController
6
+ add_item data[:output], OutputItemOutputController unless data[:output].to_s.empty?
7
+ else
8
+ add_item data[:exception], OutputItemExceptionController
9
+ end
10
+ end
11
+
12
+ def view
13
+ @view ||= view_class.new self, data[:time]
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class OutputItemView < Shirka::Qt::TreeItemView
2
+ def init(data)
3
+ @data = "Time elapsed: %.3f ms" % data
4
+ end
5
+
6
+ def style(widget)
7
+ widget.setForeground 0, Qt::Brush.new(Qt::Color.new 100, 100, 100)
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class OutputItemCodeController < Shirka::Qt::TreeItemController
2
+ def on_double_clicked
3
+ fire :code_selected, data
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class OutputItemCodeView < Shirka::Qt::TreeItemView
2
+ def style(widget)
3
+ widget.setForeground 0, Qt::Brush.new(Qt::Color.new 0, 0, 255)
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ class OutputItemExceptionController < Shirka::Qt::TreeItemController
2
+ end