コード例 #1
0
ファイル: ssh.py プロジェクト: jsbain/stash
    def edit_file(self, remote_file):
        import tempfile
        import runpy
        import editor

        try:
            temp = tempfile.NamedTemporaryFile(
                dir=os.path.expanduser('~/Documents'), suffix='.py')
            cur_path = editor.get_path()
            sftp = self.ssh.open_sftp()
            path = self.get_remote_path()
            res = sftp.getfo(path + remote_file, temp)
            #editor.open_file(temp.name)
            temp.seek(0)
            print '***When you are finished editing the file, you must come back to console to confirm changes***'
            editor.open_file(temp.name)
            time.sleep(1.5)
            console.hide_output()
            input = raw_input('Save Changes? Y,N: ')
            editor.open_file(cur_path)
            if input == 'y' or input == 'Y':
                with open(temp.name, 'r') as f:
                    sftp.putfo(f, path + remote_file)
                    print 'File transfered.'
        except Exception, e:
            print e
コード例 #2
0
	def create_new_file_b(self):
		content = """from scene import *
import os, sys

sys.path += [os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib')]

class MyScene (Scene):
	def setup(self):
		# This will be called before the first frame is drawn.
		pass
	
	def draw(self):
		# This will be called for every frame (typically 60 times per second).
		background(0, 0, 0)
		# Draw a red circle for every finger that touches the screen:
		fill(1, 0, 0)
		for touch in self.touches.values():
			ellipse(touch.location.x - 50, touch.location.y - 50, 100, 100)
	
	def touch_began(self, touch):
		pass
	
	def touch_moved(self, touch):
		pass

	def touch_ended(self, touch):
		pass

run(MyScene())
"""
		if len(self.txtbf.txtbf.text) > 0:
			f = open(self.txtbf.txtbf.text, 'w')
			f.write(content)
			f.close()
			editor.open_file(self.txtbf.txtbf.text)
コード例 #3
0
ファイル: Tabs.py プロジェクト: c0ns0le/Pythonista
    def open_url(self,sender):
        sv=self.sv
        d=self.d
        current_path = editor.get_path()
        button_title = sender.title
    
        #unselect current tab
        current_tab = self.get_current_tab(current_path)
        if current_tab:
            sv[current_tab['name']].background_color = 'white'
            d[current_tab['name']]['selection']=editor.get_selection()
        
        if not d.has_key(button_title):
            console.hud_alert('missing tab entry for this tab.. ')
        
        new_tab=d[button_title]
        path=new_tab['path']
        if not os.path.isfile(path):
            console.hud_alert('The file for this tab has been moved, renamed, or deleted. the tab will now be removed.', icon = 'error', duration = 3)
            self.close_button(sender)

        else:
            editor.open_file(path)
            def setsel():
                sel=new_tab['selection']

                while editor.get_selection()[0] < sel[0]:
                    import time
                    editor.replace_text(sel[0],sel[0],'')
                    editor.replace_text(sel[0]+400,sel[0]+400,'')
                    time.sleep(0.25)
                editor.set_selection(*sel)
            ui.delay(setsel,1.0)
            sender.background_color = 'orange'
コード例 #4
0
ファイル: ssh.py プロジェクト: briarfox/stash
 def edit_file(self,remote_file):
     import tempfile
     import runpy
     import editor
 
     try:
         temp = tempfile.NamedTemporaryFile(dir=os.path.expanduser('~/Documents') , suffix='.py')
         cur_path = editor.get_path()
         sftp = self.ssh.open_sftp()
         path = self.get_remote_path()
         res = sftp.getfo(path+remote_file,temp)
         #editor.open_file(temp.name)
         temp.seek(0)
         print '***When you are finished editing the file, you must come back to console to confim changes***'
         editor.open_file(temp.name)
         time.sleep(1.5)
         console.hide_output()
         input = raw_input('Save Changes? Y,N: ')
         editor.open_file(cur_path)
         if input == 'y' or input =='Y':
             with open(temp.name,'r') as f:
                 sftp.putfo(f,path+remote_file)
                 print 'File transfered.'
     except exception, e:
         print e
