Exemple #1
0
    def __init__(self, filename, filepath):
        '''
        Initialize builder class and reads objects from xml
        @param filename - filename to be used
        @param filepath - source code filepath
        '''
        self._builder = Gtk.Builder()
        self._builder.add_from_file('windows/code_window.xml')
        self._window = self._builder.get_object('code_window')
        self._code_frame = self._builder.get_object('code_frame')
        self._error_image = self._builder.get_object('error_image')
        self._error_label = self._builder.get_object('error_label')
        self._error_box = self._builder.get_object('error_box')
        self._button_toolbar = self._builder.get_object('button_toolbar')
        self._statusbar = self._builder.get_object('statusbar')
        self._pylint_button = self._builder.get_object('pylint_button')
        self._spinner = self._builder.get_object('spinner')
        self._scanning_label = self._builder.get_object('scanning_label')
        self._save_button = self._builder.get_object('save_button')
        self._builder.connect_signals(self)
        self._filename = filename
        self._filepath = filepath
    
        if gsm.get(gsm.EDITOR) == gsm.VISUAL_EDITOR:
            self._editor = GeditEditor(filename, filepath, self)
        else:
            self._editor = VimEditor(filename, filepath)
            self._button_toolbar.set_visible(False)

        self._code_frame.add(self._editor.get_component())
        self._window.connect("delete-event", self.exit)
        self._window.set_title("%s : %s" % (filename, filepath))
Exemple #2
0
class CodeWindow:
    '''
    Source code window
    Author: Jan Vorcak <*****@*****.**>
    '''
    def __init__(self, filename, filepath):
        '''
        Initialize builder class and reads objects from xml
        @param filename - filename to be used
        @param filepath - source code filepath
        '''
        self._builder = Gtk.Builder()
        self._builder.add_from_file('windows/code_window.xml')
        self._window = self._builder.get_object('code_window')
        self._code_frame = self._builder.get_object('code_frame')
        self._error_image = self._builder.get_object('error_image')
        self._error_label = self._builder.get_object('error_label')
        self._error_box = self._builder.get_object('error_box')
        self._button_toolbar = self._builder.get_object('button_toolbar')
        self._statusbar = self._builder.get_object('statusbar')
        self._pylint_button = self._builder.get_object('pylint_button')
        self._spinner = self._builder.get_object('spinner')
        self._scanning_label = self._builder.get_object('scanning_label')
        self._save_button = self._builder.get_object('save_button')
        self._builder.connect_signals(self)
        self._filename = filename
        self._filepath = filepath
    
        if gsm.get(gsm.EDITOR) == gsm.VISUAL_EDITOR:
            self._editor = GeditEditor(filename, filepath, self)
        else:
            self._editor = VimEditor(filename, filepath)
            self._button_toolbar.set_visible(False)

        self._code_frame.add(self._editor.get_component())
        self._window.connect("delete-event", self.exit)
        self._window.set_title("%s : %s" % (filename, filepath))

    def show_all(self):
        self._window.show()
        self._error_box.set_visible(False)

    def present(self):
        self._window.present()

    def run_pylint(self, parent=None):
        '''
        This method runs pylint agains the currently opened file
        Author: Jan Vorcak <*****@*****.**>
        '''
        LOGILAB_MANAGER.astng_cache.clear()
        self._editor.clear_tags()
        plugins = []
        pylintrc = None
        linter = TextBufferLinter()
        linter.init_linter(EditorReporter(self._editor), pylintrc)
        linter.set_scanning_items(self._scanning_label, self._spinner)
        linter.load_default_plugins()
        linter.load_plugin_modules(plugins)
        linter.read_config_file()
        linter.load_config_file()
        linter.set_buffer(self._editor.buff)
        linter.start()

    def ignore_message_clicked(self, button):
        self._error_box.set_visible(False)
        self._editor.ignore_current_tag()
        self.run_pylint()

    def disable_message_clicked(self, button):
        self._error_box.set_visible(False)
        pmm.ignore_code(self._editor.error_tag.msg_code)
        self.run_pylint()

    def save(self, parent):
        self._editor.save()

    def set_lineno(self, lineno):
        self._editor.set_lineno(lineno)

    def exit(self, event, data):
        '''
        Needs to be unregistered from WindowManager when closing
        '''
        w = WindowManager()
        w.unregister(self._filepath)