dialogs/UriEditor.py
author Edouard Tisserant
Wed, 19 Dec 2018 10:53:19 +0100
changeset 2474 347b03f7e0e8
parent 2334 d1470c052662
child 2475 39ba6a125a97
permissions -rw-r--r--
Fixed runtime's reconnecting loop not stopping when re-configuring WAMP.
In case WAMP was already trying to connect without success and user change WAMP configuration through web interface, previous ReconnectingClient wasn't stopped.
2182
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2179
diff changeset
     1
from __future__ import absolute_import
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
2330
8c18b1a3e2bf URI Editor Dialog : moved it to /dialog, and fixed naming.
Edouard Tisserant
parents: 2329
diff changeset
     7
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
     8
    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
     9
        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
    10
        self.UriTypeChoice.SetSelection(0)
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    11
        self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.UriTypeChoice)
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    12
        self.editor_sizer = wx.BoxSizer(wx.HORIZONTAL)
2182
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2179
diff changeset
    13
        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
    14
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    15
    def _init_sizers(self):
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    16
        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
    17
        typeSizer = wx.BoxSizer(wx.HORIZONTAL)
2331
91ae5a11a462 Cut more useless code from URI Editor
Edouard Tisserant
parents: 2330
diff changeset
    18
        typeSizer.Add(wx.StaticText(self, wx.ID_ANY, _("Scheme :")), border=5,
91ae5a11a462 Cut more useless code from URI Editor
Edouard Tisserant
parents: 2330
diff changeset
    19
                                    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
    20
        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
    21
        self.mainSizer.Add(typeSizer)
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    22
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    23
        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
    24
        self.mainSizer.Add(self.ButtonSizer, border=5,
91ae5a11a462 Cut more useless code from URI Editor
Edouard Tisserant
parents: 2330
diff changeset
    25
                           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
    26
        self.SetSizer(self.mainSizer)
2176
748017ca4151 Autoresize UriLocationEditor dialog window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2007
diff changeset
    27
        self.Layout()
748017ca4151 Autoresize UriLocationEditor dialog window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2007
diff changeset
    28
        self.Fit()
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    29
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents: 2332
diff changeset
    30
    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
    31
        self.ctr = ctr
2331
91ae5a11a462 Cut more useless code from URI Editor
Edouard Tisserant
parents: 2330
diff changeset
    32
        wx.Dialog.__init__(self,
2330
8c18b1a3e2bf URI Editor Dialog : moved it to /dialog, and fixed naming.
Edouard Tisserant
parents: 2329
diff changeset
    33
                           name='UriEditor', parent=parent,
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    34
                           title=_('URI Editor'))
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    35
        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
    36
        self._init_ctrls(parent)
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    37
        self._init_sizers()
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    38
        self.scheme = None
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    39
        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
    40
        self.SetURI(uri)
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    41
        self.CenterOnParent()
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    42
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    43
    def OnTypeChoice(self, event):
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    44
        index = event.GetSelection()
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    45
        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
    46
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    47
    def SetURI(self, uri):
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    48
        try:
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    49
            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
    50
            scheme = scheme.upper()
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    51
        except:
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    52
            scheme = None
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    53
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    54
        if scheme in ConnectorSchemes():
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    55
            self.UriTypeChoice.SetStringSelection(scheme)
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    56
        else:
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    57
            self.UriTypeChoice.SetSelection(0)
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    58
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    59
        self._replaceSchemeEditor(scheme)
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    60
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    61
        if scheme is not None:
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    62
            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
    63
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    64
2001
bcbd41efd846 #2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    65
    def GetURI(self):
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    66
        if self.scheme is None:
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    67
            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
    68
        else:
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    69
            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
    70
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    71
    def _replaceSchemeEditor(self, scheme):
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    72
        self.scheme = scheme
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    73
       
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    74
        if self.scheme_editor is not None:
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    75
            self.editor_sizer.Detach(self.scheme_editor)
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    76
            self.scheme_editor.Destroy()
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    77
            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
    78
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    79
        if scheme is not None :
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    80
            EditorClass = EditorClassFromScheme(scheme)
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    81
            self.scheme_editor = EditorClass(scheme,self)
2332
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    82
        else :
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    83
            # None is for searching local network
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    84
            self.scheme_editor = DiscoveryPanel(self) 
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    85
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    86
        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
    87
        self.scheme_editor.Refresh()
03a94f862465 'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents: 2331
diff changeset
    88
            
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    89
        self.editor_sizer.Layout()
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    90
        self.mainSizer.Layout()
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    91
        self.Fit()
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents: 2182
diff changeset
    92