コード例 #5
0
ファイル: ssh.py プロジェクト: wizardofozzie/stash
    def edit_file(self, remote_file):
        import tempfile
        import runpy
        import editor

        try:
            temp = tempfile.NamedTemporaryFile(dir=os.path.expanduser("~/Documents"), suffix=".py")
            cur_path = editor.get_path()
            sftp = self.ssh.open_sftp()
            path = self.get_remote_path()
            res = sftp.getfo(path + remote_file, temp)
            # editor.open_file(temp.name)
            temp.seek(0)
            print "***When you are finished editing the file, you must come back to console to confirm changes***"
            editor.open_file(temp.name)
            time.sleep(1.5)
            console.hide_output()
            input = raw_input("Save Changes? Y,N: ")
            editor.open_file(cur_path)
            if input == "y" or input == "Y":
                with open(temp.name, "r") as f:
                    sftp.putfo(f, path + remote_file)
                    print "File transfered."
        except Exception, e:
            print e
コード例 #6
0
def makefile(filename, content):
    #replacing with direct file write.
    #editor.make_new_file(filename, content)
    f = open(filename, 'w')
    f.write(content)
    f.close()
    editor.open_file(filename)
コード例 #7
0
def new_md(sender):
    filename = console.input_alert('', 'File Name')
    if filename.find('.') > -1:
        filename = filename[:filename.rfind('.')]
    filename += '.md'
    fh = open(filename, 'a')
    del fh
    editor.open_file(filename)
コード例 #8
0
ファイル: Markdown Editor.py プロジェクト: c0ns0le/Pythonista
def new_md(sender):
    filename = console.input_alert('', 'File Name')
    if filename.find('.')>-1:
        filename = filename[:filename.rfind('.')]
    filename += '.md'
    fh = open(filename, 'a')
    del fh
    editor.open_file(filename)
コード例 #9
0
def open_editor(file='', new_tab=True):
    if os.path.isfile(os.getcwd() + '/' + file):
        editor.open_file(os.getcwd() + '/' + file, new_tab)
        console.hide_output()
    else:
        editor.make_new_file(
            file if file else
            'untitled.py')  # new_tab not supported by make_new_file
コード例 #10
0
def makefile(filename,content):
	#replacing with direct file write.
	#editor.make_new_file(filename, content)
	f = open(filename, 'w')
	f.write(content)
	f.close()
	if os.path.splitext(filename)[1] in ['.py','.txt']:
		editor.open_file(filename)
コード例 #11
0
ファイル: pythonista.py プロジェクト: dgelessus/whateversh
def main(args):
    p = argparse.ArgumentParser(description=__doc__)
    p.add_argument("file", action="store", help="file to open")
    ns = p.parse_args(args)
    
    editor.open_file(ns.file)
    console.hide_output()
    
    sys.exit(0)
コード例 #12
0
def edit_config(config_file=DEFAULT_CONFIG):
    # pylint: disable=import-error
    config_file_path = path.abspath(path.expanduser(config_file))
    if path.exists(config_file_path):
        print 'Opening: {}'.format(config_file_path)
        import editor
        editor.open_file(config_file_path)
    else:
        print 'Config file does not exist: {}'.format(config_file_path)
コード例 #13
0
ファイル: PhoneManager.py プロジェクト: cclauss/Pythonista-4
 def btn_Edit(self, sender):
     sel_rows = len(self.view['tableview1'].selected_rows)
     if sel_rows == 1:
       row = self.view['tableview1'].selected_row[1]
       filename = self.view['tableview1'].data_source.items[row]['title']
       editor.open_file(self.path + '/' + filename)
       self.view.close()
     else:
       self.btn_Help(None,message='Please select one file.',name='Error')
コード例 #14
0
def edit_config(config_file=DEFAULT_CONFIG):
    # pylint: disable=import-error
    config_file_path = path.abspath(path.expanduser(config_file))
    if path.exists(config_file_path):
        print 'Opening: {}'.format(config_file_path)
        import editor
        editor.open_file(config_file_path)
    else:
        print 'Config file does not exist: {}'.format(config_file_path)
コード例 #15
0
ファイル: update_script.py プロジェクト: cclauss/Pythonista-4
def main():
    print(sys.argv)
    if len(sys.argv) <= 1:
        print("No changes detected.")
        quit()

    editor.open_file(sys.argv[1])
    text_length = len(editor.get_text())
    editor.replace_text(0, text_length, sys.argv[2])
コード例 #16
0
ファイル: gitui.py プロジェクト: c0ns0le/Pythonista
 def checkout(self,sender):
     repo =self._get_repo()
     cwd=os.path.abspath('.')
     os.chdir(r._get_repo().path)
     #repo.clean_working()
     repo.switch_branch(self.view['branch'].text)
     self.refresh()
     os.chdir(cwd)
     editor.open_file(editor.get_path())
     console.hud_alert('checked out')
