Skip to content

Commit 5f6fc5a

Browse files
committed
Code is not ready yet
Code steel contains different path I'll fix it later not ready for release yet
1 parent 3ad1691 commit 5f6fc5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3793
-10
lines changed

application/__init__py.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from noob.application.build_cache import BuildCache
2+
from noob.application.application import Application
3+
4+

application/application.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
from noob.queries import *
2+
from noob.application.build_cache import BuildCache
3+
from noob.interface.common.actions import *
4+
5+
6+
class Application():
7+
"""docstring for Application"""
8+
active_applications = {}
9+
build_cache = BuildCache()
10+
11+
def __init__(self,vid):
12+
self.history = []
13+
self.state = {}
14+
self.ui_controller = None
15+
self.vid = vid
16+
17+
def create_application_for_view(vid):
18+
if vid not in Application.active_applications:
19+
Application.active_applications[vid] = Application(vid)
20+
21+
def get_application(vid):
22+
Application.create_application_for_view(vid)
23+
return Application.active_applications[vid]
24+
25+
26+
27+
28+
29+
def respond_to_query(self,interface,query_description):
30+
extra = {"state":self.state,"history":self.history}
31+
view_information = interface.get_view_information()
32+
ui_information = interface.get_ui_information()
33+
34+
# extract code and change count and reuse previous build if possible
35+
code = view_information["code"]
36+
change_count = view_information["change_count"]
37+
latest_build = Application.build_cache.get_build(self.vid,change_count)
38+
39+
# get the corresponding query and execute it
40+
s = get_query(query_description)(code,latest_build)
41+
s(view_information,query_description,extra)
42+
43+
# register build for later use
44+
b = s.get_the_latest_build()
45+
if b:
46+
Application.build_cache.register_build(self.vid,change_count,b)
47+
48+
if isinstance(s,SelectionQuery):
49+
result = s.result
50+
alternatives = s.alternatives
51+
# self.state["result"] = None
52+
# self.state["alternatives"] = []
53+
if result:
54+
self.state["result"] = result
55+
self.state["alternatives"] = []
56+
interface.push_action(SelectionAction(result))
57+
self.history.append(("selection",view_information["change_count"],view_information["selection"],result))
58+
interface.push_action(ClearHighlightAction("alternatives"))
59+
if alternatives:
60+
self.state["alternatives"] = alternatives
61+
interface.push_action(DisplayRegionsAction("alternatives",alternatives,"Alternatives:\n"))
62+
interface.push_action(HighlightCleverAction(alternatives,"alternatives",result))
63+
elif isinstance(s,InsertionQuery):
64+
output = s.writing_locations_text
65+
selections = s.optional_selection
66+
if output:
67+
for location, text in output:
68+
interface.push_action(ReplaceAction(location,text))
69+
self.history.append(("insert"))
70+
if selections:
71+
interface.push_action(SelectionAction(selections))
72+
73+
elif isinstance(s,CollectionQuery):
74+
result = s.result
75+
items = s.items
76+
writing_positions = s.writing_positions
77+
selections = s.optional_selection
78+
if result:
79+
for location in writing_positions:
80+
interface.push_action(ReplaceAction(location,result))
81+
if items:
82+
interface.push_action(DisplayNiceAction(items,True))
83+
self.state["collection"] = items
84+
if selections:
85+
interface.push_action(SelectionAction(selections))
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
def respond_to_event(interface,event_description):
103+
pass
104+
105+
106+

application/build_cache.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class BuildCache():
2+
"""docstring for BuildCache"""
3+
def __init__(self):
4+
self.cache_memory = {}
5+
def register_build(self,vid,change_count,build):
6+
self.cache_memory[vid] = (change_count,build)
7+
8+
def get_build(self,vid,change_count):
9+
if vid not in self.cache_memory:
10+
return None
11+
data = self.cache_memory[vid]
12+
if change_count!= data[0]:
13+
return None
14+
return data[1]
15+
16+

bundles/Caster/python_voice_coding_plugin_caster.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ def noob_send(command,format,**kwargs):
3333
data = create_arguments(command,format,**kwargs)
3434
send_sublime("noob_voice_coding", data)
3535

36-
def lazy_value(c,f):
37-
return R(Function(noob_send, command = c, format = f))
36+
def lazy_value(c,f,**kwargs):
37+
return R(Function(noob_send, command = c, format = f,**kwargs))
3838

3939

4040
class NoobRule(MergeRule):
41-
pronunciation = "noob"
41+
pronunciation = "python voice coding plugin"
4242
mapping = {
4343
# alternative rule
4444
"[smart] alternative <alternative_index>":
@@ -75,15 +75,19 @@ class NoobRule(MergeRule):
7575

7676
# insert rule
7777
"(smart insert|insert item) <item_index>":
78-
lazy_value("insert",1),
78+
lazy_value("insert_item",1),
7979

8080
# collect rule
81-
"[smart] collect <index_collectable>":
81+
"[smart] collect <collectable>":
8282
lazy_value("collect_indexable",1),
8383
"[smart] variable <collect_index>":
8484
lazy_value("collect_variable",2),
8585
"[smart] parameter <collect_index>":
8686
lazy_value("collect_parameter",2),
87+
"[smart] module <collect_index>":
88+
lazy_value("collect_module",2),
89+
"[smart] imported (value|object) <collect_index>":
90+
lazy_value("collect_imported_value",2),
8791

8892

8993

@@ -128,7 +132,7 @@ class NoobRule(MergeRule):
128132
}
129133
),
130134
Choice("color",{
131-
"(red|gray)":1,
135+
"red":1,
132136
"blue":2,
133137
"green":3,
134138
"yellow":4,
@@ -156,8 +160,8 @@ class NoobRule(MergeRule):
156160
"(assignment left| left)" : "assignment left",
157161
"assignment full" : "assignment full",
158162
"import statement":"import statement",
159-
"(import|imported) (value|item|object|element)":"import value",
160-
"module" : "module",
163+
#"(import|imported) (value|item|object|element)":"import value",
164+
#"module" : "module",
161165
"(expression statement|expression)" : "expression statement",
162166
"iterator" : "iterator",
163167
"iterable" : "iterable",
@@ -168,9 +172,12 @@ class NoobRule(MergeRule):
168172
"(function|functions)" :"function",
169173
}
170174
),
171-
Choice("index_collectable",{
175+
Choice("collectable",{
172176
"(variable|variables)":"variable",
173177
"( parameter | parameters)":"parameter",
178+
"(module|modules)":"module",
179+
"(import|imported) (value|item|object|element)":"import value",
180+
"function ( name |names)":"function name",
174181
}
175182
),
176183

0 commit comments

Comments
 (0)