~ubuntu-branches/ubuntu/vivid/kate/vivid-proposed

« back to all changes in this revision

Viewing changes to addons/kate/pate/src/plugins/python_utils/python_utils.py

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
'''Python Utilities: Parse Checker, PEP8 Checker, Pyflakes Checker, Snippets'''
3
 
 
4
 
# Copyright (c) 2013 by Pablo Martín <goinnn@gmail.com>
5
 
#
6
 
# This software is free software: you can redistribute it and/or modify
7
 
# it under the terms of the GNU Lesser General Public License as published by
8
 
# the Free Software Foundation, either version 3 of the License, or
9
 
# (at your option) any later version.
10
 
#
11
 
# This software is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU Lesser General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU Lesser General Public License
17
 
# along with this software.  If not, see <http://www.gnu.org/licenses/>.
18
 
 
19
 
# This plugin originally was in this repository:
20
 
# <https://github.com/goinnn/Kate-plugins/tree/master/kate_plugins/pyte_plugins/>
21
 
# The original author of the pep8 and pyflakes checker is Alejandro Blanco <alejandro.b.e@gmail.com>
22
 
 
23
 
import os
24
 
 
25
 
from PyQt4 import uic
26
 
from PyQt4.QtGui import QWidget
27
 
 
28
 
from libkatepate.compat import text_type
29
 
 
30
 
from python_snippets import *
31
 
from python_checkers.parse_checker import *
32
 
 
33
 
from python_settings import (KATE_CONFIG,
34
 
                             _PEP8_CHECK_WHEN_SAVE,
35
 
                             _IGNORE_PEP8_ERRORS,
36
 
                             _PYFLAKES_CHECK_WHEN_SAVE,
37
 
                             _PARSECODE_CHECK_WHEN_SAVE,
38
 
                             _IPDB_SNIPPET,
39
 
                             DEFAULT_CHECK_PEP8_WHEN_SAVE,
40
 
                             DEFAULT_IGNORE_PEP8_ERRORS,
41
 
                             DEFAULT_CHECK_PYFLAKES_WHEN_SAVE,
42
 
                             DEFAULT_PARSECODE_CHECK_WHEN_SAVE,
43
 
                             DEFAULT_IPDB_SNIPPET)
44
 
 
45
 
 
46
 
_CONFIG_UI = 'python_utils.ui'
47
 
 
48
 
 
49
 
class ConfigWidget(QWidget):
50
 
    """Configuration widget for this plugin."""
51
 
 
52
 
    def __init__(self, parent=None, name=None):
53
 
        super(ConfigWidget, self).__init__(parent)
54
 
        # Set up the user interface from Designer.
55
 
        uic.loadUi(os.path.join(os.path.dirname(__file__), _CONFIG_UI), self)
56
 
        self.reset()
57
 
 
58
 
    def apply(self):
59
 
        kate.configuration[_PEP8_CHECK_WHEN_SAVE] = self.checkPEP8WhenSave.isChecked()
60
 
        kate.configuration[_IGNORE_PEP8_ERRORS] = self.ignorePEP8Errors.text()
61
 
        kate.configuration[_PYFLAKES_CHECK_WHEN_SAVE] = self.checkPyFlakesWhenSave.isChecked()
62
 
        kate.configuration[_PARSECODE_CHECK_WHEN_SAVE] = self.checkParseCode.isChecked()
63
 
        kate.configuration[_IPDB_SNIPPET] = self.ipdbSnippet.text()
64
 
        kate.configuration.save()
65
 
 
66
 
    def reset(self):
67
 
        self.defaults()
68
 
        if _PEP8_CHECK_WHEN_SAVE in kate.configuration:
69
 
            self.checkPEP8WhenSave.setChecked(kate.configuration[_PEP8_CHECK_WHEN_SAVE])
70
 
        if _IGNORE_PEP8_ERRORS in kate.configuration:
71
 
            self.ignorePEP8Errors.setText(kate.configuration[_IGNORE_PEP8_ERRORS])
72
 
        if _PYFLAKES_CHECK_WHEN_SAVE in kate.configuration:
73
 
            self.checkPyFlakesWhenSave.setChecked(kate.configuration[_PYFLAKES_CHECK_WHEN_SAVE])
74
 
        if _PARSECODE_CHECK_WHEN_SAVE in kate.configuration:
75
 
            self.checkParseCode.setChecked(kate.configuration[_PARSECODE_CHECK_WHEN_SAVE])
76
 
        if _IPDB_SNIPPET in kate.configuration:
77
 
            self.ipdbSnippet.setText(kate.configuration[_IPDB_SNIPPET])
78
 
 
79
 
    def defaults(self):
80
 
        self.checkPEP8WhenSave.setChecked(DEFAULT_CHECK_PEP8_WHEN_SAVE)
81
 
        self.ignorePEP8Errors.setText(DEFAULT_IGNORE_PEP8_ERRORS)
82
 
        self.checkPyFlakesWhenSave.setChecked(DEFAULT_CHECK_PYFLAKES_WHEN_SAVE)
83
 
        self.checkParseCode.setChecked(DEFAULT_PARSECODE_CHECK_WHEN_SAVE)
84
 
        self.ipdbSnippet.setText(DEFAULT_IPDB_SNIPPET)
85
 
 
86
 
 
87
 
class ConfigPage(kate.Kate.PluginConfigPage, QWidget):
88
 
    """Kate configuration page for this plugin."""
89
 
    def __init__(self, parent=None, name=None):
90
 
        super(ConfigPage, self).__init__(parent, name)
91
 
        self.widget = ConfigWidget(parent)
92
 
        lo = parent.layout()
93
 
        lo.addWidget(self.widget)
94
 
 
95
 
    def apply(self):
96
 
        self.widget.apply()
97
 
 
98
 
    def reset(self):
99
 
        self.widget.reset()
100
 
 
101
 
    def defaults(self):
102
 
        self.widget.defaults()
103
 
        self.changed.emit()
104
 
 
105
 
 
106
 
@kate.configPage(**KATE_CONFIG)
107
 
def configPage(parent=None, name=None):
108
 
    return ConfigPage(parent, name)
109
 
 
110
 
 
111
 
# kate: space-indent on; indent-width 4;