コード例 #17
0
ファイル: gitui.py プロジェクト: sebab/pythonista-scripts
 def checkout(self, sender):
     repo = self._get_repo()
     cwd = os.path.abspath('.')
     os.chdir(r._get_repo().path)
     #repo.clean_working()
     repo.switch_branch(self.view['branch'].text)
     self.refresh()
     os.chdir(cwd)
     editor.open_file(editor.get_path())
     console.hud_alert('checked out')
コード例 #18
0
ファイル: git.py プロジェクト: RichardPotthoff/stash
def refresh_editor():
    #reload current file in editor
    # TODO: only reload if the file was recently updated...
    try:
        sel=editor.get_selection()
        editor.open_file(editor.get_path())
        import time
        time.sleep(0.5) #let the file load
        editor.replace_text(sel[0],sel[0],'') #force scroll
        editor.set_selection(sel[0],sel[1])
    except:
        print 'Could not refresh editor.  continuing anyway'
コード例 #19
0
	def create_new_file_e(self):
		if len(self.txtbf.txtbf.text) > 0:
			path = self.fs.getcwd() + '/' + self.txtbf.txtbf.text
			f = open(path, 'w')
			f.write("""import os, sys

sys.path += [os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib')]

""")
			f.close()
			editor.open_file(os.path.relpath(path))
			sys.exit()
コード例 #20
0
 def urlscheme_overwrite_file_with_wc_copy(self, path, b64_contents):
     text = base64.b64decode(b64_contents)
     full_file_path = os.path.join(os.path.expanduser('~/Documents'), path)
     try:
         os.makedirs(full_file_path)
     except OSError as e:
         if e.errno != errno.EEXIST:
             raise e
     with open(full_file_path, 'w') as f:
         f.write(text)
     editor.open_file(path)
     console.hud_alert(path + ' Updated')
コード例 #21
0
	def urlscheme_overwrite_file_with_wc_copy(self, path, b64_contents):
		text = base64.b64decode(b64_contents)
		full_file_path = os.path.join(os.path.expanduser('~/Documents'), path)
		try:
			os.makedirs(full_file_path)
		except OSError as e:
			if e.errno != errno.EEXIST:
				raise e
		with open(full_file_path, 'w') as f:
			f.write(text)
		editor.open_file(path)
		console.hud_alert(path +' Updated')
コード例 #22
0
ファイル: git.py プロジェクト: zx110101/00
def refresh_editor():
    #reload current file in editor
    # TODO: only reload if the file was recently updated...
    try:
        sel = editor.get_selection()
        editor.open_file(editor.get_path())
        import time
        time.sleep(0.5)  #let the file load
        editor.replace_text(sel[0], sel[0], '')  #force scroll
        editor.set_selection(sel[0], sel[1])
    except:
        print('Could not refresh editor.  continuing anyway')
コード例 #23
0
ファイル: Working_Copy_Sync.py プロジェクト: ahenry91/wc_sync
	def urlscheme_overwrite_file_with_wc_copy(self, path, b64_contents):
		text = base64.b64decode(b64_contents)
		full_file_path = os.path.join(DOCS_DIR, path)
		try:
			os.makedirs(full_file_path)
		except OSError as e:
			if e.errno != errno.EEXIST:
				raise e
		with open(full_file_path, 'wb') as f:
			f.write(text)
		editor.open_file(path)
		_, filename = os.path.split(path)
		console.hud_alert(filename + ' Updated')
コード例 #24
0
 def urlscheme_overwrite_file_with_wc_copy(self, path, b64_contents):
     text = base64.b64decode(b64_contents)
     full_file_path = os.path.join(DOCS_DIR, path)
     try:
         os.makedirs(full_file_path)
     except OSError as e:
         if e.errno != errno.EEXIST:
             raise e
     with open(full_file_path, 'w') as f:
         f.write(text)
     editor.open_file(path)
     _, filename = os.path.split(path)
     console.hud_alert(filename + ' Updated')
コード例 #25
0
ファイル: loader.py プロジェクト: seletskiy/ashium
def load_from_url(url, file_name=None):
    active_review = review.Review(url)
    if file_name is not None:
        entry = active_review._add_loaded_file(file_name)

        shutil.copy(editor.get_current_file_path(), entry.get_file_path())

    active_review.load()

    if file_name is not None:
        editor.open_file(entry.get_file_path())

    return active_review
コード例 #26
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()
コード例 #27
0
def main():
    resp = console.alert('Alert!', 'Choose File Extension', '.py', '.pyui', 'other', hide_cancel_button=False)
    if resp==1:
        ext = '.py'
    elif resp==2:
        ext = '.pyui'
    elif resp==3:
        ext = console.input_alert('Specify file extension')
    text = clipboard.get()
    assert text, 'No text on the clipboard!'
    filename = sys.argv[1]
    console.clear()
    filename = save(filename, text, ext)
    editor.open_file(filename)
