Open links in browser

Julien LepillerSat Nov 14 15:03:12+0100 2020

d182529

Open links in browser

offlate/core/config.py

1919
    A configuration specification is a list of specifications.  This class
2020
    represents one such specification.
2121
    """
22-
    def __init__(self, key, name, description, optional):
22+
    def __init__(self, key, name, description, optional, link):
2323
        self.key = key
2424
        self.name = name
2525
        self.description = description
2626
        self.optional = optional
27+
        self.link = link
2728
2829
    def isConfigured(self, conf):
2930
        """

3839
    """
3940
    The specification of a string.
4041
    """
41-
    def __init__(self, key, name, description, placeholder='', optional=False):
42-
        ConfigSpec.__init__(self, key, name, description, optional)
42+
    def __init__(self, key, name, description, link=None, placeholder='', optional=False):
43+
        ConfigSpec.__init__(self, key, name, description, optional, link)
4344
        self.placeholder = placeholder
4445
4546
    def isConfigured(self, conf):

5152
    The specification of a list of configurations.
5253
    """
5354
    def __init__(self, key, name, description, specifications, indexKey,
54-
            hasRequiredRow, optional=False):
55-
        ConfigSpec.__init__(self, key, name, description, optional)
55+
            hasRequiredRow, link=None, optional=False):
56+
        ConfigSpec.__init__(self, key, name, description, optional, link)
5657
        self.specifications = specifications
5758
        self.indexKey = indexKey
5859
        self.hasRequiredRow = hasRequiredRow

offlate/systems/github.py

9797
    def getSystemConfigSpec():
9898
        specs = [StringConfigSpec('token', Project.tr('Token'),
9999
            Project.tr('You can get a token from <a href=\"#\">https://github.com/settings/tokens/new</a>. \
100-
You will need at least to grant the public_repo permission.'))]
100+
You will need at least to grant the public_repo permission.'),
101+
            link='https://github.com/settings/tokens/new')]
101102
        specs.extend(GitProject.getSystemConfigSpec())
102103
        return specs

offlate/systems/transifex.py

145145
    @staticmethod
146146
    def getSystemConfigSpec():
147147
        return [StringConfigSpec('token', Project.tr('Token'),
148-
            Project.tr('You can get a token from <a href=\"#\">https://www.transifex.com/user/settings/api/</a>'))]
148+
            Project.tr('You can get a token from <a href=\"#\">https://www.transifex.com/user/settings/api/</a>'),
149+
            link='https://www.transifex.com/user/settings/api/')]
149150
150151
    @staticmethod
151152
    def getProjectConfigSpec():

offlate/ui/settings.py

6161
            for s in spec:
6262
                label = QLabel(self.tr(s.description))
6363
                label.setWordWrap(True)
64+
                label.linkActivated.connect(self.linkOpener(s.link))
6465
                widget = None
6566
                if isinstance(s, StringConfigSpec):
6667
                    widget = SettingsLineEdit()

9596
9697
        tab.setCurrentIndex(self.system + 1)
9798
99+
    def linkOpener(self, url):
100+
        return lambda : self.openLink(url)
101+
102+
    def openLink(self, url):
103+
        print(url)
104+
        QDesktopServices().openUrl(QUrl(url));
105+
98106
    def update(self):
99107
        for system in systems:
100108
            name = system['name']