1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#Frame.py
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(50, 50, 500, 300)
self.setWindowTitle("PyQT!")
Exit = QtGui.QAction("&Exit", self)
Exit.setShortcut("Ctrl+Q")
Exit.setStatusTip('Quit')
Exit.triggered.connect(self.close_application)
OpenFile = QtGui.QAction("&Open File", self)
OpenFile.setShortcut("Ctrl+O")
OpenFile.setStatusTip("Open File")
OpenFile.triggered.connect(self.File_Open)
OpenEditor = QtGui.QAction("&Editor", self)
OpenEditor.setShortcut("Ctrl+E")
OpenEditor.setStatusTip("Open Editor")
OpenEditor.triggered.connect(self.editor)
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('&File')
fileMenu.addAction(Exit)
fileMenu.addAction(OpenFile)
editorMenu = mainMenu.addMenu("&Editor")
editorMenu.addAction(OpenEditor)
self.show()
def close_application(self):
print("bye bye !")
sys.exit()
def editor(self):
self.textEdit = QtGui.QTextEdit()
self.setCentralWidget(self.textEdit)
def File_Open(self):
numl = 0
commentCount = 0;
self.name = QtGui.QFileDialog.getOpenFileName(self, 'Open File')
#file = open(name, 'r')
self.editor()
defCount = 0
with open(self.name, 'r') as file:
for eachLine in file: #loops the lines in the file object ans sets the pointer to the end of the file
if eachLine.strip(): #check if the line is a blank line
numl += 1
if eachLine.find('#') != -1: #looks to find the comment tag
commentCount += 1
print("number of comments %i" % commentCount)
print("num lines %i: "% numl)
file.seek(0, 0) #resets the pointer to the beginning of the file so we can read it again
text = file.read()
self.textEdit.setText(text)
#function_counter = CountFunc(self.name)
class CountFunc(ast.NodeVisitor):
def __init__(self):
self. func_count = 0
self.path="ui/Frame.py"
def visit_FunctionDef(self, node):
self.func_count += 1
def GoToPath(self):
p = ast.parse(open(self.path).read())
self.visit(p)
print("number of functions:", self.func_count) |
Partager