connectors/SchemeEditor.py
author Edouard Tisserant
Thu, 08 Nov 2018 14:33:35 +0100
changeset 2332 03a94f862465
parent 2329 e5703dc8848e
child 2334 d1470c052662
permissions -rw-r--r--
'Merged' URI editor dialog and Discovery dialog, also clean up related code
2329
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
     3
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
     4
# See COPYING file for copyrights details.
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
     5
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
     6
from __future__ import absolute_import
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
     7
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
     8
from itertools import repeat, izip_longest
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
     9
import wx
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    10
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    11
class SchemeEditor(wx.Panel):
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    12
    def __init__(self, scheme, parent, *args, **kwargs):
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    13
        self.txtctrls = {} 
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    14
        wx.Panel.__init__(self, parent, *args, **kwargs)
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    15
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    16
        self.mainSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=5, vgap=10)
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    17
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    18
        for tag, label in self.model:
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    19
            txtctrl = wx.TextCtrl(parent=self, size=wx.Size(200, -1))
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    20
            self.txtctrls[tag] = txtctrl
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    21
            for win, flag in [
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    22
                (wx.StaticText(self, label=label), wx.ALIGN_CENTER_VERTICAL),
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    23
                (txtctrl, wx.GROW)]:
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    24
                self.mainSizer.AddWindow(win, flag=flag)
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    25
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    26
        self.mainSizer.AddSpacer(20)
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    27
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    28
        self.SetSizer(self.mainSizer)
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    29
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    30
    def SetFields(self, fields):
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    31
        for tag, label in self.model:
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    32
            self.txtctrls[tag].SetValue(fields[tag])
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    33
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    34
    def GetFields(self):
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    35
        return {tag: self.txtctrls[tag].GetValue() for tag,label in self.model}
e5703dc8848e URI editor : Rewrote most of it, cleaner.
Edouard Tisserant
parents:
diff changeset
    36