dialogs/UriEditor.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sun, 07 Apr 2019 21:08:07 +0200
changeset 2579 8fb5c6eddc72
parent 2521 48ebcbe7f19b
child 3750 f62625418bff
permissions -rw-r--r--
Conform to pep8 and pylint :

pep8 version: 2.3.1
./ConfigTreeNode.py:130:49: E231 missing whitespace after ','
./editors/Viewer.py:643:24: E128 continuation line under-indented for visual indent
./editors/Viewer.py:670:12: E221 multiple spaces before operator
./editors/Viewer.py:671:13: E221 multiple spaces before operator
./editors/Viewer.py:2138:52: E203 whitespace before ':'
./editors/Viewer.py:2139:66: W291 trailing whitespace
./controls/VariablePanel.py:154:25: E231 missing whitespace after ','
./controls/LocationCellEditor.py:88:1: W293 blank line contains whitespace
./controls/LocationCellEditor.py:191:25: E221 multiple spaces before operator
./controls/LocationCellEditor.py:200:17: E128 continuation line under-indented for visual indent

pylint 1.8.3,
************* Module controls.LocationCellEditor
controls/LocationCellEditor.py:200: [C0330(bad-continuation), ] Wrong continued indentation (add 9 spaces).
_("Selected location is identical to previous one"))
^ |
************* Module controls.VariablePanel
controls/VariablePanel.py:154: [E1601(print-statement), VariableTable.SetValue] print statement used
************* Module editors.Viewer
editors/Viewer.py:643: [C0330(bad-continuation), ] Wrong continued indentation (add 1 space).
self.GetAddMenuCallBack(self.AddNewComment))
^|
editors/Viewer.py:598: [W0612(unused-variable), Viewer.AddDivergenceMenuItems] Unused variable 'add_branch'
editors/Viewer.py:1655: [E0602(undefined-variable), Viewer.PopupConnectionMenu] Undefined variable 'variable_type'
editors/Viewer.py:1649: [W0612(unused-variable), Viewer.PopupConnectionMenu] Unused variable 'connection_type'
************* Module connectors.PYRO.PSK_Adapter
from __future__ import absolute_import

import wx
from connectors import ConnectorSchemes, EditorClassFromScheme
from controls.DiscoveryPanel import DiscoveryPanel


class UriEditor(wx.Dialog):
    def _init_ctrls(self, parent):
        self.UriTypeChoice = wx.Choice(parent=self, choices=self.choices)
        self.UriTypeChoice.SetSelection(0)
        self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.UriTypeChoice)
        self.editor_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL)

    def _init_sizers(self):
        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
        typeSizer = wx.BoxSizer(wx.HORIZONTAL)
        typeSizer.Add(wx.StaticText(self, wx.ID_ANY, _("Scheme :")), border=5,
                      flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
        typeSizer.Add(self.UriTypeChoice, border=5, flag=wx.ALL)
        self.mainSizer.Add(typeSizer)

        self.mainSizer.Add(self.editor_sizer, border=5, flag=wx.ALL)
        self.mainSizer.Add(self.ButtonSizer, border=5,
                           flag=wx.BOTTOM | wx.ALIGN_CENTER_HORIZONTAL)
        self.SetSizer(self.mainSizer)
        self.Layout()
        self.Fit()

    def __init__(self, parent, ctr, uri=''):
        self.ctr = ctr
        wx.Dialog.__init__(self,
                           name='UriEditor', parent=parent,
                           title=_('URI Editor'))
        self.choices = [_("- Search local network -")] + ConnectorSchemes()
        self._init_ctrls(parent)
        self._init_sizers()
        self.scheme = None
        self.scheme_editor = None
        self.SetURI(uri)
        self.CenterOnParent()

    def OnTypeChoice(self, event):
        index = event.GetSelection()
        self._replaceSchemeEditor(event.GetString() if index > 0 else None)

    def SetURI(self, uri):
        try:
            scheme, loc = uri.strip().split("://", 1)
            scheme = scheme.upper()
        except Exception:
            scheme = None

        if scheme in ConnectorSchemes():
            self.UriTypeChoice.SetStringSelection(scheme)
        else:
            self.UriTypeChoice.SetSelection(0)
            scheme = None

        self._replaceSchemeEditor(scheme)

        if scheme is not None:
            self.scheme_editor.SetLoc(loc)

    def GetURI(self):
        if self.scheme is None:
            return self.scheme_editor.GetURI()
        else:
            return self.scheme+"://"+self.scheme_editor.GetLoc()

    def _replaceSchemeEditor(self, scheme):
        self.scheme = scheme

        if self.scheme_editor is not None:
            self.editor_sizer.Detach(self.scheme_editor)
            self.scheme_editor.Destroy()
            self.scheme_editor = None

        if scheme is not None:
            EditorClass = EditorClassFromScheme(scheme)
            self.scheme_editor = EditorClass(scheme, self)
        else:
            # None is for searching local network
            self.scheme_editor = DiscoveryPanel(self)

        self.editor_sizer.Add(self.scheme_editor)
        self.scheme_editor.Refresh()

        self.editor_sizer.Layout()
        self.mainSizer.Layout()
        self.Fit()