def __init__(self, workflow): """Initializes the :class:`WorkflowActions`. :param workflow: the :class:`workflow.Workflow` instance we want to control. :type workflow: :class:`workflow.Workflow` """ super(WorkflowActions, self).__init__() self.workflow = workflow self['help'] = bind(self.help) self['workflow'] = bind(self.info) self['settings'] = bind(self.settings)
def initialize(self): """ Called inside of :meth:`TerminalApplication.initialize` shortly after the WebSocket is instantiated. """ # NOTE: Why not use the 'Events' hook for these? You can't attach two # functions to the same event via that mechanism because it's a dict # (one would override the other). # An alternative would be to write a single function say, on_auth() that # calls both of these functions then assign it to 'terminal:authenticate' in # the 'Events' hook. I think this way is better since it is more explicit. self.on('terminal:authenticate', bind(send_ssh_css_template, self)) self.on('terminal:authenticate', bind(create_user_ssh_dir, self))
def run(): try: new_bind = utils.bind() ctime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') timestamp = time() with open('/home/zhoujingzhong/monitor/bind.log', 'a+') as f: old_bind = int(f.readlines()[-1].strip().split('\t')[-1]) f.write('{}\t{}\t{}\n'.format(ctime, timestamp, new_bind)) if new_bind >= old_bind: new_bind -= old_bind data = {'ip': IP, 'cpu': utils.cpu(), 'memory': utils.memory(), 'disk': utils.disk(LOC), 'cache': utils.cache(), 'bind': new_bind, 'timestamp': timestamp, 'ctime': ctime} data = {'data': json.dumps(data)} data = urllib.urlencode(data) req = urllib2.Request(url=HOST, data=data) ret = urllib2.urlopen(req) ret = ret.read() except Exception, e: traceback.print_exc() logger.error(str(e))
def run(): if not os.path.exists('bind.log'): ctime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') timestamp = time() try: bind = utils.bind() except: bind = 0 with open('bind.log', 'w') as f: f.write('{}\t{}\t{}\n'.format(ctime, timestamp, bind))
def capture(self, input_R): if (type(input_R) == pd.Series): input_R = input_R.tolist() self.output_T = pd.Series(utils.bind(self.ngram + [input_R])) i = self.ngram_size - 2 while (i > 0): self.ngram[i] = utils.permute(self.ngram[i - 1]) i -= 1 self.ngram[0] = utils.permute(input_R)
def bundle(self): if self.use_final_hv: self.bind_input[self.num_channel] = utils.bind( [self.bind_input[self.num_channel - 1], self.bind_input[1]]) self.output_R = pd.Series(utils.bundle(self.bind_input))
def bind(self, i, input_Bi, input_Di): self.input_B[i] = input_Bi self.input_D[i] = input_Di self.bind_input[i] = utils.bind([self.input_B[i], self.input_D[i]])
def initialize(self): """ Called when the WebSocket is instantiated, sets up our WebSocket actions, security policies, and attaches all of our plugin hooks/events. """ example_log.debug("ExampleApplication.initialize()") # Register our security policy function in the 'security' dict self.ws.security.update({'example': example_policies}) # Register some WebSocket actions... # These can be called from the client like so: # GateOne.ws.send(JSON.stringify({'example:test_example': whatever})); self.ws.actions.update({ 'example:test_example': self.test_example, }) # Gate One provides a location where you can store information that you # want to be persistent across user sesions/connections and whatnot: if 'example' not in self.ws.persist: # If it doesn't belong in SESSIONS but you still need it to stick # around after the user disconnects put it here: self.ws.persist['example'] = {} # NOTE: If you don't care about your app having its own plugins you can # delete everything from here until the end of this function. # -- BEGIN PLUGIN CODE -- # If you want your app to support plugins here's how you do it: # First let's check if someone has explicitly given us a list of plugins # that should be enabled (so we can exclude the others): enabled_plugins = self.ws.prefs['*']['example'].get( 'enabled_plugins', []) # Now we'll use Gate One's utils.get_plugins() function to fetch a dict # containing all our Python, JavaScript, and CSS plugin files. This is # really only so we can log which plugins are enabled because the # process of importing Python plugins happens inside of init() and # JS/CSS plugin files get sent via the send_plugin_static_files() # function inside of authenticate(). self.plugins = get_plugins( # Get everything in example/plugins/ os.path.join(APPLICATION_PATH, 'plugins'), enabled_plugins) # Now let's separate the plugins by type (to save some typing) js_plugins = [] for js_path in self.plugins['js']: name = js_path.split(os.path.sep)[-1].split('.')[0] name = os.path.splitext(name)[0] js_plugins.append(name) css_plugins = [] for css_path in css_plugins: name = css_path.split(os.path.sep)[-1].split('.')[0] name = os.path.splitext(name)[0] css_plugins.append(name) plugin_list = list(set(self.plugins['py'] + js_plugins + css_plugins)) plugin_list.sort() # So there's consistent ordering example_log.info(_( "Active Example Plugins: %s" % ", ".join(plugin_list))) # Now let's attach plugin hooks. Plugin hooks can be whatever you like # and called from anywhere in your application. There's three types of # hooks you'll definitely want though: initialize(), 'WebSocket' and # 'Events' # # The initialize() hook just calls a given plugin's "initializ()" # function if it has one. The function will be passed `self` (the # current instance of your app). This allows plugins to take care of # any initialization stuff that needs to happen before anything else. # # 'WebSocket' hooks are what allow plugins to add their own WebSocket # actions such as, "myplugin:do_something" which is a very important # part of Gate One. # # 'Events' hooks allow plugins to attach functions to `OnOff` events # such as 'self.on("example:some_event", handle_some_event)' # # With those three kinds of hooks plugins can add or override pretty # much anything. # # NOTE: All GOApplication instances include the OnOff mixin class so # they can use self.on(), self.off, self.trigger(), and self.once() # # How do plugins assign these hooks? They simply include a 'hooks' dict # somewhere in the global scope of their .py files. Example: # hooks = { # 'WebSocket': {'myplugin:some_func': some_func} # 'Events': {'example:authenticate': auth_func} # } self.plugin_hooks = {} # We'll store our plugin hooks here imported = load_modules(self.plugins['py']) for plugin in imported: try: # Add the plugin's hooks dict to self.plugin_hooks: self.plugin_hooks.update({plugin.__name__: plugin.hooks}) # Now we'll call the plugin's initialize() function: if hasattr(plugin, 'initialize'): plugin.initialize(self) except AttributeError: pass # No hooks--probably just a supporting .py file. # Now we hook up the hooks: for plugin_name, hooks in self.plugin_hooks.items(): if 'WebSocket' in hooks: # Apply the plugin's WebSocket actions to ApplicationWebSocket for ws_command, func in hooks['WebSocket'].items(): self.ws.actions.update({ws_command: bind(func, self)}) # Attach the plugin's event hooks to their respective events: if 'Events' in hooks: for event, callback in hooks['Events'].items(): self.on(event, bind(callback, self))
def __init__(self, _parent): IPanel.__init__(self, _parent) frame = self.frame self.th = utils.thread_func self.msg = util_atool.show_msg # frame = tk.LabelFrame(_parent, text=' 指令列表 ', fg=util_theme.COLOR_GRAP2, borderwidth=1, padx=4, pady=4) # 包名下拉框 btn_frame = tk.Frame(frame) cbb_item = PackageCombobox(frame) cbb = ttk.Combobox(btn_frame, width=18, state='readonly', height=20, justify='center') cbb.bind("<<ComboboxSelected>>", self.cbb_call) # utils.tooltip(cbb, '选择下拉项即执行操作') utils.tooltip(cbb, '选择下拉项改变按钮功能') btn = tk.Button(btn_frame, text="Go", width=12, fg=util_theme.COLOR_BLACK) utils.bind(btn, self.btn_call) utils.bind(btn, self.btn_call, True) frame_btn_group = tk.Frame(btn_frame) # btn_am = tk.Button(frame_btn_group, text="应用管理", width=6) btn_screen = tk.Button(frame_btn_group, text="截屏", width=6) btn_install = tk.Button(frame_btn_group, text="安装", width=6) btn_log = tk.Button(frame_btn_group, text="日志", width=6) # utils.bind(btn_am, self.btn_group_call) # utils.bind(btn_am, self.btn_group_call, True) utils.bind(btn_screen, self.btn_group_call) utils.bind(btn_screen, self.btn_group_call, True) utils.bind(btn_install, self.btn_group_call) utils.bind(btn_install, self.btn_group_call, True) utils.bind(btn_log, self.btn_group_call) utils.bind(btn_log, self.btn_group_call, True) utils.tooltip(btn_screen, "左键截屏并自动打开图片\n右键截屏不自动打开图片", 800) utils.tooltip(btn_install, "左键点击 安装\n右键点击 安装剪贴板里的apk", 800) utils.tooltip(btn_log, "左键获取日志\n右键清除日志", 800) utils.set_groove((btn, btn_screen, btn_install, btn_log)) # btn_am.grid(column=1, row=1, sticky=tk.NW) btn_screen.grid(column=2, row=1, sticky=tk.NW) btn_install.grid(column=3, row=1, sticky=tk.NW) btn_log.grid(column=4, row=1, sticky=tk.NW) cbb.grid(column=1, row=1, sticky=tk.NW) btn.grid(column=2, row=1, sticky=tk.NW) tk.Label(btn_frame, width='4').grid(column=3, row=1, sticky=tk.NW) frame_btn_group.grid(column=4, row=1) # cbb_item.grid(1, 2, tk.NW) btn_frame.grid(column=1, row=1, sticky=tk.NW) self.btn = btn self.cbb_item = cbb_item self.cbb = cbb self.cbb_ops = None # self.btn_am = btn_am self.btn_screen = btn_screen self.btn_install = btn_install self.btn_log = btn_log
def manual_int(self): if self.is_manual_int: return self.is_manual_int = True win = self.win self.hasQuery = False self.LeftIsReverse = False self.RightIsReverse = False self.sortDesc = ('排序↕', "升序a-z", '降序z-a') """组装 ui """ # 颜色 GRAP = "#515556" # GRAP2 = "#B9BFC1" # TXT_BG = "#ECECEC" LIST_BG = "#EFEFEF" LIST_WIDTH = 91 + 10 # TXT_WIDTH = 80+7 # FILE_GAP = 65+10 # WRAP_LENGTH = 780 frame = tk.Frame(win, padx=8, pady=2) frame.grid(column=1, row=0, sticky=tk.N + tk.S + tk.W) self.svL = StringVar() self.svC = StringVar() self.svR = StringVar() varL = self.svL.get_object() varC = self.svC.get_object() varR = self.svR.get_object() self.list_l = tk.Listbox(frame, selectmode=tk.EXTENDED, fg=GRAP, background=LIST_BG, height=20, setgrid=1, activestyle='none') self.list_c = utils.clone(self.list_l) self.list_r = utils.clone(self.list_l) self.list_l.config(yscrollcommand=self.yscroll1, listvariable=varL) self.list_c.config(yscrollcommand=self.yscroll2, listvariable=varC) self.list_r.config(yscrollcommand=self.yscroll3, listvariable=varR) self.list_l.config(bd=1, justify=tk.RIGHT, width=LIST_WIDTH - 35) self.list_c.config(bd=0, justify=tk.CENTER, width=7) self.list_r.config(bd=1, justify=tk.LEFT, width=25) self.list_l.grid(column=1, row=10, sticky=tk.E) self.list_c.grid(column=2, row=10, sticky=tk.W) self.list_r.grid(column=3, row=10, sticky=tk.W) self.scrollbar = tk.Scrollbar(frame, orient='vertical', command=self.yview) self.scrollbar.grid(column=4, row=10, sticky=tk.N + tk.S + tk.W) # test # for x in range(30): # self.list_l.insert('end', x) # self.list_r.insert('end', x) self.msgLeft = " ;-) 点我 粘贴 需命名的文件" self.paste_l = tk.Text(frame, height=1, width=LIST_WIDTH - 30, fg=GRAP, wrap=tk.WORD, font=setting_fftool.font_default) self.paste_l.bind("<Leave>", self.paste_leave_left) self.paste_l.bind("<Button-1>", self.pasteClick) self.paste_l.tag_config("right", justify=tk.RIGHT) self.paste_l.insert(tk.INSERT, self.msgLeft, "right") self.msg_right = " ;-) 粘贴 文件名 或 文件" self.paste_r = tk.Text(frame, height=1, width=25, fg=GRAP, wrap=tk.WORD, font=setting_fftool.font_default) self.paste_r.bind("<Leave>", self.leave_right) self.paste_r.bind("<Button-1>", self.pasteClick) self.paste_r.insert(tk.INSERT, self.msg_right) self.paste_l.grid(column=1, row=0, sticky=tk.NE) self.paste_r.grid(column=3, row=0, sticky=tk.NW) # 左右排序按钮 fleft = tk.Frame(frame, padx=8, pady=2) fRight = tk.Frame(frame, padx=8, pady=2) desc = self.sortDesc self.sortLS = tk.Button(fleft, text=desc[0], width=7) self.sortLU = tk.Button(fleft, text='↑', width=2) self.sortLD = tk.Button(fleft, text='↓', width=2) self.sortRS = tk.Button(fRight, text=desc[0], width=7) self.sortRU = tk.Button(fRight, text='↑', width=2) self.sortRD = tk.Button(fRight, text='↓', width=2) widgets = (self.sortLS, self.sortLU, self.sortLD, self.sortRS, self.sortRU, self.sortRD) for w in widgets: utils.bind(w, self.sortCall) fleft.grid(column=1, row=5, sticky=tk.NE) self.sortLS.grid(column=4, row=1) self.sortLU.grid(column=2, row=1) self.sortLD.grid(column=3, row=1) fRight.grid(column=3, row=5, sticky=tk.NE) self.sortRS.grid(column=1, row=1) self.sortRU.grid(column=2, row=1) self.sortRD.grid(column=3, row=1) start_btn = tk.Button(frame, text='开始\n命名', width=6, height=3, command=self.start_check, relief=tk.GROOVE) undo_btn = tk.Button(frame, text='↺撤销', width=6, height=1, command=self.start_check, relief=tk.GROOVE) start_btn.grid(column=2, row=20) undo_btn.grid(column=2, row=21) utils.set_state(start_btn, False) utils.set_state(undo_btn, False) # 统一设置样式 tub1 = (self.list_l, self.list_r, start_btn, undo_btn) tub = widgets + tub1 utils.set_groove(tub) self.undo_btn = undo_btn self.start_btn = start_btn
def manual_int(self): if self.is_manual_int: return self.is_manual_int = True win = self.win self.win = None frame_btn = tk.Frame(win, bd=1) frame_msg = tk.Frame(win) frame_content = tk.Frame(win) frame_device = tk.Frame(frame_content) color = util_theme.COLOR_BLACK def init_btn(text, width=8): btn = tk.Button(frame_btn, text=text, width=width, fg=color) btn.bind("<Button-1>", self.btn_click) utils.set_groove((btn, )) return btn btn_refresh = init_btn('刷新设备列表', 10) btn_wifi = init_btn('Wifi调试') btn_apk = init_btn('apkinfo') btn_folder = init_btn('定位截图') btn_remote = init_btn('遥控器') btn_setting = init_btn('✿设置') utils.bind(btn_refresh, self.btn_click, True) utils.bind(btn_wifi, self.btn_click, True) utils.bind(btn_apk, self.btn_click, True) # 设置tooltip utils.tooltip(btn_refresh, "右键单击可强制刷新", 300, 3000) cbb = ttk.Combobox(frame_btn, width=10, justify='center') cbb.bind("<<ComboboxSelected>>", self.cbb_call) utils.tooltip(cbb, '选择下拉项即执行操作') # 配置下拉项 c = [['base64 转图片', self.OP_B64_IMG], ['图片转 base64', self.OP_IMG_B64]] values = [] types = [] for arr in c: values.append(arr[0]) types.append(arr[1]) cbb['values'] = tuple(values) cbb.current(0) self.cbb = cbb self.cbb_ops = types # 提示框 w = 70 if utils.is_windows else 60 label_msg = tk.Label(frame_msg, width=w, fg=color, justify='left', anchor="nw") utils.label_msg = label_msg btn_wifi.grid(column=1, row=1) btn_refresh.grid(column=2, row=1) btn_apk.grid(column=3, row=1) btn_folder.grid(column=4, row=1) btn_remote.grid(column=5, row=1) # cbb.grid(column=5, row=1) btn_setting.grid(column=6, row=1) label_msg.grid(column=1, row=2, sticky=tk.NW) frame_device.grid(column=2, row=1, sticky=tk.NW) frame_btn.grid(column=1, row=1, sticky=tk.NW) frame_msg.grid(column=1, row=2, sticky=tk.NW) frame_content.grid(column=1, row=3, sticky=tk.NW) # menu = tk.Menu(win) # for i in ('One', 'Two', 'Three'): # menu.add_command(label=i) # if (win.tk.call('tk', 'windowingsystem') == 'aqua'): # win.bind('<2>', lambda e: menu.post(e.x_root, e.y_root)) # print('<2>') # win.bind('<Control-1>', lambda e: menu.post(e.x_root, e.y_root)) # else: # win.bind('<3>', lambda e: menu.post(e.x_root, e.y_root)) # print('<3>') utils.main = self self.btn_refresh = btn_refresh self.btn_wifi = btn_wifi self.btn_apk = btn_apk self.btn_folder = btn_folder self.btn_remote = btn_remote self.btn_setting = btn_setting self.frame_device = frame_device self.show_devices()
def initialize(self): """ Called when the WebSocket is instantiated, sets up our WebSocket actions, security policies, and attaches all of our plugin hooks/events. """ example_log.debug("ExampleApplication.initialize()") # Register our security policy function in the 'security' dict self.ws.security.update({'example': example_policies}) # Register some WebSocket actions... # These can be called from the client like so: # GateOne.ws.send(JSON.stringify({'example:test_example': whatever})); self.ws.actions.update({ 'example:test_example': self.test_example, }) # Gate One provides a location where you can store information that you # want to be persistent across user sesions/connections and whatnot: if 'example' not in self.ws.persist: # If it doesn't belong in SESSIONS but you still need it to stick # around after the user disconnects put it here: self.ws.persist['example'] = {} # NOTE: If you don't care about your app having its own plugins you can # delete everything from here until the end of this function. # -- BEGIN PLUGIN CODE -- # If you want your app to support plugins here's how you do it: # First let's check if someone has explicitly given us a list of plugins # that should be enabled (so we can exclude the others): enabled_plugins = self.ws.prefs['*']['example'].get( 'enabled_plugins', []) # Now we'll use Gate One's utils.get_plugins() function to fetch a dict # containing all our Python, JavaScript, and CSS plugin files. This is # really only so we can log which plugins are enabled because the # process of importing Python plugins happens inside of init() and # JS/CSS plugin files get sent via the send_plugin_static_files() # function inside of authenticate(). self.plugins = get_plugins( # Get everything in example/plugins/ os.path.join(APPLICATION_PATH, 'plugins'), enabled_plugins) # Now let's separate the plugins by type (to save some typing) js_plugins = [] for js_path in self.plugins['js']: name = js_path.split(os.path.sep)[-2] name = os.path.splitext(name)[0] js_plugins.append(name) css_plugins = [] for css_path in css_plugins: name = css_path.split(os.path.sep)[-2] css_plugins.append(name) plugin_list = list(set(self.plugins['py'] + js_plugins + css_plugins)) plugin_list.sort() # So there's consistent ordering example_log.info( _("Active Example Plugins: %s" % ", ".join(plugin_list))) # Now let's attach plugin hooks. Plugin hooks can be whatever you like # and called from anywhere in your application. There's three types of # hooks you'll definitely want though: initialize(), 'WebSocket' and # 'Events' # # The initialize() hook just calls a given plugin's "initializ()" # function if it has one. The function will be passed `self` (the # current instance of your app). This allows plugins to take care of # any initialization stuff that needs to happen before anything else. # # 'WebSocket' hooks are what allow plugins to add their own WebSocket # actions such as, "myplugin:do_something" which is a very important # part of Gate One. # # 'Events' hooks allow plugins to attach functions to `OnOff` events # such as 'self.on("example:some_event", handle_some_event)' # # With those three kinds of hooks plugins can add or override pretty # much anything. # # NOTE: All GOApplication instances include the OnOff mixin class so # they can use self.on(), self.off, self.trigger(), and self.once() # # How do plugins assign these hooks? They simply include a 'hooks' dict # somewhere in the global scope of their .py files. Example: # hooks = { # 'WebSocket': {'myplugin:some_func': some_func} # 'Events': {'example:authenticate': auth_func} # } self.plugin_hooks = {} # We'll store our plugin hooks here imported = load_modules(self.plugins['py']) for plugin in imported: try: # Add the plugin's hooks dict to self.plugin_hooks: self.plugin_hooks.update({plugin.__name__: plugin.hooks}) # Now we'll call the plugin's initialize() function: if hasattr(plugin, 'initialize'): plugin.initialize(self) except AttributeError: pass # No hooks--probably just a supporting .py file. # Now we hook up the hooks: for plugin_name, hooks in self.plugin_hooks.items(): if 'WebSocket' in hooks: # Apply the plugin's WebSocket actions to ApplicationWebSocket for ws_command, func in hooks['WebSocket'].items(): self.ws.actions.update({ws_command: bind(func, self)}) # Attach the plugin's event hooks to their respective events: if 'Events' in hooks: for event, callback in hooks['Events'].items(): self.on(event, bind(callback, self))
def __init__(self, parent, **kw): frame = parent color_black = util_theme.COLOR_BLACK # **kw key = 'file_types' self.file_types = kw[key] if key in kw else [ ("文件", "*.*"), ] key = 'tree_num' tree_num = kw[key] if key in kw else 20 key = 'paste_notice' self.smart_notice = kw[key] if key in kw else ' ;-) 右键点我 粘贴文件' key = 'tree_widths' tree_widths = kw[key] if key in kw else [] key = 'has_list_btn' has_list_btn = kw[key] if key in kw else False # 补齐格式 arr = [] for t in self.file_types: if len(t) >= 2: arr.append(t[1].replace("*", "")) self.file_types_tup = tuple(arr) # 补齐宽度 if utils.is_mac: w_arr = [50, 100, 220, 420, 70] else: w_arr = [30, 70, 192, 370, 70] for i in range(len(w_arr)): if len(tree_widths) - 1 < i: tree_widths.append(w_arr[i]) frame_top = tk.Frame(frame) frame_center = tk.Frame(frame) # 导入文件 / ↑ / ↓ / - /+ import_btn = tk.Button(frame_top, text='导入文件', width=14) import_dir_btn = tk.Button(frame_top, text='导入目录', width=8) import_list_btn = tk.Button(frame_top, text='↺', width=2) import_btn.bind("<Button-1>", self.import_call) import_dir_btn.bind("<Button-1>", self.import_call) import_list_btn.bind("<Button-1>", self.import_call) w = 101 - 12 - 10 if utils.is_mac else 62 tf = setting_fftool.font_default smart_paste = tk.Label(frame_top, padx=8, bd=0, height=1, width=w, fg=color_black, font=tf) smart_paste['text'] = self.smart_notice utils.bind(smart_paste, self.paste_right_click, True) tips = "右键单击此处可以粘贴哦!" utils.tooltip(smart_paste, tips, 100, 6000) up = tk.Button(frame_top, text='↑', width=2, command=self.up_call) down = tk.Button(frame_top, text='↓', width=2, command=self.down_call) remove_btn = tk.Button(frame_top, text='-', width=2, command=self.remove_call) add_btn = tk.Button(frame_top, text='+', width=2, command=self.add_call) import_btn.grid(column=1, row=0) import_dir_btn.grid(column=2, row=0) if has_list_btn: import_list_btn.grid(column=3, row=0) smart_paste.grid(column=4, row=0) up.grid(column=11, row=0) down.grid(column=12, row=0) remove_btn.grid(column=13, row=0) add_btn.grid(column=14, row=0) # 设置tooltip utils.tooltip(import_list_btn, "恢复上次的文件列表", 300, 3000) # treeview self.tree = TreeView(frame_center, tree_num=tree_num, tree_widths=tree_widths) w = (frame_top, frame_center, import_btn, import_list_btn, import_dir_btn, up, down, remove_btn, add_btn) utils.set_groove(w) frame_top.grid(column=1, row=1, sticky=tk.NW) frame_center.grid(column=1, row=2, sticky=tk.NW) self.paste = smart_paste self.import_btn = import_btn self.import_list_btn = import_list_btn self.import_dir_btn = import_dir_btn self.up = up self.down = down self.remove_btn = remove_btn self.add_btn = add_btn
def __init__(self, _parent, **kw): IPanel.__init__(self, _parent) frame = self.frame label_text = kw['label_text'] if 'label_text' in kw else '' cb_text = kw['cb_text'] if 'cb_text' in kw else '' cb_call = kw['cb_call'] if 'cb_call' in kw else None btn_text = kw['btn_text'] if 'btn_text' in kw else '' btn_call = kw['connect_call'] if 'connect_call' in kw else None action_btn_text = kw[ 'action_btn_text'] if 'action_btn_text' in kw else '...' action_btn_call = kw[ 'action_btn_call'] if 'action_btn_call' in kw else None file_types = kw['filetypes'] if 'filetypes' in kw else [] is_folder = kw['isFolder'] if 'isFolder' in kw else False text_width = kw['text_width'] if 'text_width' in kw else 80 # 颜色 color = util_theme.COLOR_BLACK wrap_length = 780 font_name = '微软雅黑' if utils.is_windows else '' font_size = 7 if utils.is_windows else 12 self.cb_call = cb_call has_check = False if label_text: self.label_txt = tk.Label(frame, text=label_text, fg=color) self.label_txt.grid(column=1, row=1, sticky=tk.W) # 勾选框 形式 elif cb_text: self.var_cb = tk.IntVar() cb = tk.Checkbutton(frame, text=cb_text, variable=self.var_cb, fg=color, command=self.checkbox_call) cb.grid(column=1, row=1, sticky=tk.W) self.cb = cb has_check = True # 按钮 形式 elif btn_text: btn = tk.Button(frame, text=btn_text, fg=color) if btn_call: btn.config(command=btn_call) utils.tooltip(btn, "点击打开目录", 100, 2000) btn.grid(column=1, row=1, sticky=tk.W) self.btn = btn utils.set_groove((btn, )) # 文件路径 txt = tk.Label(frame, text='') txt.config(width=text_width, height=1, bd=1, padx=3, fg=color, wraplength=wrap_length, justify='left', anchor='w') txt.grid(column=2, row=1) # 选择文件按钮 action_btn = tk.Button(frame, text=action_btn_text, fg=color, font=(font_name, font_size), state=tk.DISABLED) if len(file_types): action_btn.config(command=self.open_file_call) utils.bind(action_btn, self.right_click_call, True) self.filetypes = file_types self.action_btn_call = action_btn_call if is_folder: action_btn.config(command=self.open_folder_call, state=tk.NORMAL) utils.bind(action_btn, self.right_click_call, True) utils.tooltip(action_btn, "左键点击 选择文件/目录\n右键点击 前往对应文件/目录", 100, 2000) action_btn.grid(column=3, row=1) tup = (frame, action_btn) utils.set_groove(tup) self.txt = txt self.action_btn = action_btn self.hasCheck = has_check self.is_folder = is_folder
def __init__(self): top_win = tk.Toplevel(utils.win) top_win.title('wifi连接') top_win.geometry(_win_pos) frame_top = tk.Frame(top_win) frame_top2 = tk.Frame(top_win) frame_list = tk.Frame(top_win) # 顶部输入框 var_entry = tk.StringVar() var_entry2 = tk.StringVar() # 模拟器端口 port = "7555" if utils.is_windows else "5555" serial1 = "127.0.0.1:{0}".format(port) serial2 = "127.0.0.1:{0}".format("62001") desc1 = "mumu模拟器" txt1 = tk.Label(frame_top, text='请输入设备的 IP 地址:') txt2 = tk.Label(frame_top, text='最近连接:', fg=theme.COLOR_GRAY) entry = tk.Entry(frame_top, textvariable=var_entry, width=28) entry.select_adjust(15) entry.focus() btn_connect = tk.Button(frame_top, text='连接', width=8) btn_serial1 = tk.Button(frame_top, text=desc1, width=40) btn_scan = tk.Button(frame_top, text='网络发现', width=8) entry.bind('<Return>', self.entry_call) btn_connect.bind('<Button-1>', self.connect_call) utils.bind(btn_serial1, self.emulator_call, False) utils.bind(btn_serial1, self.emulator_call, True) utils.tooltip(btn_serial1, "左键 mumu模拟器 {0}\n右键 夜神模拟器 {1}".format(serial1, serial2)) utils.bind(btn_scan, self.scan_call, False) utils.bind(btn_scan, self.scan_call, True) utils.tooltip(btn_scan, "左键扫描 开放5555端口的ip\n" "右键扫描 开放7555端口的ip") # tree 配置 # 列号,宽度,对齐,列名称 config = [ ["1", 140, "center", "名称"], ["2", 120, "nw", "IP"], ["3", 80, "center", "端口号"] ] names = [] for c in config: names.append(c[0]) tree = ttk.Treeview(frame_list, show="headings", selectmode=tk.EXTENDED, columns=names) tree.config(height=10) for c in config: tree.column(c[0], width=c[1], anchor=c[2]) tree.heading(c[0], text=c[3]) tree.tag_configure(self.ODD, background='#f5f5f5') tree.bind('<Button-1>', self.tree_call) tree.bind('<Double-1>', self.tree_double_call) y_scrollbar = ttk.Scrollbar(frame_list, orient=tk.VERTICAL, command=tree.yview) tree.config(yscrollcommand=y_scrollbar.set) self.i_name = 0 self.i_ip = 1 self.i_port = 2 entry2 = tk.Entry(frame_top2, textvariable=var_entry2, width=28) rename = tk.Button(frame_top2, text='✏', width=2, command=self.rename_call) up = tk.Button(frame_top2, text='↑', width=2, command=self.up_call) down = tk.Button(frame_top2, text='↓', width=2, command=self.down_call) remove_btn = tk.Button(frame_top2, text='-', width=2, command=self.remove_call) entry2.bind('<Return>', self.entry2_call) utils.tooltip(rename, "更改设备名称\n支持输入框按enter键") txt1.grid(column=1, row=1, sticky=tk.NW) entry.grid(column=1, row=2, sticky=tk.E + tk.W) btn_serial1.grid(column=1, row=3, sticky=tk.NW) txt2.grid(column=1, row=4, sticky=tk.NW) btn_connect.grid(column=2, row=2) btn_scan.grid(column=2, row=3) tree.grid(column=1, row=2) y_scrollbar.grid(column=2, row=2, sticky=tk.N + tk.S) entry2.grid(column=2, row=3) rename.grid(column=3, row=3) up.grid(column=4, row=3) down.grid(column=5, row=3) remove_btn.grid(column=6, row=3) frame_top.grid(column=1, row=1) frame_list.grid(column=1, row=2, sticky=tk.NW) frame_top2.grid(column=1, row=3, sticky=tk.EW) utils.set_groove((btn_connect, btn_serial1, btn_scan, up, down, remove_btn)) # utils.win.call('focus', '-force', entry) top_win.protocol("WM_DELETE_WINDOW", self.on_closing) self.top_win = top_win self.frame_top = frame_top self.entry = entry self.var_entry = var_entry self.var_entry2 = var_entry2 self.btn_connect = btn_connect self.btn_emulator1 = btn_serial1 self.widget_arr = [] self.serial1 = serial1 self.serial2 = serial2 self.tree = tree self.auto_select()