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.
Copy/Paste Issue In the UI Developer
-
The issue below is still persisting! Kinda making it a bit more tedious. Love the platform tho!
Re: Pasting in UI designer always pastes into main view - not subviews
-
@streetcodernate It shouldn't be too difficult to write a Pythonista script to use as a tool after doing the paste, to move the control into the same view as the original copied control
-
@streetcodernate This is a quick and dirty little script to be configured and executed as a Pythonista tool as a workaround when you want to copy paste a control in a custom view.
First you have to select the custom view, then tap "subviews" of the custom view, then select the control you want to copy.
Then, instead of tapping copy and paste in the pop up menu, you run the script as a tool. The copy will be performed automatically in the custom view, not in the main view.
The y of the new control will be a little bit higher and its name will be the name of the original control followed by the word "copy"import console import editor from objc_util import * import ui @on_main_thread def closeTab(fn): win = UIApplication.sharedApplication().keyWindow() root_vc = win.rootViewController() tabs_vc = root_vc.detailViewController() for tab in tabs_vc.tabViewControllers(): tab_file = str(tab.filePath()) if tab_file == fn: tabs_vc.closeTab_(tab) return True return False def main(): console.clear() fn = editor.get_path() with open(fn, mode='rt') as inp: v_str = inp.read() #print(v_str) # search two selected controls t_select = '"selected" : ' is1 = v_str.find(t_select + "true") if is1 < 0: console.alert('no selected control','','ok',hide_cancel_button=True) return is2 = v_str.find('"selected" : true',is1+1) if is2 < 0: console.alert('not two selected controls','','ok',hide_cancel_button=True) return # search names of both selected controls def searchNameAndClass(isn): t = '"name" : ' i = v_str[:isn].rfind(t) j = v_str.find('",',i) nm = v_str[i+len(t)+1:j] t = '"class" : ' i = v_str[:isn].rfind(t) j = v_str.find('",',i) cl = v_str[i+len(t)+1:j] return nm,cl n1,c1 = searchNameAndClass(is1) #print(n1,c1) n2,c2 = searchNameAndClass(is2) #print(n2,c2) if c2 != 'View': console.alert('the 2nd selected control is not a subView','','ok',hide_cancel_button=True) return # duplicate copied control (and change its name) v_str = v_str[:is1] + t_select + "false" + v_str[is1+len(t_select+"true"):] i = v_str[:is1].rfind('"nodes" : [') js = v_str[:i].rfind('{') js = v_str[:js].rfind('\n') + 1 je = v_str.find('}',is1)+1 #print(v_str[js:je]) t_copy = v_str[js:je].replace('"name" : "'+n1+'"','"name" : "'+n1+'copy"') # "frame" : "{{64, 131}, {80, 32}}", fr = t_copy.find('"frame" : "{{') i = t_copy.find(', ',fr) j = t_copy.find('}',i) t_copy = t_copy[:i+1] + str(int(t_copy[i+1:j])+20) + t_copy[j:] #print(t_copy) v_str = v_str[:je] + ',\n' + t_copy + v_str[je:] #print(v_str) closeTab(fn) with open(fn, mode='wt') as out: out.write(v_str) editor.open_file(fn) if __name__ == '__main__': main()