After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 566010 - pythonconsole uses hardcoded colors, hard to read on dark theme
pythonconsole uses hardcoded colors, hard to read on dark theme
Status: RESOLVED FIXED
Product: gedit-plugins
Classification: Other
Component: General
git master
Other All
: Normal minor
: ---
Assigned To: Gedit maintainers
Gedit maintainers
Depends on:
Blocks:
 
 
Reported: 2008-12-30 08:06 UTC by barcc
Modified: 2019-03-23 20:32 UTC
See Also:
GNOME target: ---
GNOME version: 2.23/2.24


Attachments
Add config dialog to gedit plugin pythonconsole (11.52 KB, patch)
2008-12-30 14:51 UTC, barcc
needs-work Details | Review
Add config dialog to gedit plugin pythonconsole - 2nd try (13.27 KB, patch)
2009-01-04 06:32 UTC, barcc
none Details | Review
Add config dialog to gedit plugin pythonconsole - 3 (12.59 KB, patch)
2009-01-07 22:44 UTC, barcc
committed Details | Review

Description barcc 2008-12-30 08:06:06 UTC
There should be a dialog box for change the colors
Here is a patch

Other information:
=== modified file 'pythonconsole/__init__.py'
--- old/pythonconsole/__init__.py	2008-12-28 12:10:54 +0000
+++ new/pythonconsole/__init__.py	2008-12-30 04:25:19 +0000
@@ -26,7 +26,9 @@
 
 import gtk
 import gedit
+
 from console import PythonConsole
+from config import PythonConsoleConfigDialog
 
 class PythonConsolePlugin(gedit.Plugin):
 	def __init__(self):
@@ -52,3 +54,8 @@
 		bottom = window.get_bottom_panel()
 		bottom.remove_item(console)
 
+	def is_configurable(self):
+		return True
+
+	def create_configure_dialog(self):
+		return PythonConsoleConfigDialog().dialog

=== added file 'pythonconsole/config.glade'
--- old/pythonconsole/config.glade	1970-01-01 00:00:00 +0000
+++ new/pythonconsole/config.glade	2008-12-30 05:01:47 +0000
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--Generated with glade3 3.4.5 on Tue Dec 30 06:01:47 2008 -->
+<glade-interface>
+  <widget class="GtkDialog" id="dialog-config">
+    <property name="border_width">5</property>
+    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
+    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="spacing">2</property>
+        <child>
+          <widget class="GtkFrame" id="frame1">
+            <property name="visible">True</property>
+            <property name="label_xalign">0</property>
+            <property name="shadow_type">GTK_SHADOW_OUT</property>
+            <child>
+              <widget class="GtkTable" id="table1">
+                <property name="visible">True</property>
+                <property name="n_rows">2</property>
+                <property name="n_columns">2</property>
+                <property name="column_spacing">10</property>
+                <child>
+                  <widget class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">Command:</property>
+                  </widget>
+                  <packing>
+                    <property name="x_padding">10</property>
+                    <property name="y_padding">5</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">Error:</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="x_padding">10</property>
+                    <property name="y_padding">5</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkColorButton" id="colorbutton-command">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="response_id">0</property>
+                    <property name="color">#00000000ffff</property>
+                    <signal name="color_set" handler="on_colorbutton_command_color_set"/>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="x_padding">5</property>
+                    <property name="y_padding">5</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkColorButton" id="colorbutton-error">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="response_id">0</property>
+                    <property name="color">#ffff00000000</property>
+                    <signal name="color_set" handler="on_colorbutton_error_color_set"/>
+                  </widget>
+                  <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>
+                    <property name="x_padding">5</property>
+                    <property name="y_padding">5</property>
+                  </packing>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">&lt;b&gt;Colors&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+              </widget>
+              <packing>
+                <property name="type">label_item</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">GTK_BUTTONBOX_END</property>
+            <child>
+              <widget class="GtkButton" id="button1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="label" translatable="yes">gtk-close</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">0</property>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">GTK_PACK_END</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</glade-interface>