コード例 #28
0
ファイル: open_in.py プロジェクト: c0ns0le/Pythonista
def main():
    resp = console.alert('Alert!', 'Choose File Extension', '.py', '.pyui', 'other', hide_cancel_button=False)
    if resp==1:
        ext = '.py'
    elif resp==2:
        ext = '.pyui'
    elif resp==3:
        ext = console.input_alert('Specify file extension')
    text = clipboard.get()
    assert text, 'No text on the clipboard!'
    filename = sys.argv[1]
    console.clear()
    filename = save(filename, text, ext)
    editor.open_file(filename)
コード例 #29
0
	def copy_file(self, path, b64_contents):
		text = base64.b64decode(b64_contents)
		full_file_path = os.path.join(self.paths.docs, path)
		try:
			os.makedirs(full_file_path)
		except OSError as e:
			if e.errno != errno.EEXIST:
				raise e
				
		with open(full_file_path, 'wb') as f:
			f.write(text)
			
		editor.open_file(path)
		_, filename = os.path.split(path)
		console.hud_alert(filename + ' Updated')
コード例 #30
0
ファイル: editor_plugin.py プロジェクト: yoyoy0/ShellistaExt
def main(self, line):
    print line
    args = bash(line)

    if len(args) == 1:
        if HAS_EDITOR:
            editor.open_file(args[0])
        else:
            import platform
            if platform.system() == 'Linux':
                os.system('vi {0}'.format(args[0]))
            else:
                print 'Unsupported platform'
    else:
        print 'Usage: editor <filename>'
コード例 #31
0
ファイル: GUI_Helper.py プロジェクト: kitwilde/Pythonista-1
def main(pyui_path, extra_func_mode=False, remove_title_bar=False, remove_status_bar=False):
	
	
	if not pyui_path:
		exit()
	if os.path.exists(pyui_path):
		a = GUI_Helper(pyui_path, extra_func_mode, remove_title_bar, remove_status_bar)
		to_path = os.path.dirname(pyui_path)+'/'+os.path.basename(pyui_path).replace('.pyui','')+'_GUI_Helper.py'
		#print a.text
		with open(to_path,'w') as f:
			f.write(a.text)
		editor.open_file(to_path, True)
		console.hide_output()
	else:
		console.hud_alert('pyui not found')
コード例 #32
0
def main(self, line):
    args = bash(line)
    
    if len(args) == 1:
        if HAS_EDITOR:
            print 'Opening {0} in Pythonista editor.'.format(args[0])
            editor.open_file(os.path.join(os.getcwd(), args[0]))
            console.hide_output()
        else:
            import platform
            if platform.system() == 'Linux':
                os.system('vi {0}'.format(args[0]))
            else:
                print 'Unsupported platform'
    else:
        print 'Usage: editor <filename>'
コード例 #33
0
	def create_new_file_l(self):
		content = """from scene import *
from random import random
import os, sys

sys.path += [os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib')]

class MyScene (Scene):
	def setup(self):
		# This will be called before the first frame is drawn.
		# Set up the root layer and one other layer:
		self.root_layer = Layer(self.bounds)
		center = self.bounds.center()
		self.layer = Layer(Rect(center.x - 64, center.y - 64, 128, 128))
		self.layer.background = Color(1, 0, 0)
		self.layer.image = 'Snake'
		self.root_layer.add_layer(self.layer)
	
	def draw(self):
		# Update and draw our root layer. For a layer-based scene, this
		# is usually all you have to do in the draw method.
		background(0, 0, 0)
		self.root_layer.update(self.dt)
		self.root_layer.draw()
	
	def touch_began(self, touch):
		# Animate the layer to the location of the touch:
		x, y = touch.location.x, touch.location.y
		new_frame = Rect(x - 64, y - 64, 128, 128)
		self.layer.animate('frame', new_frame, 1.0, curve=curve_bounce_out)
		# Animate the background color to a random color:
		new_color = Color(random(), random(), random())
		self.layer.animate('background', new_color, 1.0)
	
	def touch_moved(self, touch):
		pass
	
	def touch_ended(self, touch):
		pass

run(MyScene())
"""
		if len(self.txtbf.txtbf.text) > 0:
			f = open(self.txtbf.txtbf.text, 'w')
			f.write(content)
			f.close()
			editor.open_file(self.txtbf.txtbf.text)
