<commit_before>import sys
from PySide import QtGui, QtCore
import json
import os
import copy

from TextEdit import Editor


class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        self.main_editor = Editor()
        self.setCentralWidget(self.main_editor)
        self.createDockWindows()
        self.createMenuBar()

    def createMenuBar(self):
        openAction = QtGui.QAction('&open', self)
        openAction.triggered.connect(self.openFile)

        exitAction = QtGui.QAction('&Exit', self)
        exitAction.triggered.connect(self.close)

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(openAction)
        fileMenu.addAction(exitAction)

    def createDockWindows(self):
        self.tree_docker = QtGui.QDockWidget("Call Sequence", self)
        self.tree_widget = QtGui.QTreeWidget(self.tree_docker)
        self.tree_widget.itemClicked.connect(self.item_clicked)
        self.tree_docker.setWidget(self.tree_widget)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea,
                           self.tree_docker)

        self.info_docker = QtGui.QDockWidget("Info", self)
        self.info_widget = QtGui.QTextEdit(self.info_docker)
        self.info_docker.setWidget(self.info_widget)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea,
                           self.info_docker)

    def openFile(self, file_name=None):
        if not file_name:
            file_name, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file')
        if not file_name:
            return
        with open(file_name, 'r') as ftr:
            call_seq = json.load(ftr)
        self.init_tree_widget(call_seq)

    def init_tree_widget(self, data):
        item = QtGui.QTreeWidgetItem()
        item.setText(0, '<top>')
        self.build_tree(item, data)
        self.tree_widget.addTopLevelItem(item)

    def build_tree(self, top, data):
        for i in data['seq']:
            item = QtGui.QTreeWidgetItem(top)
            if i['name']:
                item.setText(0, i['name'])
            else:
                item.setText(0, i['code'])
            item.meta_data = i
            name = self.build_tree(item, i)
            top.addChild(item)

    def item_clicked(self, item, column):
        meta_data = item.meta_data
        file_name = meta_data['file_name']
        if not os.path.exists(file_name):
            return
        self.main_editor.openFile(file_name)
        self.main_editor.gotoLine(meta_data['lineno'])
<commit_msg>Fix bug. If key doesn't exist, just return None.<commit_after>import sys
from PySide import QtGui, QtCore
import json
import os
import copy

from TextEdit import Editor


class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        self.main_editor = Editor()
        self.setCentralWidget(self.main_editor)
        self.createDockWindows()
        self.createMenuBar()

    def createMenuBar(self):
        openAction = QtGui.QAction('&open', self)
        openAction.triggered.connect(self.openFile)

        exitAction = QtGui.QAction('&Exit', self)
        exitAction.triggered.connect(self.close)

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(openAction)
        fileMenu.addAction(exitAction)

    def createDockWindows(self):
        self.tree_docker = QtGui.QDockWidget("Call Sequence", self)
        self.tree_widget = QtGui.QTreeWidget(self.tree_docker)
        self.tree_widget.itemClicked.connect(self.item_clicked)
        self.tree_docker.setWidget(self.tree_widget)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea,
                           self.tree_docker)

        self.info_docker = QtGui.QDockWidget("Info", self)
        self.info_widget = QtGui.QTextEdit(self.info_docker)
        self.info_docker.setWidget(self.info_widget)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea,
                           self.info_docker)

    def openFile(self, file_name=None):
        if not file_name:
            file_name, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file')
        if not file_name:
            return
        with open(file_name, 'r') as ftr:
            call_seq = json.load(ftr)
        self.init_tree_widget(call_seq)

    def init_tree_widget(self, data):
        item = QtGui.QTreeWidgetItem()
        item.setText(0, '<top>')
        self.build_tree(item, data)
        self.tree_widget.addTopLevelItem(item)

    def build_tree(self, top, data):
        for i in data['seq']:
            item = QtGui.QTreeWidgetItem(top)
            if i.get('name', None):
                item.setText(0, i['name'])
            else:
                item.setText(0, i['code'])
            item.meta_data = i
            name = self.build_tree(item, i)
            top.addChild(item)

    def item_clicked(self, item, column):
        meta_data = item.meta_data
        file_name = meta_data['file_name']
        if not os.path.exists(file_name):
            return
        self.main_editor.openFile(file_name)
        self.main_editor.gotoLine(meta_data['lineno'])

{'fraction_non_alphanumeric': 0.10364091697168176, 'fraction_numerical': 0.0011558466576767482, 'mean_word_length': 2.4090610636900855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2086337', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1604, 'n_words': 275}