Skip to content

Commit

Permalink
增加了exec -p选项,用于输出指定属性,同时进一步优化了自动补全功能
Browse files Browse the repository at this point in the history
  • Loading branch information
MCTF-Alpha-27 committed Jul 26, 2024
1 parent e915ad5 commit eaedb85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__pycache__/
.vscode/
*.ui
36 changes: 22 additions & 14 deletions plugins/debugger_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from typing import IO, Any
from libs import *
from cmd import Cmd
from keyword import kwlist

__name__ = "开发者命令行"
__author__ = "此程序开发者"
__version__ = "1.1.0"
__version__ = "1.2.0"

public = {"info": "这是一个公共字典,可以在其中存储变量"}

Expand Down Expand Up @@ -41,10 +40,11 @@ def do_exec(self, args: str):
"""
运行代码。
用法:exec [[-l command] | -i]
用法:exec [-l command] [-i] [-p attr]
-l command 运行单行代码。
-i 启动多行输入模式,运行多段代码。
-p attr 输出指定的属性。
多行输入模式命令: [#run] [#rewrite line] [#show] [#exit]
Expand Down Expand Up @@ -103,32 +103,40 @@ def do_exec(self, args: str):
for i in e.args[1:]:
print(i)
print()
elif args[0] == "-p":
print(eval(args[1]))
else:
print("无效参数%s。"%args[0])

def get_widget_names(self, widget):
def get_ui_attr(self, widget):
names = []
for child in widget.children():
names.append("calculator.ui." + child.objectName())
if isinstance(child, QWidget):
names.extend(self.get_widget_names(child))
for i in dir(widget):
if not i.startswith("__"):
names.append("calculator.ui." + i)
for i in names:
try:
for j in dir(eval(i)):
if not j.startswith("__"):
names.append(i + "." + j)
except:
break
return names

def get_class_functions(self, _class):
def get_class_attr(self, _class):
functions = []
for i in dir(_class):
if not i.startswith("_"):
functions.append("calculator." + i)
return functions

def complete_exec(self, text: str, line: str, begidx: int, endidx: int):
if line.startswith("exec -l"):
widgets = self.get_widget_names(calculator)
functions = self.get_class_functions(calculator)
if line.startswith("exec -l") or line.startswith("exec -p"):
widgets = self.get_ui_attr(calculator.ui)
functions = self.get_class_attr(calculator)
complete = widgets + functions
return [i for i in complete if i.lower().startswith(text)]
return [i for i in complete if i.startswith(text)]
if line.startswith("exec"):
return ["-l", "-i"]
return ["-l", "-i", "-p"]

debuggerCmd = DebuggerCmd()

Expand Down

0 comments on commit eaedb85

Please sign in to comment.