Introduced support for colored IRC texts.

Sun, 25 Nov 2012 20:11:13 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 25 Nov 2012 20:11:13 +0100
changeset 2228
5c59b9393306
parent 2227
b7aceb255831
child 2229
78539385a8df

Introduced support for colored IRC texts.

Network/IRC/IrcUtilities.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/ConfigurationPageBase.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/IrcPage.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/IrcPage.ui file | annotate | diff | comparison | revisions
Preferences/__init__.py file | annotate | diff | comparison | revisions
UI/UserInterface.py file | annotate | diff | comparison | revisions
--- a/Network/IRC/IrcUtilities.py	Sun Nov 25 18:40:15 2012 +0100
+++ b/Network/IRC/IrcUtilities.py	Sun Nov 25 20:11:13 2012 +0100
@@ -20,7 +20,7 @@
     r"""((?:http|ftp|https):\/\/[\w\-_]+(?:\.[\w\-_]+)+"""
     r"""(?:[\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)""")
 __ColorRe = re.compile(
-    r"""((?:\x03(?:0[0-9]|1[0-5]|[0-9])?(?:,?(?:0[0-9]|1[0-5]|[0-9])))"""
+    r"""((?:\x03(?:0[0-9]|1[0-5]|[0-9])?(?:,(?:0[0-9]|1[0-5]|[0-9]))?)"""
     r"""|\x02|\x03|\x13|\x15|\x16|\x17|\x1d|\x1f)""")
 
 def ircTimestamp():
@@ -67,8 +67,13 @@
                 msgParts.append("<b>")
                 openTags.append("b")
         elif part in ["\x03", "\x17"]:
-            # TODO: implement color reset
-            continue
+            if Preferences.getIrc("EnableIrcColours"):
+                if openTags and openTags[-1] == "span":
+                    msgParts.append("</" + openTags.pop(-1) +">")
+                else:
+                    continue
+            else:
+                continue
         elif part == "\x0f":                                # reset
             while openTags:
                 msgParts.append("</" + openTags.pop(-1) +">")
@@ -85,7 +90,7 @@
                 msgParts.append("<u>")
                 openTags.append("u")
         elif part == "\x16":
-            # TODO: implement color reversal
+            # revert color not supported
             continue
         elif part == "\x1d":                                # italic
             if openTags and openTags[-1] == "i":
@@ -94,8 +99,26 @@
                 msgParts.append("<i>")
                 openTags.append("i")
         elif part.startswith("\x03"):
-            # TODO: implement color support
-            continue
+            if Preferences.getIrc("EnableIrcColours"):
+                colors = part[1:].split(",", 1)
+                if len(colors) == 1:
+                    # foreground color only
+                    tag = '<span style="color:{0}">'.format(Preferences.getIrc(
+                        "IrcColor{0}".format(int(colors[0]))))
+                else:
+                    if colors[0]:
+                        # foreground and background
+                        tag = '<span style="background-color:{0};color={1}">'.format(
+                            Preferences.getIrc("IrcColor{0}".format(int(colors[0]))),
+                            Preferences.getIrc("IrcColor{0}".format(int(colors[1]))))
+                    else:
+                        # background only
+                        tag = '<span style="background-color:{0}">'.format(
+                            Preferences.getIrc("IrcColor{0}".format(int(colors[1]))))
+                msgParts.append(tag)
+                openTags.append("span")
+            else:
+                continue
         else:
             msgParts.append(part)
     msg = "".join(msgParts)
--- a/Preferences/ConfigurationPages/ConfigurationPageBase.py	Sun Nov 25 18:40:15 2012 +0100
+++ b/Preferences/ConfigurationPages/ConfigurationPageBase.py	Sun Nov 25 20:11:13 2012 +0100
@@ -40,13 +40,14 @@
         """
         return
         
-    def initColour(self, colourstr, button, prefMethod):
+    def initColour(self, colourstr, button, prefMethod, selectSlot=None):
         """
         Public method to initialize a colour selection button.
         
         @param colourstr colour to be set (string)
         @param button reference to a button to show the colour on (QPushButton)
         @param prefMethod preferences method to get the colour
+        @param selectSlot method to select the color
         @return reference to the created colour (QColor)
         """
         colour = QColor(prefMethod(colourstr))
@@ -55,6 +56,9 @@
         pm.fill(colour)
         button.setIconSize(pm.size())
         button.setIcon(QIcon(pm))
+        button.setProperty("colorName", colourstr)
+        if selectSlot is not None:
+            button.clicked[()].connect(selectSlot)
         return colour
         
     def selectColour(self, button, colourVar, showAlpha=False):
--- a/Preferences/ConfigurationPages/IrcPage.py	Sun Nov 25 18:40:15 2012 +0100
+++ b/Preferences/ConfigurationPages/IrcPage.py	Sun Nov 25 20:11:13 2012 +0100
@@ -8,7 +8,6 @@
 """
 
 from PyQt4.QtCore import pyqtSlot
-##from PyQt4.QtGui import QWidget
 
 from .ConfigurationPageBase import ConfigurationPageBase
 from .Ui_IrcPage import Ui_IrcPage