コード例 #34
0
ファイル: vdb.py プロジェクト: jsbain/vdb
	def setup_ui(self):
		self.curframe = self.stack[self.curindex][0]
		# The f_locals dictionary is updated from the actual frame
		# locals whenever the .f_locals accessor is called, so we
		# cache it here to ensure that modifications are not overwritten.
		editor.clear_annotations()
		self.curframe_locals = self.curframe.f_locals
		frame=self.curframe
		
		editor.open_file(frame.f_code.co_filename)
		editor.annotate_line(frame.f_lineno,
									filename = frame.f_code.co_filename,
									scroll = True)
		self.show_menu()
		self.debugmenu['down'].enabled=self.curindex<len(self.stack)-1
		self.debugmenu['up'].enabled=self.curindex>0
		console.hide_output()
コード例 #35
0
ファイル: vdb.py プロジェクト: jsbain/vdb
    def setup_ui(self):
        self.curframe = self.stack[self.curindex][0]
        # The f_locals dictionary is updated from the actual frame
        # locals whenever the .f_locals accessor is called, so we
        # cache it here to ensure that modifications are not overwritten.
        editor.clear_annotations()
        self.curframe_locals = self.curframe.f_locals
        frame = self.curframe

        editor.open_file(frame.f_code.co_filename)
        editor.annotate_line(frame.f_lineno,
                             filename=frame.f_code.co_filename,
                             scroll=True)
        self.show_menu()
        self.debugmenu['down'].enabled = self.curindex < len(self.stack) - 1
        self.debugmenu['up'].enabled = self.curindex > 0
        console.hide_output()
コード例 #36
0
ファイル: file_browser.py プロジェクト: c0ns0le/Pythonista
def show_tempfile(absolute_path):
	infile = open(absolute_path,'r')
	contents = infile.read()
	try:
		# make sure the encoding wont break Pythonista
		contents.decode('ascii')
	except:
		print 'Unknown encoding in file:\n\t',absolute_path
		sys.exit()
	infile.close()

	writefile = open('temp.py','w')
	writefile.write(contents)
	writefile.close()

	editor.open_file('temp.py')

	sys.exit()
コード例 #37
0
ファイル: file_browser.py プロジェクト: wuxi20/Pythonista
def show_tempfile(absolute_path):
    infile = open(absolute_path, 'r')
    contents = infile.read()
    try:
        # make sure the encoding wont break Pythonista
        contents.decode('ascii')
    except:
        print('Unknown encoding in file:\n\t', absolute_path)
        sys.exit()
    infile.close()

    writefile = open('temp.py', 'w')
    writefile.write(contents)
    writefile.close()

    editor.open_file('temp.py')

    sys.exit()
コード例 #38
0
ファイル: file_browser.py プロジェクト: wuxi20/Pythonista
    def openSelected(self):
        if self.scroller.sublayer.selected:
            filename = self.scroller.sublayer.selected.text
            absolute_path = os.path.join(self.fs.cwd, filename)
            relative_path = os.path.relpath(absolute_path)
            ext = os.path.splitext(filename)[1]

            if self.fs.isdir(absolute_path):
                self.opendir(filename)
            # cant open anything below the documents folder
            elif ext in ['.png', '.jpg']:
                console.show_image(absolute_path)
                sys.exit()
            elif relative_path[:2] != '..':
                if ext == '.py':
                    editor.open_file(relative_path)
                    sys.exit()
                else:
                    show_tempfile(absolute_path)
            else:
                show_tempfile(absolute_path)
コード例 #39
0
ファイル: file_browser.py プロジェクト: c0ns0le/Pythonista
	def openSelected(self):
		if self.scroller.sublayer.selected:
			filename = self.scroller.sublayer.selected.text
			absolute_path = os.path.join(self.fs.cwd,filename)
			relative_path = os.path.relpath(absolute_path)
			ext = os.path.splitext(filename)[1]

			if self.fs.isdir(absolute_path):
				self.opendir(filename)
			# cant open anything below the documents folder
			elif ext in ['.png','.jpg']:
				console.show_image(absolute_path)
				sys.exit()
			elif relative_path[:2] != '..':
				if ext == '.py':
					editor.open_file(relative_path)
					sys.exit()
				else:
					show_tempfile(absolute_path)
			else:
				show_tempfile(absolute_path)
