Yes, it is possible to do a prototype in a few hours, with a doctor's
appointment in between.
Rev 2874a6f adds a copy of @button checker to leoCheck.py. I did this
mostly so I wouldn't have to show the entire code here.
The guts of the prototype is this method:
patterns = (
('class', re.compile(r'class\s+[a-z_A-Z][a-z_A-Z0-9]*.*:')),
('def', re.compile(r'^\s*def\s+[\w0-9]+.*:')),
('c.x=', re.compile(r'^\s*c\.[\w.]+\s*=')),
# Assignment to c.
('call', re.compile(r'^\s*(\w+)(\.\w+)*\s*\(.*\)')),
# Possible function call.
)
ignore = ('dict', 'enumerate', 'list', 'tuple')
# Things that look like function calls.
def show(self, fn, node):
s = leoAst.AstFormatter().format(node)
aList = g.splitLines(s)
g.trace('%s lines, %s' % (len(aList), g.shortFileName(fn)))
for s in aList:
# Match each pattern separately for better control.
for kind, pattern in self.patterns:
m = pattern.match(s)
if m:
try:
call = m.group(1)
if not any([call.startswith(z) for z in self.ignore]):
print('%6s %s' % (kind, s.rstrip()))
except IndexError:
# No m.group(1)
print('%6s %s' % (kind, s.rstrip()))
And here is the results, when node is the ast tree for nodetags.py:
show 272 lines, nodetags.py
def def init():
call g.app.createQtGui(__file__)
call g.registerHandler('after-create-leo-frame',onCreate)
call g.plugin_signon(__name__)
call g.es('Plugin %s not loaded.'%__name__,color='red')
def def onCreate(tag,keys):
c.x= c.theTagController=theTagController
class class TagController(object):
def def __init__(self,c):
call self.initialize_taglist()
c.x= c.theTagController=self
call c.frame.log.createTab('Tags',widget=self.ui)
call self.ui.update_all()
def def initialize_taglist(self):
call taglist.append(tag)
def def get_all_tags(self):
def def update_taglist(self,tag):
call self.taglist.append(tag)
call self.taglist.remove(tag)
call self.ui.update_all()
def def get_tagged_nodes(self,tag):
call nodelist.append(p.copy())
def def get_tagged_gnxes(self,tag):
def def get_tags(self,p):
call g.trace(tags,p.h)
def def add_tag(self,p,tag):
call tags.add(tag)
call self.c.setChanged(bool)
call self.update_taglist(tag)
def def remove_tag(self,p,tag):
call tags.remove(tag)
call self.c.setChanged(bool)
call self.update_taglist(tag)
class class LeoTagWidget(QtWidgets.QWidget):
def def __init__(self,c,parent=None):
call QtWidgets.QWidget.__init__(self,parent)
call self.initUI()
call self.registerCallbacks()
call g.registerHandler('select2',self.select2_hook)
call g.registerHandler('create-node',self.command2_hook)
call g.registerHandler('command2',self.command2_hook)
def def initUI(self):
call self.setObjectName('LeoTagWidget')
call self.verticalLayout_2.setContentsMargins(0,1,0,1)
call self.verticalLayout_2.setObjectName(
'nodetags-verticalLayout_2')
call self.horizontalLayout.setContentsMargins(0,0,0,0)
call self.horizontalLayout.setObjectName(
'nodetags-horizontalLayout')
call self.horizontalLayout2.setContentsMargins(0,0,0,0)
call self.horizontalLayout2.setObjectName(
'nodetags-horizontalLayout2')
call label2.setObjectName('nodetags-label2')
call label2.setText('Tags for current node:')
call self.horizontalLayout2.addWidget(label2)
call self.verticalLayout.setObjectName('nodetags-verticalLayout')
call self.comboBox.setObjectName('nodetags-comboBox')
call self.comboBox.setEditable(bool)
call self.horizontalLayout.addWidget(self.comboBox)
call self.pushButton.setObjectName('nodetags-pushButton')
call self.pushButton.setMinimumSize(24,24)
call self.pushButton.setMaximumSize(24,24)
call self.horizontalLayout.addWidget(self.pushButton)
call self.verticalLayout.addLayout(self.horizontalLayout)
call self.listWidget.setObjectName('nodetags-listWidget')
call self.verticalLayout.addWidget(self.listWidget)
call self.verticalLayout.addLayout(self.horizontalLayout2)
call self.label.setObjectName('nodetags-label')
call self.label.setText('Total: 0 items')
call self.verticalLayout.addWidget(self.label)
call self.verticalLayout_2.addLayout(self.verticalLayout)
call QtCore.QMetaObject.connectSlotsByName(self)
def def registerCallbacks(self):
call self.listWidget.itemSelectionChanged.connect(self.
item_selected)
call self.listWidget.itemClicked.connect(self.item_selected)
call self.comboBox.currentIndexChanged.connect(self.update_list)
call self.pushButton.clicked.connect(self.add_tag)
def def item_selected(self):
call c.selectPosition(p)
call c.redraw()
def def update_current_tags(self,p):
call child.widget().deleteLater()
call label.setObjectName('nodetags-label2')
call label.setText('Tags for current node:')
call hl2.addWidget(label)
call l.setText(tag)
call l.setObjectName('nodetags-label3')
call hl2.addWidget(l)
def def callback_factory(self,tag):
def def callback(event):
call tc.remove_tag(p,tag)
call ui.comboBox.setCurrentIndex(idx)
call ui.update_all()
def def update_combobox(self):
call self.comboBox.clear()
call self.comboBox.addItems(tags)
call self.comboBox.addItems(self.custom_searches)
def def update_list(self):
call self.custom_searches.append(key)
call for (i,s) in enumerate(query):
call tags.append(s.strip())
call operations.append(s.strip())
call tags.reverse()
call operations.reverse()
call self.listWidget.clear()
call self.listWidget.addItem(item)
call self.label.clear()
call self.label.setText('Total: %s nodes'%count)
def def update_all(self):
call self.update_combobox()
call self.comboBox.setCurrentIndex(idx)
call self.update_list()
call self.update_current_tags(self.c.p)
def def add_tag(self,event=None):
call g.es('Cannot add tags containing any of these
characters: &|^-',color='red')
call self.tc.add_tag(p,tag)
def def select2_hook(self,tag,keywords):
call self.update_current_tags(self.c.p)
def def command2_hook(self,tag,keywords):
call self.tc.initialize_taglist()
call self.update_all()
Imo, the cool thing about this is tat the regex's detect what we want to
detect.
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.