@@ -47,6 +46,7 @@
             self.dateFormatCombo.findText(Preferences.getIrc("DateFormat")))
         
         # colours
+        # TODO: convert this to the code style below
         self.ircColours["NetworkMessageColour"] = \
             self.initColour("NetworkMessageColour", self.networkButton,
                 Preferences.getIrc)
@@ -86,6 +86,40 @@
         self.joinLeaveCheckBox.setChecked(Preferences.getIrc("NotifyJoinPart"))
         self.messageCheckBox.setChecked(Preferences.getIrc("NotifyMessage"))
         self.ownNickCheckBox.setChecked(Preferences.getIrc("NotifyNick"))
+        
+        # IRC text colors
+        self.ircColours["IrcColor0"] = self.initColour(
+            "IrcColor0", self.ircColor0Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor1"] = self.initColour(
+            "IrcColor1", self.ircColor1Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor2"] = self.initColour(
+            "IrcColor2", self.ircColor2Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor3"] = self.initColour(
+            "IrcColor3", self.ircColor3Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor4"] = self.initColour(
+            "IrcColor4", self.ircColor4Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor5"] = self.initColour(
+            "IrcColor5", self.ircColor5Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor6"] = self.initColour(
+            "IrcColor6", self.ircColor6Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor7"] = self.initColour(
+            "IrcColor7", self.ircColor7Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor8"] = self.initColour(
+            "IrcColor8", self.ircColor8Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor9"] = self.initColour(
+            "IrcColor9", self.ircColor9Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor10"] = self.initColour(
+            "IrcColor10", self.ircColor10Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor11"] = self.initColour(
+            "IrcColor11", self.ircColor11Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor12"] = self.initColour(
+            "IrcColor12", self.ircColor12Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor13"] = self.initColour(
+            "IrcColor13", self.ircColor13Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor14"] = self.initColour(
+            "IrcColor14", self.ircColor14Button, Preferences.getIrc, self.__selectColour)
+        self.ircColours["IrcColor15"] = self.initColour(
+            "IrcColor15", self.ircColor15Button, Preferences.getIrc, self.__selectColour)
     
     def save(self):
         """
@@ -205,6 +239,16 @@
         self.ircColours["HyperlinkColour"] = \
             self.selectColour(self.hyperlinkButton,
                 self.ircColours["HyperlinkColour"])
+    
+    @pyqtSlot()
+    def __selectColour(self):
+        """
+        Private slot to select a color.
+        """
+        button = self.sender()
+        colorKey = button.property("colorName")
+        self.ircColours[colorKey] = self.selectColour(
+            button, self.ircColours[colorKey])
 
 
 def create(dlg):
--- a/Preferences/ConfigurationPages/IrcPage.ui	Sun Nov 25 18:40:15 2012 +0100
+++ b/Preferences/ConfigurationPages/IrcPage.ui	Sun Nov 25 20:11:13 2012 +0100
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>501</width>
-    <height>651</height>
+    <height>853</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
@@ -34,7 +34,7 @@
    <item>
     <widget class="QGroupBox" name="timestampGroup">
      <property name="toolTip">
-      <string>Select to show timestamps</string>
+      <string>Enable to show timestamps</string>
      </property>
      <property name="title">
       <string>Show Timestamps</string>
@@ -359,7 +359,297 @@
     </widget>
    </item>
    <item>
+    <widget class="QGroupBox" name="textColoursGroup">
+     <property name="toolTip">
+      <string>Enable to allow coloured text in IRC messages</string>
+     </property>
+     <property name="title">
+      <string>Allow Colored Text in IRC Messages</string>
+     </property>
+     <property name="checkable">
+      <bool>true</bool>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_4">
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_15">
+        <property name="text">
+         <string notr="true">0:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QPushButton" name="ircColor0Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2">
+       <widget class="QLabel" name="label_19">
+        <property name="text">
+         <string notr="true">4:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="3">
+       <widget class="QPushButton" name="ircColor4Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="4">
+       <widget class="QLabel" name="label_23">
+        <property name="text">
+         <string notr="true">8:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="5">
+       <widget class="QPushButton" name="ircColor8Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="6">
+       <widget class="QLabel" name="label_27">
+        <property name="text">
+         <string notr="true">12:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="7">
+       <widget class="QPushButton" name="ircColor12Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="label_16">
+        <property name="text">
+         <string notr="true">1:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="QPushButton" name="ircColor1Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="2">
+       <widget class="QLabel" name="label_20">
+        <property name="text">
+         <string notr="true">5:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="3">
+       <widget class="QPushButton" name="ircColor5Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="4">
+       <widget class="QLabel" name="label_24">
+        <property name="text">
+         <string notr="true">9:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="5">
+       <widget class="QPushButton" name="ircColor9Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="6">
+       <widget class="QLabel" name="label_28">
+        <property name="text">
+         <string notr="true">13:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="7">
+       <widget class="QPushButton" name="ircColor13Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="0">
+       <widget class="QLabel" name="label_17">
+        <property name="text">
+         <string notr="true">2:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1">
+       <widget class="QPushButton" name="ircColor2Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="2">
+       <widget class="QLabel" name="label_21">
+        <property name="text">
+         <string notr="true">6:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="3">
+       <widget class="QPushButton" name="ircColor6Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="4">
+       <widget class="QLabel" name="label_25">
+        <property name="text">
+         <string notr="true">10:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="5">
+       <widget class="QPushButton" name="ircColor10Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="6">
+       <widget class="QLabel" name="label_29">
+        <property name="text">
+         <string notr="true">14:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="7">
+       <widget class="QPushButton" name="ircColor14Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="0">
+       <widget class="QLabel" name="label_18">
+        <property name="text">
+         <string notr="true">3:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="1">
+       <widget class="QPushButton" name="ircColor3Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="2">
+       <widget class="QLabel" name="label_22">
+        <property name="text">
+         <string notr="true">7:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="3">
+       <widget class="QPushButton" name="ircColor7Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="4">
+       <widget class="QLabel" name="label_26">
+        <property name="text">
+         <string notr="true">11:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="5">
+       <widget class="QPushButton" name="ircColor11Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="6">
+       <widget class="QLabel" name="label_30">
+        <property name="text">
+         <string notr="true">15:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="7">
+       <widget class="QPushButton" name="ircColor15Button">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
     <widget class="QGroupBox" name="notificationsGroup">
+     <property name="toolTip">
+      <string>Enable to show notifications</string>
+     </property>
      <property name="title">
       <string>Show Notifications</string>
      </property>
@@ -448,6 +738,23 @@
   <tabstop>joinButton</tabstop>
   <tabstop>leaveButton</tabstop>
   <tabstop>infoButton</tabstop>
+  <tabstop>textColoursGroup</tabstop>
+  <tabstop>ircColor0Button</tabstop>
+  <tabstop>ircColor1Button</tabstop>
+  <tabstop>ircColor2Button</tabstop>
+  <tabstop>ircColor3Button</tabstop>
+  <tabstop>ircColor4Button</tabstop>
+  <tabstop>ircColor5Button</tabstop>
+  <tabstop>ircColor6Button</tabstop>
+  <tabstop>ircColor7Button</tabstop>
+  <tabstop>ircColor8Button</tabstop>
+  <tabstop>ircColor9Button</tabstop>
+  <tabstop>ircColor10Button</tabstop>
+  <tabstop>ircColor11Button</tabstop>
+  <tabstop>ircColor12Button</tabstop>
+  <tabstop>ircColor13Button</tabstop>
+  <tabstop>ircColor14Button</tabstop>
+  <tabstop>ircColor15Button</tabstop>
   <tabstop>notificationsGroup</tabstop>
   <tabstop>joinLeaveCheckBox</tabstop>
   <tabstop>messageCheckBox</tabstop>
--- a/Preferences/__init__.py	Sun Nov 25 18:40:15 2012 +0100
+++ b/Preferences/__init__.py	Sun Nov 25 20:11:13 2012 +0100
@@ -931,6 +931,24 @@
         "LeaveChannelColour": "#B00000",
         "ChannelInfoColour": "#9E54B3",
         
+        "EnableIrcColours": True,
+        "IrcColor0": "#FFFF00",
+        "IrcColor1": "#000000",
+        "IrcColor2": "#000080",
+        "IrcColor3": "#008000",
+        "IrcColor4": "#FF0000",
+        "IrcColor5": "#A52A2A",
+        "IrcColor6": "#800080",
+        "IrcColor7": "#FF8000",
+        "IrcColor8": "#808000",
+        "IrcColor9": "#00FF00",
+        "IrcColor10": "#008080",
+        "IrcColor11": "#00FFFF",
+        "IrcColor12": "#0000FF",
+        "IrcColor13": "#FFC0CB",
+        "IrcColor14": "#A0A0A0",
+        "IrcColor15": "#C0C0C0",
+        
         "ShowNotifications": True,
         "NotifyJoinPart": True,
         "NotifyMessage": False,
@@ -2569,7 +2587,7 @@
     @return the requested user setting
     """
     if key in ["TimestampIncludeDate", "ShowTimestamps", "ShowNotifications",
-               "NotifyJoinPart", "NotifyMessage", "NotifyNick"]:
+               "NotifyJoinPart", "NotifyMessage", "NotifyNick", "EnableIrcColours"]:
         return toBool(prefClass.settings.value("IRC/" + key,
                 prefClass.ircDefaults[key]))
     else:
--- a/UI/UserInterface.py	Sun Nov 25 18:40:15 2012 +0100
+++ b/UI/UserInterface.py	Sun Nov 25 20:11:13 2012 +0100
@@ -5171,6 +5171,9 @@
             if not self.helpWindow.shutdown():
                 return False
         
+        if not self.irc.shutdown():
+            return False
+        
         self.__writeSession()
         
         if not self.project.closeProject():
@@ -5182,9 +5185,6 @@
         if not self.viewmanager.closeViewManager():
             return False
         
-        if not self.irc.shutdown():
-            return False
-        
         self.shell.closeShell()
         self.terminal.closeTerminal()
         

eric ide

mercurial