コード例 #40
0
ファイル: edit.py プロジェクト: briarfox/shellista-ssh
def edit_file(file_to_edit):
    '''Open file in a temp text page to allow editing'''
    
    cur_path = editor.get_path()
    #with open('tmp.txt', 'w') as file:
    try:
        file = open(TEMP_DIR+'/tmp.txt','w')
        file.write(file_to_edit.read())
        file.close()
        editor.reload_files()
        raw_input('*When you are finished editing the file, you must come back to console to confim changes*\n[Press Enter]')
        editor.open_file(TEMP)
        console.hide_output()
        while True:
            input = raw_input('Save Changes? Y,N: ')
            if input=='Y' or input=='y':
                editor.open_file(cur_path)
                return open(TEMP_DIR+'/tmp.txt','r')
            elif input=='N' or input=='n':
                editor.open_file(cur_path)
                return False

        
    except Exception, e:
        print e
        return False
コード例 #41
0
def main():
    path = editor.get_path()

    if not path:
        tab.new_file()
        return

    folder = os.path.dirname(path)
    try:
        file_name = console.input_alert('Enter filename').strip()

        if not file_name:
            raise KeyboardInterrupt

        path = os.path.join(folder, file_name)
        if os.path.exists(path):
            editor.open_file(path, new_tab=True)
        else:
            editor.make_new_file(path, new_tab=True)

    except KeyboardInterrupt:
        pass
コード例 #42
0
ファイル: tab.py プロジェクト: teneen/blackmamba
def open_file(path, new_tab=True, line=None):
    index = None
    paths = get_paths()

    if paths:
        try:
            index = paths.index(path)
        except ValueError:
            pass

    if index is None:
        import editor
        editor.open_file(path, new_tab=new_tab)
    else:
        select_tab(index)

    if line is not None:

        def scroll():
            source.scroll_to_line(line)

        ui.delay(scroll, 0.2)
コード例 #43
0
ファイル: Tabs.py プロジェクト: sebab/pythonista-scripts
    def open_url(self, sender):
        sv = self.sv
        d = self.d
        current_path = editor.get_path()
        button_title = sender.title

        #unselect current tab
        current_tab = self.get_current_tab(current_path)
        if current_tab:
            sv[current_tab['name']].background_color = 'white'
            d[current_tab['name']]['selection'] = editor.get_selection()

        if not d.has_key(button_title):
            console.hud_alert('missing tab entry for this tab.. ')

        new_tab = d[button_title]
        path = new_tab['path']
        if not os.path.isfile(path):
            console.hud_alert(
                'The file for this tab has been moved, renamed, or deleted. the tab will now be removed.',
                icon='error',
                duration=3)
            self.close_button(sender)

        else:
            editor.open_file(path)

            def setsel():
                sel = new_tab['selection']

                while editor.get_selection()[0] < sel[0]:
                    import time
                    editor.replace_text(sel[0], sel[0], '')
                    editor.replace_text(sel[0] + 400, sel[0] + 400, '')
                    time.sleep(0.25)
                editor.set_selection(*sel)

            ui.delay(setsel, 1.0)
            sender.background_color = 'orange'
コード例 #44
0
def main():
    resp = console.alert('Alert!',
                         'Choose File Extension',
                         '.py',
                         '.pyui',
                         hide_cancel_button=False)
    if resp == 1:
        ext = '.py'
    elif resp == 2:
        ext = '.pyui'
    text = clipboard.get()
    assert text, 'No text on the clipboard!'
    filename = dialogs.text_dialog(title="What's your script called?")
    console.clear()
    print('Wait a Moment Please!')
    filename = save(filename.strip().lower().replace(" ", "_"), text.strip(),
                    ext)
    console.set_font('Futura', 16)
    save_path = str(
        "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/downloads/scripts/"
        + filename)
    print('Done!\nFile Saved as:\n\n' + filename + "\n\nin:\n\n" + save_path)
    editor.open_file(save_path, new_tab=True)
コード例 #45
0
def main(args):
    if args:
        name = args[0]
    else:
        sel = editor.get_selection() or ""
        seltxt = preformat(editor.get_text()[sel[0]:sel[1]])
        if sel and sel[0] != sel[1] and is_valid_name(seltxt):
            name = seltxt
        else:
            name = console.input_alert("Find Module")
    
    try:
        loc = find_path(name)
    except ValueError:
        console.hud_alert(name + " is not a valid module name", "error")
        return
    
    if loc == "<built-in>":
        console.hud_alert(name + " is a built-in module", "error")
    elif loc == "<string>":
        console.hud_alert("Could not find module " + name, "error")
    else:
        editor.open_file(os.path.relpath(loc, DOCS))