=== added file 'pythonconsole/config.py'
--- old/pythonconsole/config.py	1970-01-01 00:00:00 +0000
+++ new/pythonconsole/config.py	2008-12-30 05:58:39 +0000
@@ -0,0 +1,95 @@
+# -*- coding: utf-8 -*-
+
+# config.py -- Config dialog
+#
+# Copyright (C) 2006 - Steve Frécinaux
+#
+# 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 gtk.glade
+import gconf
+
+
+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'
+GLADE_FILE = os.path.join(os.path.dirname(__file__), "config.glade")
+
+
+class PythonConsoleConfig (object):
+
+    def __init__(self):
+        self.color_command = self.gconf_get_str(GCONF_KEY_COMMAND_COLOR, 'blue')
+        self.color_error = self.gconf_get_str(GCONF_KEY_ERROR_COLOR, 'red')
+    
+    @staticmethod
+    def set_handler(handler):
+        gconf.client_get_default().notify_add(GCONF_KEY_BASE, handler)
+
+    def gconf_get_str(self, 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
+
+class PythonConsoleConfigDialog(object):
+
+    def __init__(self):
+        object.__init__(self)
+
+        self.ui = gtk.glade.XML(GLADE_FILE, 'dialog-config')
+        self.dialog = self.ui.get_widget('dialog-config')
+
+        config = PythonConsoleConfig()
+        self.ui.get_widget('colorbutton-command').set_color(
+                            gtk.gdk.color_parse(config.color_command))
+        self.ui.get_widget('colorbutton-error').set_color(
+                            gtk.gdk.color_parse(config.color_error))
+
+        self.ui.signal_autoconnect(self)
+
+        self.dialog.connect('response', self.on_response)
+
+    def __del__(self):
+        self.__class__._instance = None
+
+    def on_response(self, dialog, response_id):
+        self.dialog.destroy()
+
+    def on_colorbutton_command_color_set(self, colorbutton):
+        color = colorbutton.get_color()
+        value = color.to_string()
+        self.gconf_set_str(GCONF_KEY_COMMAND_COLOR, value)
+
+    def on_colorbutton_error_color_set(self, colorbutton):
+        color = colorbutton.get_color()
+        value = color.to_string()
+        self.gconf_set_str(GCONF_KEY_ERROR_COLOR, value)
+
+    def gconf_set_str(self, key, value):
+        v = gconf.Value(gconf.VALUE_STRING)
+        v.set_string(value)
+        gconf.client_get_default().set(key, v)
+

=== modified file 'pythonconsole/console.py'
--- old/pythonconsole/console.py	2008-12-28 12:10:54 +0000
+++ new/pythonconsole/console.py	2008-12-30 04:21:33 +0000
@@ -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.set_handler(self.on_gconf_notify)
+		self.on_gconf_notify()
+
+		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 on_gconf_notify(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
Comment 1 Steve Frécinaux 2008-12-30 09:30:51 UTC
Could you please attach your patch to the bug instead of copy-pasting it inline ?
Comment 2 barcc 2008-12-30 14:51:22 UTC
Created attachment 125528 [details] [review]
Add config dialog to gedit plugin pythonconsole

Sorry for pasting inline, i didn't know.
Comment 3 Paolo Borelli 2009-01-02 11:04:04 UTC
I have not looked in detail at the code, but here are a first round of comments:

 - for the ui it should use gtkbuilder format, not the obsolete glade format (either use glade3 from svn or use the conversion script shipped with gtk)

 - the config dialog should be a singleton, that is it should enforce that there is just one instance of the dialog: if I press configure more than once the same dialog should be displayed

 - the files should be added to Makefile.am in order to be built and installed

 - if possible try to create a diff agains the svn version of gedit instead of using "old", "new", because otherwise it's a bit of a pain to apply
Comment 4 barcc 2009-01-04 06:32:17 UTC
Created attachment 125723 [details] [review]
Add config dialog to gedit plugin pythonconsole - 2nd try

Thanks for your advice.

glade -> gtkbuilder:
    done
config dialog should be a singleton:
    behaves like the snippets plugin
files added to Makefile.am:
    done
diff against svn version:
    Attachment
Comment 5 Paolo Borelli 2009-01-04 13:23:32 UTC
Comment on attachment 125723 [details] [review]
Add config dialog to gedit plugin pythonconsole - 2nd try

thanks for the quick response, the patch looks pretty good to me. I have just a few nitpicks:

>Index: plugins/pythonconsole/pythonconsole/config.ui

The dialog should follow the HIG a bit more (http://library.gnome.org/devel/hig-book/stable/), in particular it should drop the frame border and it should use a slightly more descriptive strings

>-		self.__spaces_pattern = re.compile(r'^\s+')		
>+		PythonConsoleConfig.set_handler(self.on_gconf_notify)
>+		self.on_gconf_notify()
>+

Given that the function is also called here during initialization and given that the use of gconf is hidden in the config.py module, I'd rename this function "apply_preferences" or somthing similar

>===================================================================
>--- plugins/pythonconsole/pythonconsole/config.py	(Revision 0)
>+++ plugins/pythonconsole/pythonconsole/config.py	(Revision 0)
>@@ -0,0 +1,111 @@
>+# -*- coding: utf-8 -*-
>+
>+# config.py -- Config dialog
>+#
>+# Copyright (C) 2006 - Steve Frécinaux

Here you should put your name :)

>+
>+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'
>+UI_FILE = os.path.join(os.path.dirname(__file__), "config.ui")
>+

instead of using __file__ we now introduced a property of GeditPlugin that species the "datadir" path where to load files from (this is needed for proper relocability on Windows etc) so you should obtain the datadir from the gedit plugin object and pass the it to the init function PythonConsoleConfigDialog and then use it to load the ui file. you can take a look for instance at the snippet manager etc, since we just converted the other plugins to this method


>+        
>+    def on_colorbutton_command_color_set(self, colorbutton):
>+        color = colorbutton.get_color()
>+        value = color.to_string()
>+        self.gconf_set_str(GCONF_KEY_COMMAND_COLOR, value)
>+

This is ok, so this last comment is just "cosmetic", but it would be more pythonic if this class didn't know nothing about gconf and just had a reference to PythonCosoleConfig and then just did config.color_command = color; ConsoleConfig in turn would have special __set_color_command and __get_color_command methods that took care of actually storing/retrieving the value from gconf. But as I said this is just an idea, feel free to leave it as it is now.


Since you are at it, what about also adding buttons to configure the background and foreground color?
Comment 6 barcc 2009-01-07 22:44:50 UTC
Created attachment 125979 [details] [review]
Add config dialog to gedit plugin pythonconsole - 3

dialog should follow the HIG
  drop frame
  default colors from the GNOME 32-color palette
on_gconf_notify renamed to apply_preferences
gedit.Plugin.get_data_dir() instead of __file__
Only PythonConsoleConfig uses gconf, provides property
Comment 7 Paolo Borelli 2009-01-08 01:04:45 UTC
Thanks a lot for updating the patch! I committed it to svn, the feature will be available in the next release.