VSCode_snippets

阅读量: 鲁文奎 2021-04-22 12:04:57
Categories: Tags:

VSCode_snippets

{
	// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and 
	// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
	// same ids are connected.
	// Example:
	// "Print to console": {
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	"printDebug": {
		"prefix": "log",
		"body": "printDebug('$1')",
		"description": "输出Log到聊天窗口"
	},
	"rds":
	{
		"prefix": "rds",
		"body": "tw2global.rds.",
		"description": "全局变量"
	},
	"server":{
		"prefix": "server",
		"body": "# -*- coding: GB18030 -*- \nimport tw2global\n\nAvatar = None\nPlayerAvatar = None\n\nclass AvatarMember(object):\n\tpass\n\nclass PlayerAvatarMember(object):\n\tpass",
		"description":"与server通信"
	},
	"dialog":{
		"prefix": "dialog",
		"body": "# -*- coding: utf-8 -*-\nimport tw2global\nfrom guis import ui\nfrom guis import Dialog\nfrom guis import CustomLib\nfrom CallbackHelper import Functor\nimport BigWorld\n\ng_dialogObj = None\ndef instance():\n\tglobal g_dialogObj\n\tif not g_dialogObj:\n\t\tg_dialogObj = ${1}()\n\treturn g_dialogObj\n\n \n#所有界面的控制逻辑体都是派生于CustomLib.CustomControlBase\nclass ${1}(CustomLib.CustomControlBase):\n\tMSG_BTN_CLOSE = 1\n\t\n\tdef __init__(self, parent = ui.getAnchor(ui.subpanel_center), x = 0, y = 0):\t\n\t\tsuper(${1}, self).__init__()\n\t\tself.parent = parent\n\t\t#隐藏即消失\n\t\tself.setPriority(self.CUSTOMBASE_PRIORITY_RELEASE_AFTER_HIDE)\n\t\tself.reset_data()\n\t\t\n\tdef show(self, need_show = True):\n\t\t#对成员的操作应该放在Display中进行\n\t\tself.need_show = need_show\n\t\tself.OnShow('${2}.xml', Argv = {'Parent': self.parent,})\n\n\tdef dummy_initialize(self):\n\t\tself.show(need_show = self.need_show)\n\n\tdef reset_data(self):\n\t\tself.need_show = True\n\t\t\n\tdef OnDestroy(self):\n\t\tpass\n\t\t\n\tdef OnInit(self):\n\t\tpass\n\t\t\t\n\tdef Display(self):\n\t\tself.hide(not self.need_show)\n\t\tself.layout()\n\n\tdef hide(self, bhide):\n\t\tsuper(${1},self).hide(bhide)\n\t\tself.need_show = not bhide\n\t\t\n\tdef layout(self):\n\t\tif self.is_hide():\n\t\t\treturn\n\t\t\n\tdef message(self, msgid, component):\n\t\tmsg = msgid - ui.msg_button\n\t\tif msg == self.MSG_BTN_CLOSE:\n\t\t\tself.hide(1)\n\t\telif msg == 2:\n\t\t\tpass\n",
		"description":"基本界面"
	},
	"dialog_new":{
		"prefix": "dialog_new",
		"body": "# -*- coding: utf-8 -*-\nimport tw2global\nfrom guis import ui\nfrom guis import Dialog\nfrom guis import CustomLib\nfrom CallbackHelper import Functor\nimport BigWorld\n\ng_dialogObj = None\ndef instance():\n\tglobal g_dialogObj\n\tif not g_dialogObj:\n\t\tg_dialogObj = ${1}()\n\treturn g_dialogObj\n\n#==============================================================================================================\n#单例模式\n#==============================================================================================================\n\n#==============================================================================================================\n#自定义组件\n#==============================================================================================================\n\n#==============================================================================================================\n#面板\n#==============================================================================================================\nclass ${1}(CustomLib.CustomControlBase):\n\t#-----------------------------------------------------------------------------------------------\n\t# >>>>>>>>>>>>>>常量定义\n\t#-----------------------------------------------------------------------------------------------\n\tMSG_BTN_CLOSE = 1\n\n\t#-----------------------------------------------------------------------------------------------\n\t# >>>>>>>>>>>>>>周期函数\n\t#-----------------------------------------------------------------------------------------------\n\tdef __init__(self, parent = ui.getAnchor(ui.subpanel_center), x = 0, y = 0):\t\n\t\tsuper(${1}, self).__init__()\n\t\tself.parent = parent\n\t\tself.x = x\n\t\tself.y = y\n\t\tself.setPriority(self.CUSTOMBASE_PRIORITY_RELEASE_AFTER_HIDE)\n\t\tself.reset_data()\n\n\t#+++++++++++++++++++++++++++++++++++++\n\t# 初始化组件的状态(包含组件的创建和设置一些初始状态)\n\t#+++++++++++++++++++++++++++++++++++++\n\tdef OnInit(self):\n\t\tpass\n\n\t#+++++++++++++++++++++++++++++++++++++\n\t# 界面被回收时调用此方法\n\t#+++++++++++++++++++++++++++++++++++++\n\tdef OnDestroy(self):\n\t\tpass\n\n\tdef Display(self):\n\t\tself.hide(not self.need_show)\n\t\tself.__updateData()\n\t\tself.__updataDynamicUI()\n\t\n\t#+++++++++++++++++++++++++++++++++++++\n\t# 外部要显示界面,调用此方法\n\t# 方法调用顺序:show()->OnInit()->Display()\n\t#+++++++++++++++++++++++++++++++++++++\n\tdef show(self, need_show = True):\n\t\tself.need_show = need_show\n\t\tself.OnShow('.xml', Argv = {'Parent': self.parent,'Offset':(self.x, self.y)})\n\n\tdef dummy_initialize(self):\n\t\tself.show(need_show = self.need_show)\n\n\tdef reset_data(self):\n\t\tself.need_show = True\n\t\n\tdef hide(self, bhide):\n\t\tsuper(${1},self).hide(bhide)\n\t\tself.need_show = not bhide\n\n\t#+++++++++++++++++++++++++++++++++++++\n\t# 界面的消息执行模型\n\t# todo:\n\t# 为界面上的各种组件提供消息处理\n\t#+++++++++++++++++++++++++++++++++++++\n\tdef message(self, msgid, component):\n\t\tmsg = msgid - ui.msg_button\n\t\tif msg == self.MSG_BTN_CLOSE:\n\t\t\tself.hide(1)\n\t\telif msg == 2:\n\t\t\tpass\n\n\t#-----------------------------------------------------------------------------------------------\n\t# >>>>>>>>>>>>>>API\n\t#-----------------------------------------------------------------------------------------------\n\n\t#-----------------------------------------------------------------------------------------------\n\t# >>>>>>>>>>>>>>内部函数\n\t#-----------------------------------------------------------------------------------------------\n\t#+++++++++++++++++++++++++++++++++\n\t#更新数据\n\t#+++++++++++++++++++++++++++++++++\n\tdef __updateData():\n\t\tself.__updateDataFromTable()\n\t\tself.__requestDataFromServer()\n\n\t#+++++++++++++++++++++++++++++++++\n\t#从表中更新数据\n\t#+++++++++++++++++++++++++++++++++\n\tdef __updateDataFromTable():\n\t\tpass\n\t\n\t#+++++++++++++++++++++++++++++++++\n\t#向服务器请求数据\n\t#+++++++++++++++++++++++++++++++++\n\tdef __requestDataFromServer()\n\t\tpass\n\t\n\t#+++++++++++++++++++++++++++++++++++++\n\t# 更新界面的数据模型\n\t# todo:\n\t# 根据数据来显示UI\n\t#+++++++++++++++++++++++++++++++++++++\n\tdef __updataDynamicUI(self):\n\t\tif self.is_hide():\n\t\t\treturn\n\t\t## todo\n\t#-----------------------------------------------------------------------------------------------\n\t# >>>>>>>>>>>>>>组件回调函数\n\t#-----------------------------------------------------------------------------------------------\n\n\t#-----------------------------------------------------------------------------------------------\n\t# >>>>>>>>>>>>>>与服务器交互\n\t#-----------------------------------------------------------------------------------------------\n",
		"description": "标准页面"
	},
	"view":{
		"prefix": "view",
		"body": "# -*- coding:GB18030 -*-\nfrom guis import ui\nfrom guis.uimve import view\nfrom guis.uimve import event\nimport ${2} #事件 event\nimport ${3} # 数据 model\nfrom guis import ui_common_v2 as v2\nimport tw2global\n\n# ==================================================================\n# \n# ==================================================================\n\n# ==================================================================\n# 组件的前缀说明:\n# btn: 按钮相关\n# ckbtn: 复选框按钮\n# crbtn: 单选框按钮\n# lb: 文本相关\n# rlb: 富文本相关\n# clb: 可点击的文本\n# cs: 可选区域\n# cb: 画一个区域\n# cli: 列表\n# csr: 滑动条\n# cimg: 图片\n# ced: 文本输入框\n# crl: 右对齐文本\n# ==================================================================\n\n# ==================================================================\n# 打印函数调用堆栈\n# import inspect\n# print self,': ',inspect.stack()\n# ==================================================================\n\ng_dialog = None\n\ndef instance():\n\tglobal g_dialog\n\tif not g_dialog:\n\t\tg_dialog = ${1}()\n\treturn g_dialog\n\n# from debug.test_mve import test_view as view\n# view.instance().hide(0)\nclass ${1}(view.View):\n\t# 这个大小由使用的面板的的背景来决定, 这里设置的大小适合于a1的面板\n\tCAP_RECT_WIDTH = 1098  # 可拖动区域的大小\n\tCAP_RECT_HEIGHT = 131  # 可拖动区域的高度\n\n\tdef __init__(self, parent=ui.getAnchor(ui.subpanel_center)):\n\t\t# parent,filename,pos,msg,style=0,cap=True,w=0,h=0\n\t\t# 这里需要注意的是style参数(定义在ui.py文件中):\n\t\t# 用 | 连接\n\t\t# STYLE_NONE = 0\n\t\t# 能否移动\n\t\t# STYLE_CAN_MOVE = 1\n\t\t# 固定窗口顺序\n\t\t# STYLE_STABLE_ORDER = 2\n\t\t# 检查是否移出屏幕边界\n\t\t# STYLE_STICK_INSIDE = 4\n\t\tsuper(${1}, self).__init__(parent, v2.DIALOG_BG_STYLE_A1, v2.DIALOG_BG_STYLE_A1_POS, 0, style=1)\n\t\tself.setCapRect(0, 0, self.CAP_RECT_WIDTH, self.CAP_RECT_HEIGHT)\n\t\tself.closeBtn = self.create_close_button(bg_Style=ui.BG_STYLE_A1)\n\t\ttw2global.rds.${1} = self\n\t\tself.data = None # 数据中心\n\n\t@view.check_dialog_show(event_id=event.EVENT_UPDATE_DIALOG)\n\tdef layout(self):\n\t\tpass\n\n\tdef hide(self, bhide):\n\t\tsuper(${1}, self).hide(bhide)\n\t\tui.regShowDialog(self, bhide, 1)\n\t\tif not bhide:\n\t\t\t# 注册数据中心\n\t\t\tself.data = test_model.instance(self) # 注册 view\n\t\t\t# 注册所有事件\n\t\t\tfor method_name in TestView.ALL_DYNAMIC_LIST:\n\t\t\t\tfunc = getattr(self,method_name,None)\n\t\t\t\tif func and hasattr(func,'__call__'):\n\t\t\t\t\tfunc(call_type = \"register\")\n\t\telse:\n\t\t\tif self.data!=None:\n\t\t\t\tself.data.release_all_event(self) # 取消注册所有事件\n\t\t\t\tself.data = None\n\n\tdef message(self, msgid):\n\t\tmsg = msgid - ui.msg_button\n\t\tif msg == 1 or msg == ui.msg_escape:\n\t\t\tself.hide(True)\n",
		"description": "view 模板"
	},
	"model":{
		"prefix": "model",
		"body": "# -*- coding:GB18030 -*-\nfrom guis import ui\nfrom guis.uimve import model\nfrom guis.uimve import event\nimport ${2} # 事件 event\n\n# 1. 这里的设计可以解决数据先到, 然后在客户端缓存的问题\n# 2. 解决一个数据中心对应多个界面的问题\ng_data = None\ndef instance(bind_view_root = None):\n\tglobal g_data\n\tif not g_data:\n\t\tg_data = ${1}()\n\tif bind_view_root:\n\t\tg_data.add_view_root(bind_view_root)\n\treturn g_data\n\n# from debug.test_mve import ${1} as model\n# model.instance()\nclass ${1}(model.Model):\n\t\"\"\"\n\t数据中心\n\t\"\"\"\n\tdef __init__(self):\n\t\tsuper(${1},self).__init__()\n\n# ==============================属性例子=====================================\n\t# @property\n\t# def Age(self):\n\t# \treturn self._age\n\n\t# @Age.setter\n\t# def Age(self,v):\n\t# \tif v!=self._age:\n\t# \t\tself._age = v\n\t# \t\tself.trigger_event(test_event.EVENT_AGE,self._age)\n# ==============================属性例子=====================================",
		"description": "model 模板"
	},
	"props":{
		"prefix": "props",
		"body": "@property\ndef ${1}(self):\n\treturn\n\n@${1}.setter\ndef Name(self, value):\n\tpass",
		"description": "属性"
	}
	// }
}