コード例 #46
0
ファイル: GUI_Helper.py プロジェクト: zencuke/GUI_Helper
def main(pyui_path,
         extra_func_mode=False,
         remove_title_bar=False,
         remove_status_bar=False,
         class_name=False,
         main_view_name=False):
    global gui_helper

    if not pyui_path:
        exit()
    if os.path.exists(pyui_path):
        get_attrib_main(pyui_path, extra_func_mode, remove_title_bar,
                        remove_status_bar, class_name,
                        main_view_name)  #making text
        to_path = os.path.dirname(pyui_path) + '/' + os.path.basename(
            pyui_path).replace('.pyui', '') + '_GUI_Helper.py'

        with open(to_path, 'w') as f:
            f.write(gui_helper.get_text())
        editor.open_file(to_path, True)
        console.hide_output()
    else:
        console.hud_alert('pyui not found')
コード例 #47
0
def open_tab(path_or_index=None):
    tabVC = _utils._application.keyWindow().rootViewController(
    ).detailViewController()
    # Open a new empty tab
    if isinstance(path_or_index, type(None)):
        tabVC.addTab_(None)

    # Open a new tab with a file
    if isinstance(path_or_index, str):
        import editor
        #tabVC.open(File=path, inNewTab=True, withPreferredEditorType=True, forceReload=False)
        editor.open_file(path_or_index, new_tab=True, force_reload=False)

    # Switch to an existing tab
    if isinstance(path_or_index, int):
        # This doesn't really work well, since just the editor will change tab,
        # but Pythonista won't select a different tab in the tab bar
        #tabVC.selectTabAtIndex_(path)

        # from editor.py
        tabs = []
        for tab in tabVC.tabViewControllers():
            if tab.isKindOfClass_(PA2EmptyTabViewController):
                tabs.append(None)
            if tab.isKindOfClass_(PA2UniversalTextEditorViewController):
                if not tab.isViewLoaded():
                    tabs.append(None)
                    continue
                tab_path = str(tab.filePath())
                tabs.append(tab_path)

        path = tabs[path_or_index]
        if not path is None:
            import editor
            editor.open_file(path, new_tab=True, force_reload=False)
        else:
            raise ValueError("Can't open empty path")
コード例 #48
0
ファイル: edit.py プロジェクト: BBOOXX/stash
def open_temp(file='', new_tab=True):
    try:
        file_to_edit = file
        temp = tempfile.NamedTemporaryFile(dir=os.path.expanduser('~/Documents') , suffix='.py')
        cur_path = editor.get_path()
        if file_to_edit != '':
            try:
                to_edit = open(file_to_edit,'r')
            except:
                to_edit = open(file_to_edit,'w+')

            temp.write(to_edit.read())
            temp.flush()
            to_edit.close()
            
        print('***When you are finished editing the file, you must come back to console to confim changes***')
        editor.open_file(temp.name, new_tab)
        time.sleep(1.5)
        console.hide_output()
        input = raw_input('Save Changes? Y,N: ')
    
        if input=='Y' or input=='y':
            while True:
                try:
                    save_as = raw_input('Save file as [Enter to confirm]: %s' % file_to_edit) or file_to_edit
                except:
                    save_as = file_to_edit
                if save_as:
                    break

            if not new_tab:
                editor.open_file(cur_path) # restore previous script in editor
            with open(save_as,'w') as f:
                with open(temp.name,'r') as tmp:
                    f.write(tmp.read())
                    
            print('File Saved.')
        elif input=='N' or input=='n':
            if not new_tab:
                editor.open_file(cur_path) # restore previous script in editor
    
    except Exception as e:
        print(e)
        
    finally:
        temp.close()
コード例 #49
0
def main(self,file_to_edit):
    '''Open file in a temp text page to allow editing'''
    cur_path = editor.get_path()
    #with open('tmp.txt', 'w') as file:
    try:
        file = open(TEMP_DIR+'/tmp.txt','w')
        try:
            to_edit = open(file_to_edit,'r')
            
        except:
            to_edit = open(file_to_edit,'w+')
            
        file.write(to_edit.read())
        to_edit.close()
        file.close()
        editor.reload_files()
        raw_input('*When you are finished editing the file, you must come back to console to confim changes*\n[Press Enter]')
        editor.open_file(TEMP)
        console.hide_output()
        
        input = raw_input('Save Changes? Y,N: ')
            
        if input=='Y' or input=='y':
            save_as = raw_input('Save file as [Enter to confirm]: %s' % file_to_edit) or file_to_edit
            editor.open_file(cur_path)
            tmp = open(TEMP_DIR+'/tmp.txt','r')
            cur = open(save_as,'w')
            cur.write(tmp.read())
            cur.close()
            tmp.close()
                
        elif input=='N' or input=='n':
            editor.open_file(cur_path)


        
    except Exception, e:
        print e
        return False
