dialogs/UriEditor.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 14 May 2024 14:22:32 +0200
changeset 3941 09aa8a10026c
parent 3935 bc51b5a2daa9
permissions -rw-r--r--
ERPC: fix SetTraceVariablesList interface

This fix debug not suspending when having no variables, and other debug error being not reported.
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 2521
diff changeset
     1
2182
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2179
diff changeset
     2
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
     3
import wx
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
     4
from connectors import ConnectorSchemes, EditorClassFromScheme
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
     5
from controls.DiscoveryPanel import DiscoveryPanel
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
     6
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2475
diff changeset
     7
2330
8c18b1a3e2bf URI Editor Dialog : moved it to /dialog, and fixed naming.
Edouard Tisserant
parents: 2329
diff changeset
     8
class UriEditor(wx.Dialog):
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
     9
    def _init_ctrls(self, parent):
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    10
        self.UriTypeChoice = wx.Choice(parent=self, choices=self.choices)
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    11
        self.UriTypeChoice.SetSelection(0)
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    12
        self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.UriTypeChoice)
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    13
        self.editor_sizer = wx.BoxSizer(wx.HORIZONTAL)
2182
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2179
diff changeset
    14
        self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL)
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    15
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    16
    def _init_sizers(self):
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    17
        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    18
        typeSizer = wx.BoxSizer(wx.HORIZONTAL)
2331
91ae5a11a462 Cut more useless code from URI Editor
Edouard Tisserant
parents: 2330
diff changeset
    19
        typeSizer.Add(wx.StaticText(self, wx.ID_ANY, _("Scheme :")), border=5,
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2475
diff changeset
    20
                      flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    21
        typeSizer.Add(self.UriTypeChoice, border=5, flag=wx.ALL)
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    22
        self.mainSizer.Add(typeSizer)
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    23
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    24
        self.mainSizer.Add(self.editor_sizer, border=5, flag=wx.ALL)
2331
91ae5a11a462 Cut more useless code from URI Editor
Edouard Tisserant
parents: 2330
diff changeset
    25
        self.mainSizer.Add(self.ButtonSizer, border=5,
91ae5a11a462 Cut more useless code from URI Editor
Edouard Tisserant
parents: 2330
diff changeset
    26
                           flag=wx.BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    27
        self.SetSizer(self.mainSizer)
2176
748017ca4151 Autoresize UriLocationEditor dialog window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2007
diff changeset
    28
        self.Layout()
748017ca4151 Autoresize UriLocationEditor dialog window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2007
diff changeset
    29
        self.Fit()
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    30
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents: 2332
diff changeset
    31
    def __init__(self, parent, ctr, uri=''):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents: 2332
diff changeset
    32
        self.ctr = ctr
2331
91ae5a11a462 Cut more useless code from URI Editor
Edouard Tisserant
parents: 2330
diff changeset
    33
        wx.Dialog.__init__(self,
2330
8c18b1a3e2bf URI Editor Dialog : moved it to /dialog, and fixed naming.
Edouard Tisserant
parents: 2329
diff changeset
    34
                           name='UriEditor', parent=parent,
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    35
                           title=_('URI Editor'))
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    36
        self.choices = [_("- Search local network -")] + ConnectorSchemes()
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    37
        self._init_ctrls(parent)
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    38
        self._init_sizers()
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    39
        self.scheme = None
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    40
        self.scheme_editor = None
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    41
        self.SetURI(uri)
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    42
        self.CenterOnParent()
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    43
3935
bc51b5a2daa9 IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents: 3750
diff changeset
    44
    def Destroy(self):
bc51b5a2daa9 IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents: 3750
diff changeset
    45
        self.scheme_editor.Destroy()
bc51b5a2daa9 IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents: 3750
diff changeset
    46
        wx.Dialog.Destroy(self)
bc51b5a2daa9 IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents: 3750
diff changeset
    47
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    48
    def OnTypeChoice(self, event):
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    49
        index = event.GetSelection()
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    50
        self._replaceSchemeEditor(event.GetString() if index > 0 else None)
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    51
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    52
    def SetURI(self, uri):
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    53
        try:
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2475
diff changeset
    54
            scheme, loc = uri.strip().split("://", 1)
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    55
            scheme = scheme.upper()
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2475
diff changeset
    56
        except Exception:
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    57
            scheme = None
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    58
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    59
        if scheme in ConnectorSchemes():
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    60
            self.UriTypeChoice.SetStringSelection(scheme)
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    61
        else:
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    62
            self.UriTypeChoice.SetSelection(0)
2475
39ba6a125a97 Fix exception dialog with non recognized URI schemes
Edouard Tisserant
parents: 2334
diff changeset
    63
            scheme = None
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    64
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    65
        self._replaceSchemeEditor(scheme)
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    66
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    67
        if scheme is not None:
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    68
            self.scheme_editor.SetLoc(loc)
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    69
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    70
    def GetURI(self):
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    71
        if self.scheme is None:
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    72
            return self.scheme_editor.GetURI()
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    73
        else:
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    74
            return self.scheme+"://"+self.scheme_editor.GetLoc()
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    75
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    76
    def _replaceSchemeEditor(self, scheme):
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    77
        self.scheme = scheme
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2475
diff changeset
    78
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    79
        if self.scheme_editor is not None:
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    80
            self.editor_sizer.Detach(self.scheme_editor)
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    81
            self.scheme_editor.Destroy()
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    82
            self.scheme_editor = None
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    83
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2475
diff changeset
    84
        if scheme is not None:
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    85
            EditorClass = EditorClassFromScheme(scheme)
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2475
diff changeset
    86
            self.scheme_editor = EditorClass(scheme, self)
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2475
diff changeset
    87
        else:
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    88
            # None is for searching local network
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2475
diff changeset
    89
            self.scheme_editor = DiscoveryPanel(self)
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    90
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    91
        self.editor_sizer.Add(self.scheme_editor)
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    92
        self.scheme_editor.Refresh()
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2475
diff changeset
    93
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    94
        self.editor_sizer.Layout()
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    95
        self.mainSizer.Layout()
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    96
        self.Fit()