kinsamanka@3750: andrej@2182: denis@2001: import wx Edouard@2329: from connectors import ConnectorSchemes, EditorClassFromScheme Edouard@2332: from controls.DiscoveryPanel import DiscoveryPanel denis@2001: edouard@2492: Edouard@2330: class UriEditor(wx.Dialog): denis@2001: def _init_ctrls(self, parent): Edouard@2332: self.UriTypeChoice = wx.Choice(parent=self, choices=self.choices) denis@2001: self.UriTypeChoice.SetSelection(0) denis@2001: self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.UriTypeChoice) Edouard@2329: self.editor_sizer = wx.BoxSizer(wx.HORIZONTAL) andrej@2182: self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL) denis@2001: denis@2001: def _init_sizers(self): denis@2001: self.mainSizer = wx.BoxSizer(wx.VERTICAL) denis@2001: typeSizer = wx.BoxSizer(wx.HORIZONTAL) Edouard@2331: typeSizer.Add(wx.StaticText(self, wx.ID_ANY, _("Scheme :")), border=5, edouard@2492: flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL) denis@2001: typeSizer.Add(self.UriTypeChoice, border=5, flag=wx.ALL) denis@2001: self.mainSizer.Add(typeSizer) denis@2001: Edouard@2329: self.mainSizer.Add(self.editor_sizer, border=5, flag=wx.ALL) Edouard@2331: self.mainSizer.Add(self.ButtonSizer, border=5, Edouard@2331: flag=wx.BOTTOM | wx.ALIGN_CENTER_HORIZONTAL) denis@2001: self.SetSizer(self.mainSizer) andrej@2176: self.Layout() andrej@2176: self.Fit() denis@2001: Edouard@2334: def __init__(self, parent, ctr, uri=''): Edouard@2334: self.ctr = ctr Edouard@2331: wx.Dialog.__init__(self, Edouard@2330: name='UriEditor', parent=parent, Edouard@2329: title=_('URI Editor')) Edouard@2332: self.choices = [_("- Search local network -")] + ConnectorSchemes() denis@2001: self._init_ctrls(parent) denis@2001: self._init_sizers() Edouard@2329: self.scheme = None Edouard@2329: self.scheme_editor = None denis@2001: self.SetURI(uri) denis@2001: self.CenterOnParent() denis@2001: edouard@3935: def Destroy(self): edouard@3935: self.scheme_editor.Destroy() edouard@3935: wx.Dialog.Destroy(self) edouard@3935: denis@2001: def OnTypeChoice(self, event): denis@2001: index = event.GetSelection() Edouard@2329: self._replaceSchemeEditor(event.GetString() if index > 0 else None) denis@2001: denis@2001: def SetURI(self, uri): Edouard@2329: try: edouard@2492: scheme, loc = uri.strip().split("://", 1) Edouard@2332: scheme = scheme.upper() edouard@2492: except Exception: Edouard@2332: scheme = None Edouard@2332: Edouard@2329: if scheme in ConnectorSchemes(): Edouard@2329: self.UriTypeChoice.SetStringSelection(scheme) Edouard@2332: else: Edouard@2332: self.UriTypeChoice.SetSelection(0) Edouard@2475: scheme = None Edouard@2332: Edouard@2332: self._replaceSchemeEditor(scheme) Edouard@2332: Edouard@2332: if scheme is not None: Edouard@2329: self.scheme_editor.SetLoc(loc) denis@2001: denis@2001: def GetURI(self): Edouard@2332: if self.scheme is None: Edouard@2332: return self.scheme_editor.GetURI() denis@2001: else: Edouard@2329: return self.scheme+"://"+self.scheme_editor.GetLoc() denis@2001: Edouard@2329: def _replaceSchemeEditor(self, scheme): Edouard@2329: self.scheme = scheme edouard@2492: Edouard@2329: if self.scheme_editor is not None: Edouard@2329: self.editor_sizer.Detach(self.scheme_editor) Edouard@2329: self.scheme_editor.Destroy() Edouard@2329: self.scheme_editor = None denis@2001: edouard@2492: if scheme is not None: Edouard@2332: EditorClass = EditorClassFromScheme(scheme) edouard@2492: self.scheme_editor = EditorClass(scheme, self) edouard@2492: else: Edouard@2332: # None is for searching local network edouard@2492: self.scheme_editor = DiscoveryPanel(self) Edouard@2332: Edouard@2332: self.editor_sizer.Add(self.scheme_editor) Edouard@2332: self.scheme_editor.Refresh() edouard@2492: Edouard@2329: self.editor_sizer.Layout() Edouard@2329: self.mainSizer.Layout() Edouard@2329: self.Fit()