Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello โ I'm @olemoritz on Twitter.
Disable word completion suggestion/pop-up feature
-
Can you add a feature to disable word completion suggestion/pop-up?
-
Create a little script with
import editor editor._get_editor_tab().editorView().completionProvider=None
And put it in tools to act on edited script tab
-
Thanks @cvp . But where can I find โtoolsโ?
-
@alice.106667 wrench icon above right
-
Damn @cvp is there anything you donโt know. Lol
-
@madivad More than a lot but, as retired, I have plenty of time to play with this marvelous app
-
Is it possible to apply this completionProvider to other types of files so that snippet can work for not just .py files,thanks.
https://forum.omz-software.com/topic/7103/snippets-for-non-py-file
-
@mieq tools are also active (see wrench button) for non .py files but I don't know if it would have the effect you want.
-
@cvp just want the auto completion show up even in non .py files.because the snippets will show up in the code completion suggestion.
-
@mieq I understand your request but sincerely, no idea.
-
@cvp haha,never mind.
-
@mieq you could always foresee your js snippets in the snippets settings and edit your js file renamed as a .py, and rename it into .js at the end.
-
@mieq I just spent more than one hour to try to find a way in objectiveC by analyzing some methods of the tab editor view but without any success.
-
@cvp Never Mind,I will try the rename method.Thanks a lot.
-
@mieq Just to prove that I have made progress, although quite useless since without success.
Try thisfrom objc_util import * @on_main_thread def main(): win = UIApplication.sharedApplication().keyWindow() root_vc = win.rootViewController() tabs_vc = root_vc.detailViewController() tab = tabs_vc.selectedTabViewController() for snippet in tab.editorView().completionProvider().snippets(): print(snippet) if __name__ == '__main__': main()
-
@mieq could I have some of your js snippets? And about how much snippets do you want to use?
-
@cvp In fact, I just discovered Pythonista's snippets and thought it would be great if it worked on all files. (But even apart from that, Pythonista is a very good text editor.) So I didn't actually create any snippets.
-
@mieq Haha ๐
Anyway, could you try this script as wrench/tool and tap it when you are editing an html or JavaScript file.
It will provide you a keyboard with additional keys, instead of snippets, to generate some lines.
Try each additional keys, given as example.import editor from objc_util import * import ui def key_pressed(sender): import ui from objc_util import ObjCClass tv = sender.objc_instance.firstResponder() # associated TextView tv.insertText_(sender.data) return class MyView(ui.View): def __init__(self, pad, *args, **kwargs): #super().__init__(self, *args, **kwargs) self.width = ui.get_screen_size()[0] # width of keyboard = screen self.background_color = 'lightgray'#(0,1,0,0.2) self.h_button = 32 self.pad = pad # build buttons for pad_elem in self.pad: if pad_elem['key'] in ('nul', 'new row'): # free space or new row continue button = ui.Button() # Button for user functionnality button.name = pad_elem['key'] button.background_color = 'white' # or any other color button.tint_color = 'black' button.corner_radius = 5 button.font = ('<system>',self.h_button - 8) button.title = pad_elem['key'] if 'icon' in pad_elem: button.image = ui.Image.named(pad_elem['icon']).with_rendering_mode(ui.RENDERING_MODE_ORIGINAL) if 'data' in pad_elem: button.data = pad_elem['data'] else: button.data = button.title if '\n' in button.title: ObjCInstance(button).button().titleLabel().setLineBreakMode(0) # NSLineBreakByWordWrapping) button.action = key_pressed retain_global(button) # see https://forum.omz-software.com/topic/4653/button-action-not-called-when-view-is-added-to-native-view self.add_subview(button) self.layout() def layout(self): import ui #print('layout') # supports changing orientation #print(ui.get_screen_size()) dx = 8 dy = 2 x0 = 15 y0 = 10 dx_middle = 25 y = y0 x = x0 w_button = (ui.get_screen_size()[0] - 2*x0 - 17*dx - dx_middle)/18 for pad_elem in self.pad: nw = pad_elem.get('width', 1) wb = w_button*nw + dx*(nw-1) if (x + wb + dx) > self.width: y = y + self.h_button + dy x = x0 if pad_elem['key'] == 'nul': # let free space x = x + wb + dx continue elif pad_elem['key'] == 'new row': # new row y = y + self.h_button + dy x = x0 continue button = self[pad_elem['key']] xb = x + dx_middle if (x+wb) > self.width/2 else x button.frame = (xb,y,wb,self.h_button) if button.title != '': font_size = self.h_button - 8 while True: d = ui.measure_string(button.title,font=(button.font[0],font_size))[0]+4 if d <= wb: break font_size = font_size - 1 button.font = (button.font[0],font_size) x = x + wb + dx self.height = y + self.h_button + dy @on_main_thread def AddButtonsToPythonistaKeyboard(pad=None): if not pad: pad = [ {'key':'<html>\n\n</html>','width':1}, {'key':'<head>\n\n</head>','width':1}, {'key':'<style>\n\n</style>','width':1}, {'key':'<body>\n\n</body>','width':1}, {'key':'<script>\n\n</script>','data':'<script>...</script>','width':1}, {'key':'nul'}, {'key':'for','data':'for () { \n}'}, {'key':'if','data':'if () {\n\n} else {\n\n}'}, # {'key':'new row'}, # {'key':'nul'}, # {'key':'nul'}, # {'key':'nul'} ] ev = editor._get_editor_tab().editorView() tv = ev.textView() #print(tv._get_objc_classname()) #print(dir(tv)) # create ui.View for InputAccessoryView above keyboard v = MyView(pad) # view above keyboard vo = ObjCInstance(v) # get ObjectiveC object of v retain_global(v) # see https://forum.omz-software.com/topic/4653/button-action-not-called-when-view-is-added-to-native-view tv.setInputAccessoryView_(vo) # attach accessory to textview tv.strfind = '' if __name__ == '__main__': AddButtonsToPythonistaKeyboard()
-
@cvp This is awesome,๐ Thank you so much!
-
@mieq of course, my script is not very professional and you have to know you can add your own keys, even on several rows.
Keys have their face with the text of 'key' (or an icon) and generates the text of 'data' if present, else of 'key'.