python 将自定义浏览器选项卡插入Pythonista

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 将自定义浏览器选项卡插入Pythonista相关的知识,希望对你有一定的参考价值。

# coding: utf-8
from Foundation import *
from QuartzCore import *
from UIKit import *

import console

WKWebView = ObjCClass('WKWebView')
	
@on_main_thread
def main():
	rootVC = UIApplication.sharedApplication().windows()[0].rootViewController()
	tabVC = rootVC.detailViewController()

	methods = [openURL, search]
	protocols = ['OMTabContent']
	CustomViewController = create_objc_class('CustomViewController', UIViewController, methods=methods, protocols=protocols)
	
	vc = CustomViewController.new()
	vc.title = 'Web'
	
	urlBarItem = UIBarButtonItem.alloc().initWithImage_style_target_action_(UIImage.imageNamed_('Textures/ionicons-link-24'),0,vc,sel('openURL'))
	searchBarItem = UIBarButtonItem.alloc().initWithImage_style_target_action_(UIImage.imageNamed_('Textures/ionicons-search-24'),0,vc,sel('search'))

	vc.navigationItem().rightBarButtonItems = [urlBarItem, searchBarItem]
	
	webView = WKWebView.new()
	webView.loadRequest_(NSURLRequest.requestWithURL_(NSURL.URLWithString_('http://www.google.com')))
	vc.view = webView

	tabVC.addTabWithViewController_(vc)
	
def openURL(_self, _cmd):
	address = console.input_alert('Open URL')
	if len(address) > 0:
		ObjCInstance(_self).view().loadRequest_(NSURLRequest.requestWithURL_(NSURL.URLWithString_(address)))
	
def search(_self, _cmd):
	term = console.input_alert('Search')
	if len(term) > 0:
		ObjCInstance(_self).view().loadRequest_(NSURLRequest.requestWithURL_(NSURL.URLWithString_('http://google.com/search?q='+term)))
	
if __name__ == '__main__':
	main()

以上是关于python 将自定义浏览器选项卡插入Pythonista的主要内容,如果未能解决你的问题,请参考以下文章

将自定义小部件添加到 Flutter TabBar 的活动选项卡

将 ActiveX 控件插入到 Powerpoint 幻灯片中

国际开发协会 Python + Qt。如何将我自己的选项卡插入 IDA 主选项卡小部件?

如何在关闭浏览器选项卡或浏览器时插入数据[重复]

如何将自定义选项添加到 Microsoft Edge 右键菜单?

将自定义 boxshadow 添加到 Flutter 卡