gedit r6825 - trunk/plugins/pythonconsole/pythonconsole



Author: pborelli
Date: Thu Jan  8 01:00:58 2009
New Revision: 6825
URL: http://svn.gnome.org/viewvc/gedit?rev=6825&view=rev

Log:
2009-01-08  Paolo Borelli  <pborelli katamail com>

	* plugins/pythonconsole/pythonconsole/*: Add a config dialog
	to set console colors, patch by B. Clausius, bug #566010.



Added:
   trunk/plugins/pythonconsole/pythonconsole/config.py
   trunk/plugins/pythonconsole/pythonconsole/config.ui
Modified:
   trunk/plugins/pythonconsole/pythonconsole/Makefile.am
   trunk/plugins/pythonconsole/pythonconsole/__init__.py
   trunk/plugins/pythonconsole/pythonconsole/console.py

Modified: trunk/plugins/pythonconsole/pythonconsole/Makefile.am
==============================================================================
--- trunk/plugins/pythonconsole/pythonconsole/Makefile.am	(original)
+++ trunk/plugins/pythonconsole/pythonconsole/Makefile.am	Thu Jan  8 01:00:58 2009
@@ -1,10 +1,15 @@
 # Python console plugin
 
+plugindir = $(GEDIT_PLUGINS_LIBS_DIR)/pythonconsole
 plugin_PYTHON =		\
 	__init__.py	\
-	console.py
+	console.py	\
+	config.py
 
-plugindir = $(GEDIT_PLUGINS_LIBS_DIR)/pythonconsole
+uidir = $(GEDIT_PLUGINS_DATA_DIR)/pythonconsole/ui
+ui_DATA = config.ui
+
+EXTRA_DIST = $(ui_DATA)
 
 CLEANFILES =
 DISTCLEANFILES =

Modified: trunk/plugins/pythonconsole/pythonconsole/__init__.py
==============================================================================
--- trunk/plugins/pythonconsole/pythonconsole/__init__.py	(original)
+++ trunk/plugins/pythonconsole/pythonconsole/__init__.py	Thu Jan  8 01:00:58 2009
@@ -26,11 +26,14 @@
 
 import gtk
 import gedit
+
 from console import PythonConsole
+from config import PythonConsoleConfigDialog
 
 class PythonConsolePlugin(gedit.Plugin):
 	def __init__(self):
 		gedit.Plugin.__init__(self)
+		self.dlg = None
 		
 	def activate(self, window):
 		console = PythonConsole(namespace = {'__builtins__' : __builtins__,
@@ -52,3 +55,17 @@
 		bottom = window.get_bottom_panel()
 		bottom.remove_item(console)
 
+	def is_configurable(self):
+		return True
+
+	def create_configure_dialog(self):
+		if not self.dlg:
+			self.dlg = PythonConsoleConfigDialog(self.get_data_dir())
+		
+		dialog = self.dlg.dialog()
+		window = gedit.app_get_default().get_active_window()
+		if window:
+			dialog.set_transient_for(window)
+
+		return dialog
+

Added: trunk/plugins/pythonconsole/pythonconsole/config.py
==============================================================================
--- (empty file)
+++ trunk/plugins/pythonconsole/pythonconsole/config.py	Thu Jan  8 01:00:58 2009
@@ -0,0 +1,120 @@
+# -*- 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
+
+import gtk
+import gconf
+
+__all__ = ('PythonConsoleConfig', 'PythonConsoleConfigDialog')
+
+GCONF_KEY_BASE = '/apps/gedit-2/plugins/pythonconsole'
+GCONF_KEY_COMMAND_COLOR = GCONF_KEY_BASE + '/command-color'
+GCONF_KEY_ERROR_COLOR = GCONF_KEY_BASE + '/error-color'
+
+DEFAULT_COMMAND_COLOR = '#314e6c' # Blue Shadow
+DEFAULT_ERROR_COLOR = '#990000' # Accent Red Dark
+
+class PythonConsoleConfig (object):
+
+    def __init__(self):
+        pass
+    
+    @staticmethod
+    def add_handler(handler):
+        gconf.client_get_default().notify_add(GCONF_KEY_BASE, handler)
+
+    color_command = property(
+        lambda self:  self.gconf_get_str(GCONF_KEY_COMMAND_COLOR, DEFAULT_COMMAND_COLOR),
+        lambda self, value:  self.gconf_set_str(GCONF_KEY_COMMAND_COLOR, value))
+
+    color_error = property(
+        lambda self:  self.gconf_get_str(GCONF_KEY_ERROR_COLOR, DEFAULT_ERROR_COLOR),
+        lambda self, value:  self.gconf_set_str(GCONF_KEY_ERROR_COLOR, value))
+    
+    @staticmethod
+    def gconf_get_str(key, default=''):
+        val = gconf.client_get_default().get(key)
+        if val is not None and val.type == gconf.VALUE_STRING:
+            return val.get_string()
+        else:
+            return default
+
+    @staticmethod
+    def gconf_set_str(key, value):
+        v = gconf.Value(gconf.VALUE_STRING)
+        v.set_string(value)
+        gconf.client_get_default().set(key, v)
+
+class PythonConsoleConfigDialog (object):
+
+    def __init__(self, datadir):
+        object.__init__(self)
+        self._dialog = None
+        self._ui_path = os.path.join(datadir, 'ui', 'config.ui')
+        self.config = PythonConsoleConfig()
+
+    def dialog(self):
+        if self._dialog is None:
+            self._ui = gtk.Builder()
+            self._ui.add_from_file(self._ui_path)
+
+            self.set_colorbutton_color(self._ui.get_object('colorbutton-command'),
+                                        self.config.color_command)
+            self.set_colorbutton_color(self._ui.get_object('colorbutton-error'),
+                                        self.config.color_error)
+            
+            self._ui.connect_signals(self)
+            
+            self._dialog = self._ui.get_object('dialog-config')
+            self._dialog.show_all()
+        else:
+            self._dialog.present()
+        
+        return self._dialog
+    
+    @staticmethod
+    def set_colorbutton_color(colorbutton, value):
+        try:
+            color = gtk.gdk.color_parse(value)
+        except ValueError:
+            pass    # Default color in config.ui used
+        else:
+            colorbutton.set_color(color)
+
+    def on_dialog_config_response(self, dialog, response_id):
+        self._dialog.destroy()
+
+    def on_dialog_config_destroy(self, dialog):
+        self._dialog = None
+        self._ui = None
+        
+    def on_colorbutton_command_color_set(self, colorbutton):
+        self.config.color_command = colorbutton.get_color().to_string()
+
+    def on_colorbutton_error_color_set(self, colorbutton):
+        self.config.color_error = colorbutton.get_color().to_string()
+

Added: trunk/plugins/pythonconsole/pythonconsole/config.ui
==============================================================================
--- (empty file)
+++ trunk/plugins/pythonconsole/pythonconsole/config.ui	Thu Jan  8 01:00:58 2009
@@ -0,0 +1,107 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="2.14"/>
+  <!-- interface-naming-policy toplevel-contextual -->
+  <object class="GtkDialog" id="dialog-config">
+    <property name="window_position">center-on-parent</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">dialog</property>
+    <property name="has_separator">False</property>
+    <signal name="destroy" handler="on_dialog_config_destroy"/>
+    <signal name="response" handler="on_dialog_config_response"/>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkTable" id="table2">
+            <property name="visible">True</property>
+            <property name="border_width">6</property>
+            <property name="n_rows">2</property>
+            <property name="n_columns">2</property>
+            <property name="column_spacing">6</property>
+            <property name="row_spacing">6</property>
+            <child>
+              <object class="GtkLabel" id="label-command">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">C_ommand color:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">colorbutton-command</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label-error">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">_Error color:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">colorbutton-error</property>
+              </object>
+              <packing>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkColorButton" id="colorbutton-command">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="color">#31314e4e6c6c</property>
+                <signal name="color_set" handler="on_colorbutton_command_color_set"/>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkColorButton" id="colorbutton-error">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="color">#999900000000</property>
+                <signal name="color_set" handler="on_colorbutton_error_color_set"/>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="label" translatable="yes">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-7">button1</action-widget>
+    </action-widgets>
+  </object>
+</interface>

Modified: trunk/plugins/pythonconsole/pythonconsole/console.py
==============================================================================
--- trunk/plugins/pythonconsole/pythonconsole/console.py	(original)
+++ trunk/plugins/pythonconsole/pythonconsole/console.py	Thu Jan  8 01:00:58 2009
@@ -32,13 +32,15 @@
 import gtk
 import pango
 
+from config import PythonConsoleConfig
+
 __all__ = ('PythonConsole', 'OutFile')
 
 class PythonConsole(gtk.ScrolledWindow):
 	def __init__(self, namespace = {}):
 		gtk.ScrolledWindow.__init__(self)
 
-		self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC);
+		self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
 		self.set_shadow_type(gtk.SHADOW_IN)
 		self.view = gtk.TextView()
 		self.view.modify_font(pango.FontDescription('Monospace'))
@@ -50,11 +52,12 @@
 		buffer = self.view.get_buffer()
 		self.normal = buffer.create_tag("normal")
 		self.error  = buffer.create_tag("error")
-		self.error.set_property("foreground", "red")
 		self.command = buffer.create_tag("command")
-		self.command.set_property("foreground", "blue")
 
-		self.__spaces_pattern = re.compile(r'^\s+')		
+		PythonConsoleConfig.add_handler(self.apply_preferences)
+		self.apply_preferences()
+
+		self.__spaces_pattern = re.compile(r'^\s+')
 		self.namespace = namespace
 
 		self.block_command = False
@@ -78,6 +81,11 @@
 		self.view.connect("key-press-event", self.__key_press_event_cb)
 		buffer.connect("mark-set", self.__mark_set_cb)
 		
+	def apply_preferences(self, *args):
+		config = PythonConsoleConfig()
+		self.error.set_property("foreground", config.color_error)
+		self.command.set_property("foreground", config.color_command)
+		
 	def stop(self):
 		self.namespace = None
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]