def AddButtonsToPythonistaKeyboard(pad=None):
	if not pad:
		pad = [
		{'key':'next word','width':2},
		{'key':'find','icon':'iob:ios7_search_32'},
		{'key':'nul'},
		{'key':'>'},
#		{'key':'new row'},
		{'key':'nul'},
		{'key':'nul'},
		{'key':'#'},
		{'key':'nul'},
		{'key':'"'},
		{'key':'nul'},
		{'key':'left','icon':'iob:arrow_left_a_32'},
		{'key':'right','icon':'iob:arrow_right_a_32'},
		{'key':'down','icon':'iob:arrow_down_a_32'},
		{'key':'\\'},
		{'key':'nul'},
		{'key':'delete','title':'Del'}]
		
	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.find = ''
def AddButtonsToPythonistaKeyboard(pad=None):
	if not pad:
		pad = [
		{'key':'next word','width':2},
		{'key':'nul'},
		{'key':'nul'},
		{'key':'>'},
#		{'key':'new row'},
		{'key':'nul'},
		{'key':'nul'},
		{'key':'#'},
		{'key':'nul'},
		{'key':'"'},
		{'key':'nul'},
		{'key':'left','icon':'iob:arrow_left_a_32'},
		{'key':'right','icon':'iob:arrow_right_a_32'},
		{'key':'nul'},
		{'key':'\\'},
		{'key':'nul'},
		{'key':'delete','title':'right delete','width':2}]
		
	ev = editor._get_editor_tab().editorView()
	tv = ev.textView()
	#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
Ejemplo n.º 3
0
def select(idx):
    import editor
    tvc = editor._get_editor_tab().parentViewController()
    tbv = tvc.tabBarView()
    tvs = tbv.tabViews()
    if idx < len(tvs):
        tvc.tabBarView().tabSelected_(tvs[idx])
        tvc.switchToTabViewController_(tvc.tabViewControllers()[idx])
Ejemplo n.º 4
0
def prevTab():
    import editor
    tvc = editor._get_editor_tab().parentViewController()
    tbv = tvc.tabBarView()
    tvs = tbv.tabViews()
    current = tbv.selectedTabIndex()
    next = (current - 1) % len(tvs)
    tbv.tabSelected_(tvs[next])
    tvc.switchToTabViewController_(tvc.tabViewControllers()[next])
Ejemplo n.º 5
0
def main():
    global drive, edit_tab, EditedGoogleFile, local_filename

    google_drive_auth_path = os.path.expanduser(
        '~/Documents/MesTools/settings.yaml')
    gauth = GoogleAuth(google_drive_auth_path)
    drive = GoogleDrive(gauth)
    # Create local webserver and auto handles authentication.
    if not hasattr(webbrowser, '_open'):
        webbrowser._open = webbrowser.open

    def wbopen(url, *args, **kwargs):
        return webbrowser._open(url)

    webbrowser.open = wbopen

    GoogleFile = {}
    GoogleFile['title'] = 'drive'
    GoogleFile['id'] = 'root'
    GoogleFile['mimeType'] = 'application/vnd.google-apps.folder'

    root_node = FileTreeNode(GoogleFile)

    picker = TreeDialogController(root_node)
    picker.view.present('sheet')
    picker.view.wait_modal()
    if picker.selected_entries:
        e = picker.selected_entries[0]
        EditedGoogleFile = e.GoogleFile
        filename = EditedGoogleFile['title']

        # create local file for editing
        path = sys.argv[0]
        i = path.rfind('/')
        path = path[:i + 1]
        i = filename.rfind('.')
        ext = filename[i + 1:]
        local_filename = path + filename[:i] + ' [on GoogleDrive].' + ext
        # get Google Drive file as a local file
        EditedGoogleFile.GetContentFile(local_filename)

        time.sleep(0.2)

        # edit local file in same tab, so keyboard is still active
        editor.open_file(local_filename, new_tab=False)

        # add a save key to Pythonista keyboard
        edit_tab = editor._get_editor_tab()

        th = my_thread()
        th.start()
Ejemplo n.º 6
0
Archivo: vdb.py Proyecto: jsbain/vdb
    def show_menu(self):
        '''attach debuggermenu to current editorview, killing
		existing view if it exists.  TODO: reuse existing object.
		'''
        DEBUGMENUTAG = hash('DEBUGMENU')
        ed = editor._get_editor_tab().editorView()
        debugmenuobj = ed.viewWithTag_(DEBUGMENUTAG)
        try:
            if debugmenuobj:
                debugmenuobj.removeFromSuperview()
                ObjCInstance(self.debugmenu).removeFromSuperview()
        except AttributeError:
            pass
        ed.addSubview_(self.debugmenu)
Ejemplo n.º 7
0
Archivo: vdb.py Proyecto: jsbain/vdb
	def show_menu(self):
		'''attach debuggermenu to current editorview, killing
		existing view if it exists.  TODO: reuse existing object.
		'''
		DEBUGMENUTAG = hash('DEBUGMENU')
		ed = editor._get_editor_tab().editorView()
		debugmenuobj = ed.viewWithTag_(DEBUGMENUTAG)
		try:
			if debugmenuobj:
				debugmenuobj.removeFromSuperview()
				ObjCInstance(self.debugmenu).removeFromSuperview()
		except AttributeError:
			pass
		ed.addSubview_(self.debugmenu)