コード例 #50
0
ファイル: edit.py プロジェクト: briarfox/stash
def open_temp(file=''):
    try:
        file_to_edit = file
        temp = tempfile.NamedTemporaryFile(dir=os.path.expanduser('~/Documents') , suffix='.py')
        cur_path = editor.get_path()
        if file_to_edit != '':
            try:
                to_edit = open(file_to_edit,'r')
            except:
                to_edit = open(file_to_edit,'w+')

            temp.write(to_edit.read())
            temp.flush()
            to_edit.close()
            
        print '***When you are finished editing the file, you must come back to console to confim changes***'
        editor.open_file(temp.name)
        time.sleep(1.5)
        console.hide_output()
        input = raw_input('Save Changes? Y,N: ')
    
        if input=='Y' or input=='y':
            try:
                save_as = raw_input('Save file as [Enter to confirm]: %s' % file_to_edit) or file_to_edit
            except:
                save_as = file_to_edit
            
            editor.open_file(cur_path)
            with open(save_as,'w') as f:
                with open(temp.name,'r') as tmp:
                    f.write(tmp.read())
                    
            print 'File Saved.'
        elif input=='N' or input=='n':
            editor.open_file(cur_path)
    
    except Exception, e:
        print e
コード例 #51
0
ファイル: CreateTestFile.py プロジェクト: Phuket2/Pythonista
"""

# uncomment the line below, if you want nothing written
# to the temp file...
# my_std_script = ''

_target_dir = os.path.join(_base_dir, _temp_dir_name)


# make sure the target dir exists
if not os.path.isdir(_target_dir):
    result = console.alert(
        title="Directory Does Not Exist", message="the target_dir, does not exist!", button1="Make Dir"
    )

    # Cancel button exits, so no check required.

    # os.mkdir, will raise a OSError, so no check done
    os.mkdir(_target_dir)
try:
    with tempfile.NamedTemporaryFile(mode="w", dir=_target_dir, suffix=".py", delete=False) as f:
        f.write(my_std_script)
        name = f.name

except Exception as err:
    raise Exception(err.message, err.args)


# open in a new tab...
editor.open_file(name, True, False)
コード例 #52
0
ファイル: edit.py プロジェクト: briarfox/stash
def open_editor(file=''):
    if os.path.isfile(os.getcwd()+'/'+file):
        editor.open_file(os.getcwd()+'/'+file)
        console.hide_output()
    else:
        print 'File not found.'
コード例 #53
0
def ds_action(sender):
    # generic action for data source
    if sender.selected_row >= 0:
        editor.open_file(sender.items[sender.selected_row])
コード例 #54
0
ファイル: filenav.py プロジェクト: Phuket2/pythonista-scripts
def open_path(path):
    # Open an absolute path in editor
    editor.open_file(os.path.relpath(path, os.path.expanduser("~/Documents")))
コード例 #55
0
		console.hud_alert(path + ' Downloaded')
		
	def urlscheme_overwrite_file_with_wc_copy(self, path, b64_contents):
		text = base64.b64decode(b64_contents)
		
		try:
			os.makedirs(os.path.join(os.path.expanduser('~/Documents'), path))
		except OSError, e:
			if e.errno != errno.EEXIST:
				raise e
				
		full_file_path = os.path.join(os.path.expanduser('~/Documents'), path)
		with open(full_file_path, 'w') as f:
			f.write(text)
			
		editor.open_file(path)
		console.hud_alert(path +' Updated')
		
			
def main():
	wc = WorkingCopySync()
	if len(sys.argv) <= 1:
		wc.present()
	else:
		action = sys.argv[1]
		if action == 'copy_repo':
			wc.urlscheme_copy_repo_from_wc(sys.argv[2], sys.argv[3])
		elif action == 'overwrite_file':
			wc.urlscheme_overwrite_file_with_wc_copy(sys.argv[2], sys.argv[3])
		elif action == 'repo_list':
			repo_list = []
コード例 #56
0
ファイル: text_viewer.py プロジェクト: Vik2015/browsepy
 def openineditor(self, sender):
     self.view.close()
     editor.open_file(self.fn)
コード例 #57
0
ファイル: view.py プロジェクト: Floobits/floobits-neovim-old
 def focus(self):
     editor.open_file(self.vim_buf.name)
コード例 #58
0
ファイル: FileManager.py プロジェクト: c0ns0le/Pythonista
 def btn_Edit(self, sender):
     editor.open_file(self.path + '/' + self.filename)
     self.view.close()