File: config.py

package info (click to toggle)
eog-plugins 44.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,564 kB
  • sloc: ansic: 2,848; python: 593; makefile: 34; xml: 14
file content (76 lines) | stat: -rw-r--r-- 2,768 bytes parent folder | download | duplicates (8)
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
# -*- coding: utf-8 -*-

# config.py -- Config dialog
#
# Copyright (C) 2008 - B. Clausius
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# Parts from "Interactive Python-GTK Console" (stolen from epiphany's console.py)
#     Copyright (C), 1998 James Henstridge <james@daa.com.au>
#     Copyright (C), 2005 Adam Hooper <adamh@densi.com>
# Bits from gedit Python Console Plugin
#     Copyrignt (C), 2005 Raphaƫl Slinckx

import os
from gi.repository import Gio, Gtk, Gdk

__all__ = ('PythonConsoleConfigWidget')


class PythonConsoleConfigWidget(object):

    CONSOLE_KEY_BASE = 'org.gnome.eog.plugins.pythonconsole'
    CONSOLE_KEY_COMMAND_COLOR = 'command-color'
    CONSOLE_KEY_ERROR_COLOR = 'error-color'

    def __init__(self, datadir):
        object.__init__(self)

        self._ui_path = os.path.join(datadir, 'config.ui')
        self._settings = Gio.Settings.new(self.CONSOLE_KEY_BASE)
        self._ui = Gtk.Builder()
        self._ui.set_translation_domain('eog-plugins')

    def configure_widget(self):
        self._ui.add_objects_from_file(self._ui_path, ["grid"])

        self.set_colorbutton_color(self._ui.get_object('colorbutton-command'),
                                   self._settings.get_string(self.CONSOLE_KEY_COMMAND_COLOR))
        self.set_colorbutton_color(self._ui.get_object('colorbutton-error'),
                                   self._settings.get_string(self.CONSOLE_KEY_ERROR_COLOR))

        self._ui.connect_signals(self)

        widget = self._ui.get_object('grid')

        return widget

    @staticmethod
    def set_colorbutton_color(colorbutton, value):
        color = Gdk.color_parse(value)

        if color is not None:
            colorbutton.set_color(color)

    def on_colorbutton_command_color_set(self, colorbutton):
        self._settings.set_string(self.CONSOLE_KEY_COMMAND_COLOR,
                                  colorbutton.get_color().to_string())

    def on_colorbutton_error_color_set(self, colorbutton):
        self._settings.set_string(self.CONSOLE_KEY_ERROR_COLOR,
                                  colorbutton.get_color().to_string())

# ex:et:ts=4: