ExtensionIrc/ConfigurationPage/IrcPage.py

Fri, 18 Apr 2025 18:36:48 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 18 Apr 2025 18:36:48 +0200
changeset 2
5b635dc8895f
permissions
-rw-r--r--

Extracted the IRC widgets from eric-ide to provide them as a plug-in.

# -*- coding: utf-8 -*-

# Copyright (c) 2012 - 2025 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the IRC configuration page.
"""

from eric7.Preferences.ConfigurationPages.ConfigurationPageBase import (
    ConfigurationPageBase,
)

from .Ui_IrcPage import Ui_IrcPage


class IrcPage(ConfigurationPageBase, Ui_IrcPage):
    """
    Class implementing the IRC configuration page.
    """

    TimeFormats = ["hh:mm", "hh:mm:ss", "h:mm ap", "h:mm:ss ap"]
    DateFormats = [
        "yyyy-MM-dd",
        "dd.MM.yyyy",
        "MM/dd/yyyy",
        "yyyy MMM. dd",
        "dd MMM. yyyy",
        "MMM. dd, yyyy",
    ]

    def __init__(self, plugin):
        """
        Constructor

        @param plugin reference to the plugin object
        @type PluginPipxInterface
        """
        super().__init__()
        self.setupUi(self)
        self.setObjectName("IrcPage")

        self.__plugin = plugin

        self.timeFormatCombo.addItems(IrcPage.TimeFormats)
        self.dateFormatCombo.addItems(IrcPage.DateFormats)

        # set initial values
        # timestamps
        self.timestampGroup.setChecked(self.__plugin.getPreferences("ShowTimestamps"))
        self.showDateCheckBox.setChecked(
            self.__plugin.getPreferences("TimestampIncludeDate")
        )
        self.timeFormatCombo.setCurrentIndex(
            self.timeFormatCombo.findText(self.__plugin.getPreferences("TimeFormat"))
        )
        self.dateFormatCombo.setCurrentIndex(
            self.dateFormatCombo.findText(self.__plugin.getPreferences("DateFormat"))
        )

        # colours
        self.initColour(
            "NetworkMessageColour",
            self.networkButton,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "ServerMessageColour",
            self.serverButton,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "ErrorMessageColour",
            self.errorButton,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "TimestampColour",
            self.timestampButton,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "HyperlinkColour",
            self.hyperlinkButton,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "ChannelMessageColour",
            self.channelButton,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "OwnNickColour",
            self.ownNickButton,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "NickColour", self.nickButton, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "JoinChannelColour",
            self.joinButton,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "LeaveChannelColour",
            self.leaveButton,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "ChannelInfoColour",
            self.infoButton,
            self.__plugin.getPreferences,
            byName=True,
        )

        # notifications
        self.notificationsGroup.setChecked(
            self.__plugin.getPreferences("ShowNotifications")
        )
        self.joinLeaveCheckBox.setChecked(
            self.__plugin.getPreferences("NotifyJoinPart")
        )
        self.messageCheckBox.setChecked(self.__plugin.getPreferences("NotifyMessage"))
        self.ownNickCheckBox.setChecked(self.__plugin.getPreferences("NotifyNick"))

        # IRC text colors
        self.initColour(
            "IrcColor0", self.ircColor0Button, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "IrcColor1", self.ircColor1Button, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "IrcColor2", self.ircColor2Button, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "IrcColor3", self.ircColor3Button, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "IrcColor4", self.ircColor4Button, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "IrcColor5", self.ircColor5Button, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "IrcColor6", self.ircColor6Button, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "IrcColor7", self.ircColor7Button, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "IrcColor8", self.ircColor8Button, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "IrcColor9", self.ircColor9Button, self.__plugin.getPreferences, byName=True
        )
        self.initColour(
            "IrcColor10",
            self.ircColor10Button,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "IrcColor11",
            self.ircColor11Button,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "IrcColor12",
            self.ircColor12Button,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "IrcColor13",
            self.ircColor13Button,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "IrcColor14",
            self.ircColor14Button,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "IrcColor15",
            self.ircColor15Button,
            self.__plugin.getPreferences,
            byName=True,
        )

        # Automatic User Information Lookup
        self.whoGroup.setChecked(self.__plugin.getPreferences("AutoUserInfoLookup"))
        self.whoUsersSpinBox.setValue(self.__plugin.getPreferences("AutoUserInfoMax"))
        self.whoIntervalSpinBox.setValue(
            self.__plugin.getPreferences("AutoUserInfoInterval")
        )

        # Markers
        self.markWhenHiddenCheckBox.setChecked(
            self.__plugin.getPreferences("MarkPositionWhenHidden")
        )
        self.initColour(
            "MarkerLineForegroundColour",
            self.markerForegroundButton,
            self.__plugin.getPreferences,
            byName=True,
        )
        self.initColour(
            "MarkerLineBackgroundColour",
            self.markerBackgroundButton,
            self.__plugin.getPreferences,
            byName=True,
        )

    def save(self):
        """
        Public slot to save the IRC configuration.
        """
        # timestamps
        self.__plugin.setPreferences("ShowTimestamps", self.timestampGroup.isChecked())
        self.__plugin.setPreferences(
            "TimestampIncludeDate", self.showDateCheckBox.isChecked()
        )
        self.__plugin.setPreferences("TimeFormat", self.timeFormatCombo.currentText())
        self.__plugin.setPreferences("DateFormat", self.dateFormatCombo.currentText())

        # notifications
        self.__plugin.setPreferences(
            "ShowNotifications", self.notificationsGroup.isChecked()
        )
        self.__plugin.setPreferences(
            "NotifyJoinPart", self.joinLeaveCheckBox.isChecked()
        )
        self.__plugin.setPreferences("NotifyMessage", self.messageCheckBox.isChecked())
        self.__plugin.setPreferences("NotifyNick", self.ownNickCheckBox.isChecked())

        # Automatic User Information Lookup
        self.__plugin.setPreferences("AutoUserInfoLookup", self.whoGroup.isChecked())
        self.__plugin.setPreferences("AutoUserInfoMax", self.whoUsersSpinBox.value())
        self.__plugin.setPreferences(
            "AutoUserInfoInterval", self.whoIntervalSpinBox.value()
        )

        # Markers
        self.__plugin.setPreferences(
            "MarkPositionWhenHidden", self.markWhenHiddenCheckBox.isChecked()
        )

        # colours
        self.saveColours(self.__plugin.setPreferences)

eric ide

mercurial