Ejemplo n.º 8
0
def create_menu(debugger):
	'''create a menu, and bind to debugger.
	'''
	button_items = []
	for name, imagename in btn_dict.items():
		b = ui.Button(name=name, image=ui.Image.named(imagename))

		action = getattr(debugger, name+'_action', None)
		if callable(action):
			b.action = action
		else:
			b.enabled = False
		button_items.append(b)
	ed = editor._get_editor_tab().editorView()
	w,h = ed.frame().size.width, ed.frame().size.height
	debugmenu = ui.View(frame = (w-44, 0, 44, h),flex='LH')
	y = 10
	for b in button_items:
		b.y = y
		debugmenu.add_subview(b)
		y += b.height + 20
	ObjCInstance(debugmenu).tag = DEBUGMENUTAG
	editor.apply_ui_theme(debugmenu)
	return debugmenu
Ejemplo n.º 9
0
    method_setImplementation = c.method_setImplementation
    method_setImplementation.restype = None
    method_setImplementation.argtypes = [c_void_p, c_void_p]
    if didAdd:
        orig_method = c.class_getInstanceMethod(cls.ptr, sel(selector))
        new_method = c.class_getInstanceMethod(cls.ptr, sel(new_sel))
        method_exchangeImplementations(orig_method, new_method)
    else:
        # setimp,
        orig_method = c.class_getInstanceMethod(cls.ptr, sel(selector))
        method_setImplementation(orig_method, imp)


if __name__ == '__main__':
    import console
    t = editor._get_editor_tab()

    def saveData(_self, _sel):
        '''swizzle savedata. called whenever tab is switched, etc. seems to be called whether or not there are changes, so be sure to check if hasChanges before doing anything.  In this case, I always call _original_saveData after, but it would be possible to prevent saves, etc.'''
        try:
            obj = ObjCInstance(_self)
            if obj.hasChanges():
                console.hud_alert('saving ' +
                                  str(obj.filePath()).split('/')[-1])
        finally:
            obj = ObjCInstance(_self)
            original_method = getattr(
                obj, _bytes_to_str(b'original' + c.sel_getName(_sel)), None)
            if original_method:
                original_method()
Ejemplo n.º 10
0
	method_setImplementation=c.method_setImplementation
	method_setImplementation.restype=None
	method_setImplementation.argtypes=[c_void_p, c_void_p]
	if didAdd:
			orig_method=c.class_getInstanceMethod(cls.ptr, sel(selector))
			new_method=c.class_getInstanceMethod(cls.ptr, sel(new_sel))
			method_exchangeImplementations(orig_method, new_method)
	else:
		# setimp, 
		orig_method=c.class_getInstanceMethod(cls.ptr, sel(selector))
		method_setImplementation(orig_method,imp)


if __name__=='__main__':
	import console
	t=editor._get_editor_tab()

	def saveData(_self,_sel):
		'''swizzle savedata. called whenever tab is switched, etc. seems to be called whether or not there are changes, so be sure to check if hasChanges before doing anything.  In this case, I always call _original_saveData after, but it would be possible to prevent saves, etc.'''
		try:
			obj=ObjCInstance(_self)
			if obj.hasChanges():
				console.hud_alert('saving '+str(obj.filePath()).split('/')[-1])
		finally:
			obj=ObjCInstance(_self)
			original_method=getattr(obj,'original'+c.sel_getName(_sel),None)
			if original_method:
				original_method()
			
	cls=ObjCInstance(c.object_getClass(t.ptr))
	swizzle(cls,'saveData',saveData)
Ejemplo n.º 11
0
# https://forum.omz-software.com/topic/3692/auto-fill-correct-blowing-up-editor-app/6

import editor
editor._get_editor_tab().editorView().completionProvider = None

# disable jedi

editor._get_editor_tab().editorView().completionProvider(
).fallbackCompletionProvider = None
Ejemplo n.º 12
0
def close_current_tab():
    import editor
    tab = editor._get_editor_tab()
    close_tab(tab)
Ejemplo n.º 13
0
# https://forum.omz-software.com/topic/3419/share-code-custom-editor-font

# You can download the example font from http://cdn.kollmer.me/embed/SFMono-Regular.otf

# Add the script (https://gist.github.com/lukaskollmer/0c01b7a27e512db480847fac2cc54103) to your site-packages Folder and add the following lines to your pythonista-startup.py file

import custom_editor_font
import editor
import console

# point this to your font file
font_path = "file://" + os.path.expanduser("~/Documents/Fonts/SFMono/SFMono-Regular.otf")

custom_editor_font.load_custom_font(font_path)

font_name = "SFMono-Regular"
font_size = 15

custom_editor_font.set_editor_font(font_name, font_size)
console.set_font(font_name, font_size)
editor._get_editor_tab().reloadFile()

Ejemplo n.º 14
0
def launch_with_py2(path, args):
    '''launch a script at path, using args.  This essentially is what happens when you press the run button and choose py2.  Note, this means globals are cleared.... blechhh'''
    E = editor._get_editor_tab()
    E.runScriptAtPath_withInterpreterVersion_arguments_(path, 2, args)