コード例 #1
0
    def Configure(self, Prefix="Remote", remotes=[], suffixes=None):
        egEventInit = eg.EventGhostEvent.__init__

        text = self.text
        self.remotes = cpy(remotes)
        del remotes
        panel = eg.ConfigPanel(self, resizable=True)
        if not suffixes:
            from eg.Classes.IrDecoder.Rc6 import MCE_REMOTE as MCE
            suffixes = list(MCE.itervalues())
        panel.suffixes = suffixes

        def TestUse(val):
            rem = None
            for item in self.remotes:
                for button in item[2]:
                    if button[2] == val:
                        rem = item[0]
                        break
                if rem:
                    break
            return rem

        panel.testUse = TestUse

        leftSizer = wx.BoxSizer(wx.VERTICAL)
        box1 = wx.StaticBox(panel, -1, "")
        eventSizer = wx.StaticBoxSizer(box1, wx.VERTICAL)
        prefLabel = wx.StaticText(panel, -1, text.prefix)
        prefText = wx.TextCtrl(panel, -1, Prefix)
        prefLabel2 = wx.StaticText(panel, -1, text.nativePrefix)
        prefText2 = wx.TextCtrl(panel, -1, "")
        buttonsListCtrl = wx.ListCtrl(panel,
                                      -1,
                                      style=wx.LC_REPORT | wx.VSCROLL
                                      | wx.LC_VRULES | wx.LC_HRULES
                                      | wx.LC_SINGLE_SEL)
        self.back = buttonsListCtrl.GetBackgroundColour()
        self.fore = buttonsListCtrl.GetForegroundColour()
        self.selBack = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
        self.selFore = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
        suffText = wx.TextCtrl(panel, -1, "", style=wx.TE_READONLY)
        suffText.SetToolTipString(text.suffToolTip)
        labelText = wx.TextCtrl(panel, -1, "")
        suffChoice = wx.Choice(panel, -1, choices=panel.suffixes)

        def UpdateChoices():
            suffChoice.Clear()
            suffChoice.AppendItems(panel.suffixes)

        panel.updateChoices = UpdateChoices

        evtPrefSizer = wx.BoxSizer(wx.HORIZONTAL)
        evtPrefSizer.Add(prefLabel, 0, wx.TOP, 3)
        evtPrefSizer.Add(prefText, 1, wx.EXPAND | wx.LEFT, 5)
        eventSizer.Add(evtPrefSizer, 0, wx.EXPAND | wx.TOP, 4)
        suffButton = wx.Button(panel, -1, text.suffixes)
        eventSizer.Add(suffButton, 0, wx.EXPAND | wx.TOP, 8)
        remListSizer = wx.GridBagSizer(1, 10)
        box2 = wx.StaticBox(panel, -1, "")
        rightStatSizer = wx.StaticBoxSizer(box2, wx.VERTICAL)
        rightSizer = wx.GridBagSizer(8, 1)
        rightStatSizer.Add(rightSizer, 1, wx.EXPAND)
        remListLabel = wx.StaticText(panel, -1, text.menuPreview)
        listBoxCtrl = wx.ListBox(panel,
                                 -1,
                                 style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
        labelLbl = wx.StaticText(panel, -1, text.label)
        labelCtrl = wx.TextCtrl(panel, -1, '')
        #Buttons 'Delete', 'Import', 'Export' and 'Insert new'
        lenLst = [panel.GetTextExtent(item)[0] for item in text.buttons]
        btn = wx.Button(panel, -1, text.buttons[lenLst.index(max(lenLst))])
        sz = btn.GetSize()
        btn.Destroy()
        btnDEL = wx.Button(panel, -1, text.buttons[0], size=sz)
        btnApp = wx.Button(panel, -1, text.buttons[1], size=sz)
        btnImp = wx.Button(panel, -1, text.buttons[2], size=sz)
        btnExp = wx.Button(panel, -1, text.buttons[3], size=sz)

        def EnableBtns(enable):
            btnDEL.Enable(enable)
            btnImp.Enable(enable)
            btnExp.Enable(enable)

        def EnableLabel(enable):
            labelCtrl.Enable(enable)
            labelLbl.Enable(enable)

        EnableBtns(False)
        EnableLabel(False)
        lenLst = [panel.GetTextExtent(item)[0] for item in text.buttons2]
        btn = wx.Button(panel, -1, text.buttons2[lenLst.index(max(lenLst))])
        sz = btn.GetSize()
        btn.Destroy()
        delEvent = wx.Button(panel, -1, text.buttons2[0], size=sz)
        clearEvents = wx.Button(panel, -1, text.buttons2[1], size=sz)
        addEvent = wx.Button(panel, -1, text.buttons2[2], size=sz)
        duplEvent = wx.Button(panel, -1, text.buttons2[3], size=sz)

        #Button UP
        bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_UP, wx.ART_OTHER, (16, 16))
        btnUP = wx.BitmapButton(panel, -1, bmp)
        btnUP.Enable(False)
        #Button DOWN
        bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_DOWN, wx.ART_OTHER, (16, 16))
        btnDOWN = wx.BitmapButton(panel, -1, bmp)
        btnDOWN.Enable(False)

        leftSizer.Add(eventSizer, 0, wx.EXPAND)
        leftSizer.Add(remListSizer, 1, wx.EXPAND | wx.TOP, 15)
        leftSizer.Add((1, 4))
        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        mainSizer.Add(leftSizer, 0, wx.EXPAND)
        mainSizer.Add(rightStatSizer, 1, wx.LEFT | wx.EXPAND, 24)
        panel.sizer.Add(mainSizer, 1, wx.EXPAND)

        def EnableCtrls(enable):
            suffText.Enable(enable)
            labelText.Enable(enable)
            suffChoice.Enable(enable)
            if enable:
                eg.EventGhostEvent.__init__ = EventRemap
            else:
                eg.EventGhostEvent.__init__ = egEventInit

        def ResetCtrls():
            suffText.ChangeValue("")
            labelText.ChangeValue("")
            suffChoice.SetSelection(-1)

        def FillButtonsList(item):
            buttonsListCtrl.DeleteAllItems()
            for row in range(len(item[2])):
                buttonsListCtrl.InsertStringItem(row, item[2][row][0])
                buttonsListCtrl.SetStringItem(row, 1, item[2][row][1])
                buttonsListCtrl.SetStringItem(row, 2, item[2][row][2])

        def FillRemoteForm(item):
            self.oldSel = -1
            prefText2.SetValue(item[1])
            enable = item[1] != ""
            addEvent.Enable(enable)
            ResetCtrls()
            FillButtonsList(item)
            clearEvents.Enable(len(item[2]) > 0)
            EnableButtonsRight(False)
            duplEvent.Enable(False)
            EnableCtrls(False)

        evtPrefSizer2 = wx.BoxSizer(wx.HORIZONTAL)
        evtPrefSizer2.Add((-1, 1), 1, wx.EXPAND)
        evtPrefSizer2.Add(prefLabel2, 0, wx.TOP, 3)
        evtPrefSizer2.Add(prefText2, 0, wx.LEFT, 5)
        w = 0
        for i, colLabel in enumerate(text.header):
            buttonsListCtrl.InsertColumn(i, colLabel)
            buttonsListCtrl.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER)
            w += buttonsListCtrl.GetColumnWidth(i)
        buttonsListCtrl.SetSize(
            (w + SYS_VSCROLL_X + buttonsListCtrl.GetWindowBorderSize()[0], -1))
        w0 = buttonsListCtrl.GetColumnWidth(0)
        w1 = buttonsListCtrl.GetColumnWidth(1)
        w2 = buttonsListCtrl.GetColumnWidth(2)
        suffText.SetMinSize((w0 - 1, -1))
        labelText.SetMinSize((w1 - 1, -1))
        suffChoice.SetMinSize((w2 - 1, -1))
        rightSizer.Add(evtPrefSizer2, (0, 0), (1, 4),
                       flag=wx.EXPAND | wx.TOP,
                       border=4)
        rightSizer.Add(buttonsListCtrl, (1, 0), (5, 4), flag=wx.EXPAND)
        rightSizer.Add(delEvent, (1, 4),
                       flag=wx.TOP | wx.ALIGN_RIGHT,
                       border=24)
        rightSizer.Add(clearEvents, (2, 4), flag=wx.ALIGN_RIGHT)
        brdr = 8 + SYS_VSCROLL_X + buttonsListCtrl.GetWindowBorderSize()[0]
        rightSizer.Add(btnUP, (3, 4), flag=wx.LEFT, border=brdr)
        rightSizer.Add(btnDOWN, (4, 4), flag=wx.LEFT, border=brdr)
        rightSizer.Add(duplEvent, (5, 4),
                       flag=wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT)
        rightSizer.Add(suffText, (6, 0), flag=wx.EXPAND | wx.LEFT, border=1)
        rightSizer.Add(labelText, (6, 1), flag=wx.EXPAND | wx.LEFT, border=1)
        rightSizer.Add(suffChoice, (6, 2), flag=wx.EXPAND | wx.LEFT, border=1)
        rightSizer.Add(addEvent, (6, 4), flag=wx.LEFT, border=brdr)
        rightSizer.AddGrowableRow(5)
        rightSizer.AddGrowableCol(0, w0)
        rightSizer.AddGrowableCol(1, w1)
        rightSizer.AddGrowableCol(2, w2)
        remListSizer.Add(remListLabel, (0, 0))
        remListSizer.Add(listBoxCtrl, (1, 0), (4, 1), flag=wx.EXPAND)
        remListSizer.Add(labelLbl, (5, 0), flag=wx.TOP, border=8)
        remListSizer.Add(labelCtrl, (6, 0), flag=wx.EXPAND)
        remListSizer.Add(btnDEL, (1, 1))
        remListSizer.Add(btnImp, (2, 1), flag=wx.TOP, border=8)
        remListSizer.Add(btnExp, (3, 1), flag=wx.TOP, border=8)
        remListSizer.Add((-1, 1), (4, 1))
        remListSizer.Add(btnApp, (6, 1))
        remListSizer.AddGrowableRow(4)
        panel.sizer.Layout()

        def EnableLeftSide(enable):
            EnableBtns(enable)
            EnableLabel(enable)
            btnApp.Enable(enable)
            remListLabel.Enable(enable)
            listBoxCtrl.Enable(enable)
            labelLbl.Enable(enable)
            labelCtrl.Enable(enable)

        def SetWidth():
            w0 = suffText.GetSize()[0] + 1
            w1 = labelText.GetSize()[0] + 1
            w2 = suffChoice.GetSize()[0] + 1
            buttonsListCtrl.SetSize(
                (w0 + w1 + w2 + SYS_VSCROLL_X +
                 buttonsListCtrl.GetWindowBorderSize()[0], -1))
            buttonsListCtrl.SetColumnWidth(0, w0)
            buttonsListCtrl.SetColumnWidth(1, w1)
            buttonsListCtrl.SetColumnWidth(2, w2)

        def OnSize(event):
            wx.CallAfter(SetWidth)
            panel.Update()
            event.Skip()

        panel.Bind(wx.EVT_SIZE, OnSize)

        def OnDelEvent(evt):
            rem = listBoxCtrl.GetSelection()
            self.remotes[rem][2].pop(self.oldSel)
            buttonsListCtrl.DeleteItem(self.oldSel)
            lngth = len(self.remotes[rem][2])
            prefText2.Enable(True)
            if lngth == 0:
                self.oldSel = -1
                OnPrefText2()
                ResetCtrls()
                evt.Skip()
                return
            elif self.oldSel == lngth:
                row = lngth - 1
            else:
                row = self.oldSel
            self.oldSel = -1
            SelRow(row)
            suffText.ChangeValue(buttonsListCtrl.GetItemText(row))
            labelText.ChangeValue(buttonsListCtrl.GetItem(row, 1).GetText())
            suffChoice.SetStringSelection(
                buttonsListCtrl.GetItem(row, 2).GetText())
            OnPrefText2()
            Validation()
            evt.Skip()

        delEvent.Bind(wx.EVT_BUTTON, OnDelEvent)

        def OnClearEvents(evt):
            rem = listBoxCtrl.GetSelection()
            self.remotes[rem][2] = []
            buttonsListCtrl.DeleteAllItems()
            self.oldSel = -1
            EnableLeftSide(True)
            prefText2.Enable(True)
            OnPrefText2()
            ResetCtrls()
            evt.Skip()

        clearEvents.Bind(wx.EVT_BUTTON, OnClearEvents)

        def onButtonDelete(evt):
            sel = listBoxCtrl.GetSelection()
            listBoxCtrl.Delete(sel)
            self.remotes.pop(sel)
            lngth = len(self.remotes)
            if lngth > 0:
                if sel == lngth:
                    sel = lngth - 1
                listBoxCtrl.SetSelection(sel)
                onClick()
            else:
                labelCtrl.ChangeValue("")
                EnableBtns(False)
                item = ["", "", []]
                FillRemoteForm(item)
            evt.Skip()

        btnDEL.Bind(wx.EVT_BUTTON, onButtonDelete)

        def OnLabelChange(evt):
            flag = False
            sel = listBoxCtrl.GetSelection()
            label = labelCtrl.GetValue()
            self.remotes[sel][0] = label
            listBoxCtrl.SetString(sel, label)
            enable = label != ""
            if enable:
                if [n[0] for n in self.remotes].count(label) == 1:
                    flag = True
            EnableBtns(enable)
            panel.dialog.buttonRow.okButton.Enable(flag)
            btnApp.Enable(flag)
            item = self.remotes[sel]
            prefText2.Enable(flag)
            OnPrefText2()
            if not flag:
                addEvent.Enable(False)
            evt.Skip()

        labelCtrl.Bind(wx.EVT_TEXT, OnLabelChange)

        def OnButtonAppend(evt):
            EnableLabel(True)
            item = ["", "", []]
            self.remotes.append(item)
            listBoxCtrl.Append("")
            listBoxCtrl.SetSelection(listBoxCtrl.GetCount() - 1)
            prefText2.ChangeValue("")
            labelCtrl.SetValue("")
            FillRemoteForm(item)
            labelCtrl.SetFocus()
            addEvent.Enable(False)
            evt.Skip()

        btnApp.Bind(wx.EVT_BUTTON, OnButtonAppend)

        def EnableButtonsRight(enable):
            delEvent.Enable(enable)
            if enable:
                rem = listBoxCtrl.GetSelection()
                if len(self.remotes[rem][2]) < 2:
                    enable = False
            btnUP.Enable(enable)
            btnDOWN.Enable(enable)

        def OnPrefText2(evt=None):
            global prefix
            prefix = prefText2.GetValue()
            rem = listBoxCtrl.GetSelection()
            if rem > -1:
                self.remotes[rem][1] = prefix
                s = None
                if prefix != "":
                    #Conflict test:
                    for i in range(len(self.remotes)):
                        rmt = self.remotes[i]
                        if prefix != rmt[1] or i == rem:
                            continue
                        for suff in self.remotes[rem][2]:
                            for sf in rmt[2]:
                                if suff[0] == sf[0] and suff[2] != sf[2]:
                                    s = suff[0]
                                    n = rmt[0]
                                    n0 = suff[2]
                                    n1 = sf[2]
                                    break
                            if s:
                                break
                        if s:
                            break
                    if s:
                        MessageBox(
                            panel,
                            text.message4 % (prefix, prefix, s, n0, n, n1),
                            text.messBoxTit2,
                            wx.ICON_EXCLAMATION,
                            plugin=self,
                        )
                        EnableLeftSide(False)
                        panel.dialog.buttonRow.okButton.Enable(False)
                    else:
                        EnableLeftSide(True)
                        panel.dialog.buttonRow.okButton.Enable(True)
                enable = prefix != "" and not s
                buttonsListCtrl.Enable(enable)
                if not enable or len(self.remotes[rem][2]) == 0:
                    addEvent.Enable(False)
                    duplEvent.Enable(False)
                    EnableButtonsRight(False)
                    clearEvents.Enable(False)
                    EnableCtrls(False)
                elif enable and len(self.remotes[rem][2]) > 0:
                    clearEvents.Enable(True)
                    if self.oldSel != -1:
                        EnableButtonsRight(True)
                        duplEvent.Enable(True)
                        EnableCtrls(True)
                    else:
                        EnableButtonsRight(False)
                        duplEvent.Enable(False)
                        EnableCtrls(False)
                if enable and len(self.remotes[rem][2]) == 0:
                    addEvent.Enable(True)
                if evt:
                    evt.Skip()

        prefText2.Bind(wx.EVT_TEXT, OnPrefText2)

        def Validation():
            flag = True
            strng = suffText.GetValue()
            prfx = prefText2.GetValue()
            rem = listBoxCtrl.GetSelection()
            newSuff = suffChoice.GetStringSelection()
            name = None
            sfx = None
            for i in range(len(self.remotes)):
                item = self.remotes[i]
                if i == rem or item[1] != prfx:
                    continue
                for suff in item[2]:
                    if suff[0] == strng and suff[2] != newSuff:
                        name = item[0]
                        sfx = suff[2]
                        break
                if name:
                    break
            if name:
                MessageBox(
                    panel,
                    text.message2 % (prfx, strng, newSuff, sfx, name),
                    text.messBoxTit2,
                    wx.ICON_EXCLAMATION,
                    plugin=self,
                )
                flag = False
            if [item[0] for item in self.remotes[rem][2]].count(strng) > 1:
                suffText.SetValue("")
                MessageBox(panel,
                           text.message6 % (strng),
                           text.messBoxTit3,
                           wx.ICON_EXCLAMATION,
                           plugin=self,
                           time=7)
            if strng == "":
                flag = False
            if labelText.GetValue().strip() == "":
                flag = False
            if suffChoice.GetSelection() == -1:
                flag = False
            addEvent.Enable(flag)
            duplEvent.Enable(flag)
            prefText2.Enable(flag)
            EnableLeftSide(flag)
            panel.dialog.buttonRow.okButton.Enable(flag)

        def EventRemap(self,
                       suffix="",
                       payload=None,
                       prefix="Main",
                       source=eg):
            SetSuffix(prefix, suffix)
            self.string = "%s.%s" % (prefix, suffix)
            self.prefix = prefix
            self.suffix = suffix
            self.payload = payload
            self.source = source
            self.time = clock()
            self.isEnded = False
            self.shouldEnd = Event()
            self.upFuncList = []

        def SetSuffix(eventPrefix, eventSuffix):
            if prefix == eventPrefix:
                suffText.SetValue(eventSuffix)

        def OnButtonAddEvent(evt):
            if self.oldSel == -1:
                self.oldSel = buttonsListCtrl.GetItemCount() - 1
            row = self.oldSel + 1
            self.remotes[listBoxCtrl.GetSelection()][2].insert(
                row, ["", "", ""])
            buttonsListCtrl.InsertStringItem(row, "")
            buttonsListCtrl.SetStringItem(row, 1, "")
            buttonsListCtrl.SetStringItem(row, 2, "")
            buttonsListCtrl.EnsureVisible(row)
            SelRow(row)
            EnableCtrls(True)
            addEvent.Enable(False)
            duplEvent.Enable(False)
            clearEvents.Enable(True)
            prefText2.Enable(False)
            EnableLeftSide(False)
            panel.dialog.buttonRow.okButton.Enable(False)
            ResetCtrls()
            EnableButtonsRight(True)
            evt.Skip()

        addEvent.Bind(wx.EVT_BUTTON, OnButtonAddEvent)

        def OnButtonDuplEvent(evt):
            addEvent.Enable(False)
            duplEvent.Enable(False)
            panel.dialog.buttonRow.okButton.Enable(False)
            suffText.ChangeValue("")
            strng1 = labelText.GetValue()
            strng2 = suffChoice.GetStringSelection()
            row = self.oldSel + 1
            self.remotes[listBoxCtrl.GetSelection()][2].insert(
                row, ["", strng1, strng2])
            buttonsListCtrl.InsertStringItem(row, "")
            buttonsListCtrl.SetStringItem(row, 1, strng1)
            buttonsListCtrl.SetStringItem(row, 2, strng2)
            SelRow(row)
            buttonsListCtrl.EnsureVisible(row)
            evt.Skip()

        duplEvent.Bind(wx.EVT_BUTTON, OnButtonDuplEvent)

        def OnSuffText(evt):
            strng = evt.GetString()
            self.remotes[listBoxCtrl.GetSelection()][2][self.oldSel][0] = strng
            buttonsListCtrl.SetStringItem(self.oldSel, 0, strng)
            Validation()
            evt.Skip()

        suffText.Bind(wx.EVT_TEXT, OnSuffText)

        def OnLabelText(evt):
            strng = labelText.GetValue()
            self.remotes[listBoxCtrl.GetSelection()][2][self.oldSel][1] = strng
            buttonsListCtrl.SetStringItem(self.oldSel, 1, strng)
            Validation()
            evt.Skip()

        labelText.Bind(wx.EVT_TEXT, OnLabelText)

        def OnSuffChoice(evt):
            strng = suffChoice.GetStringSelection()
            self.remotes[listBoxCtrl.GetSelection()][2][self.oldSel][2] = strng
            buttonsListCtrl.SetStringItem(self.oldSel, 2, strng)
            duplEvent.Enable(True)
            Validation()
            evt.Skip()

        suffChoice.Bind(wx.EVT_CHOICE, OnSuffChoice)

        def SelRow(row):
            if row != self.oldSel:
                if self.oldSel in range(buttonsListCtrl.GetItemCount()):
                    item = buttonsListCtrl.GetItem(self.oldSel)
                    item.SetTextColour(self.fore)
                    item.SetBackgroundColour(self.back)
                    buttonsListCtrl.SetItem(item)
                self.oldSel = row
            if buttonsListCtrl.GetItemBackgroundColour(row) != self.selBack:
                item = buttonsListCtrl.GetItem(row)
                item.SetTextColour(self.selFore)
                item.SetBackgroundColour(self.selBack)
                buttonsListCtrl.SetItem(item)

        def OnSuffixSelect(evt):
            row = evt.GetIndex()
            buttonsListCtrl.SetItemState(row, 0, wx.LIST_STATE_SELECTED)
            if row == self.oldSel:
                evt.Skip()
                return
            if not addEvent.IsEnabled() and self.oldSel > -1:
                old = self.oldSel
                self.oldSel = row
                SelRow(old)
                PlaySound('SystemExclamation', SND_ASYNC)
                evt.Skip()
                return
            EnableCtrls(True)
            SelRow(row)
            duplEvent.Enable(True)
            EnableButtonsRight(True)
            suffText.ChangeValue(buttonsListCtrl.GetItemText(row))
            labelText.ChangeValue(buttonsListCtrl.GetItem(row, 1).GetText())
            suffChoice.SetStringSelection(
                buttonsListCtrl.GetItem(row, 2).GetText())
            evt.Skip()

        buttonsListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, OnSuffixSelect)

        def OnBtnExp(evt):
            ix = listBoxCtrl.GetSelection()
            name = self.remotes[ix][0]
            dlg = wx.FileDialog(panel,
                                message=text.save % name,
                                defaultDir=eg.configDir,
                                defaultFile=name,
                                wildcard=text.wildcard,
                                style=wx.SAVE)
            if dlg.ShowModal() == wx.ID_OK:
                self.dataToXml(self.remotes[ix], dlg.GetPath())
            dlg.Destroy()
            evt.Skip()

        btnExp.Bind(wx.EVT_BUTTON, OnBtnExp)

        def OnBtnImp(evt):
            ix = listBoxCtrl.GetSelection()
            dlg = wx.FileDialog(panel,
                                message=text.choose % self.remotes[ix][0],
                                defaultDir=eg.configDir,
                                defaultFile="",
                                wildcard=text.wildcard,
                                style=wx.OPEN | wx.CHANGE_DIR)
            if dlg.ShowModal() == wx.ID_OK:
                filePath = dlg.GetPath()
                item = self.xmlToData(filePath)
                dlg.Destroy()
            else:
                dlg.Destroy()
                evt.Skip()
                return
            if not item:
                MessageBox(
                    panel,
                    text.message5 % path.split(dlg.GetPath())[1],
                    text.messBoxTit1,
                    wx.ICON_EXCLAMATION,
                    plugin=self,
                )
                evt.Skip()
                return
            #Conflict test:
            s = None
            for i in range(len(self.remotes)):
                rem = self.remotes[i]
                if item[1] != rem[1] or i == ix:
                    continue
                for suff in item[2]:
                    for sf in rem[2]:
                        if suff[0] == sf[0] and suff[2] != sf[2]:
                            s = suff[0]
                            n = rem[0]
                            n0 = suff[2]
                            n1 = sf[2]
                            break
                    if s:
                        break
                if s:
                    break
            if s:
                MessageBox(
                    panel,
                    text.message3 % (item[1], s, n0, n, n1),
                    text.messBoxTit2,
                    wx.ICON_EXCLAMATION,
                    plugin=self,
                )
                evt.Skip()
                return
            else:
                for suff in item[2]:
                    if suff[2] not in panel.suffixes:
                        panel.suffixes.append(suff[2])
                item[0] = self.remotes[ix][0]
                self.remotes[ix] = item
                FillRemoteForm(item)
            evt.Skip()

        btnImp.Bind(wx.EVT_BUTTON, OnBtnImp)

        def OnSuffButton(evt):
            dlg = SuffixesFrame(
                parent=panel,
                plugin=self,
            )
            dlg.Centre()
            wx.CallAfter(dlg.ShowSuffixesFrame)
            evt.Skip()

        suffButton.Bind(wx.EVT_BUTTON, OnSuffButton)

        def onButtonUp(evt):
            rem = listBoxCtrl.GetSelection()
            newSel, suffixes = Move(self.remotes[rem][2], self.oldSel, -1)
            self.remotes[rem][2] = suffixes
            FillButtonsList(self.remotes[rem])
            SelRow(newSel)
            buttonsListCtrl.EnsureVisible(self.oldSel)
            evt.Skip()

        btnUP.Bind(wx.EVT_BUTTON, onButtonUp)

        def onButtonDown(evt):
            rem = listBoxCtrl.GetSelection()
            newSel, suffixes = Move(self.remotes[rem][2], self.oldSel, 1)
            self.remotes[rem][2] = suffixes
            FillButtonsList(self.remotes[rem])
            SelRow(newSel)
            buttonsListCtrl.EnsureVisible(self.oldSel)
            evt.Skip()

        btnDOWN.Bind(wx.EVT_BUTTON, onButtonDown)

        def OnApplyBtn(evt):
            panel.dialog.buttonRow.applyButton.Enable(False)
            #evt.Skip() => applyButton work is only fictive !!!

        panel.dialog.buttonRow.applyButton.Bind(wx.EVT_BUTTON, OnApplyBtn)

        def OnCloseBox(evt):
            eg.EventGhostEvent.__init__ = egEventInit
            evt.Skip()

        panel.dialog.Bind(wx.EVT_CLOSE, OnCloseBox)
        panel.dialog.buttonRow.cancelButton.Bind(wx.EVT_BUTTON, OnCloseBox)

        def onClick(evt=None, init=False):
            if init:
                listBoxCtrl.Set([n[0] for n in self.remotes])
                if listBoxCtrl.GetCount():
                    listBoxCtrl.SetSelection(0)
            if listBoxCtrl.GetCount():
                rem = listBoxCtrl.GetSelection()
                item = self.remotes[rem]
                FillRemoteForm(self.remotes[rem])
                EnableBtns(True)
                EnableLabel(True)
            else:
                item = ["", "", []]
            labelCtrl.ChangeValue(item[0])
            FillRemoteForm(item)
            listBoxCtrl.SetFocus()
            if evt:
                evt.Skip()

        listBoxCtrl.Bind(wx.EVT_LISTBOX, onClick)
        onClick(init=True)

        while panel.Affirmed():
            eg.EventGhostEvent.__init__ = egEventInit
            panel.SetResult(prefText.GetValue(), self.remotes, panel.suffixes)
コード例 #2
0
ファイル: __init__.py プロジェクト: kdschlosser/EventGhost
    def Configure(
        self,
        Prefix = "Remote",
        remotes = [],
        suffixes = None
    ):
        egEventInit = eg.EventGhostEvent.__init__

        text = self.text
        self.remotes = cpy(remotes)
        del remotes
        panel = eg.ConfigPanel(self, resizable = True)
        if not suffixes:
            from eg.Classes.IrDecoder.Rc6 import MCE_REMOTE as MCE
            suffixes = list(MCE.itervalues())
        panel.suffixes =  suffixes

        def TestUse(val):
            rem = None
            for item in self.remotes:
                for button in item[2]:
                    if button[2]==val:
                        rem = item[0]
                        break
                if rem:
                    break
            return rem
        panel.testUse = TestUse

        leftSizer = wx.BoxSizer(wx.VERTICAL)
        box1 = wx.StaticBox(panel, -1, "")
        eventSizer = wx.StaticBoxSizer(box1, wx.VERTICAL)
        prefLabel = wx.StaticText(panel, -1, text.prefix)
        prefText = wx.TextCtrl(panel, -1, Prefix)
        prefLabel2 = wx.StaticText(panel, -1, text.nativePrefix)
        prefText2 = wx.TextCtrl(panel, -1, "")
        buttonsListCtrl = wx.ListCtrl(panel, -1, style=wx.LC_REPORT | wx.VSCROLL|wx.LC_VRULES |wx.LC_HRULES |wx.LC_SINGLE_SEL)
        self.back = buttonsListCtrl.GetBackgroundColour()
        self.fore = buttonsListCtrl.GetForegroundColour()
        self.selBack = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
        self.selFore = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
        suffText = wx.TextCtrl(panel, -1, "", style = wx.TE_READONLY )
        suffText.SetToolTipString(text.suffToolTip)
        labelText = wx.TextCtrl(panel, -1, "")
        suffChoice = wx.Choice(panel, -1, choices = panel.suffixes)

        def UpdateChoices():
            suffChoice.Clear()
            suffChoice.AppendItems(panel.suffixes)
        panel.updateChoices = UpdateChoices

        evtPrefSizer = wx.BoxSizer(wx.HORIZONTAL)
        evtPrefSizer.Add(prefLabel, 0, wx.TOP, 3)
        evtPrefSizer.Add(prefText, 1, wx.EXPAND|wx.LEFT, 5)
        eventSizer.Add(evtPrefSizer, 0, wx.EXPAND|wx.TOP, 4)
        suffButton = wx.Button(panel, -1, text.suffixes)
        eventSizer.Add(suffButton, 0, wx.EXPAND|wx.TOP, 8)
        remListSizer = wx.GridBagSizer(1, 10)
        box2 = wx.StaticBox(panel, -1, "")
        rightStatSizer = wx.StaticBoxSizer(box2, wx.VERTICAL)
        rightSizer = wx.GridBagSizer(8, 1)
        rightStatSizer.Add(rightSizer, 1, wx.EXPAND)
        remListLabel=wx.StaticText(panel, -1, text.menuPreview)
        listBoxCtrl = wx.ListBox(
            panel,-1,
            style = wx.LB_SINGLE | wx.LB_NEEDED_SB
        )
        labelLbl = wx.StaticText(panel, -1, text.label)
        labelCtrl = wx.TextCtrl(panel, -1, '')
        #Buttons 'Delete', 'Import', 'Export' and 'Insert new'
        lenLst = [panel.GetTextExtent(item)[0] for item in text.buttons]
        btn = wx.Button(panel,-1,text.buttons[lenLst.index(max(lenLst))])
        sz = btn.GetSize()
        btn.Destroy()
        btnDEL = wx.Button(panel, -1, text.buttons[0], size = sz)
        btnApp = wx.Button(panel, -1, text.buttons[1], size = sz)
        btnImp = wx.Button(panel, -1, text.buttons[2], size = sz)
        btnExp = wx.Button(panel, -1, text.buttons[3], size = sz)

        def EnableBtns(enable):
            btnDEL.Enable(enable)
            btnImp.Enable(enable)
            btnExp.Enable(enable)


        def EnableLabel(enable):
            labelCtrl.Enable(enable)
            labelLbl.Enable(enable)

        EnableBtns(False)
        EnableLabel(False)
        lenLst = [panel.GetTextExtent(item)[0] for item in text.buttons2]
        btn = wx.Button(panel,-1,text.buttons2[lenLst.index(max(lenLst))])
        sz = btn.GetSize()
        btn.Destroy()
        delEvent = wx.Button(panel, -1, text.buttons2[0], size = sz)
        clearEvents = wx.Button(panel, -1, text.buttons2[1], size = sz)
        addEvent = wx.Button(panel, -1, text.buttons2[2], size = sz)
        duplEvent = wx.Button(panel, -1, text.buttons2[3], size = sz)

        #Button UP
        bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_UP, wx.ART_OTHER, (16, 16))
        btnUP = wx.BitmapButton(panel, -1, bmp)
        btnUP.Enable(False)
        #Button DOWN
        bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_DOWN, wx.ART_OTHER, (16, 16))
        btnDOWN = wx.BitmapButton(panel, -1, bmp)
        btnDOWN.Enable(False)

        leftSizer.Add(eventSizer, 0, wx.EXPAND)
        leftSizer.Add(remListSizer,1,wx.EXPAND|wx.TOP, 15)
        leftSizer.Add((1,4))
        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        mainSizer.Add(leftSizer, 0, wx.EXPAND)
        mainSizer.Add(rightStatSizer, 1, wx.LEFT | wx.EXPAND, 24)
        panel.sizer.Add(mainSizer, 1, wx.EXPAND)

        def EnableCtrls(enable):
            suffText.Enable(enable)
            labelText.Enable(enable)
            suffChoice.Enable(enable)
            if enable:
                eg.EventGhostEvent.__init__ = EventRemap
            else:
                eg.EventGhostEvent.__init__ = egEventInit


        def ResetCtrls():
            suffText.ChangeValue("")
            labelText.ChangeValue("")
            suffChoice.SetSelection(-1)


        def FillButtonsList(item):
            buttonsListCtrl.DeleteAllItems()
            for row in range(len(item[2])):
                buttonsListCtrl.InsertStringItem(row, item[2][row][0])
                buttonsListCtrl.SetStringItem(row, 1, item[2][row][1])
                buttonsListCtrl.SetStringItem(row, 2, item[2][row][2])


        def FillRemoteForm(item):
            self.oldSel = -1
            prefText2.SetValue(item[1])
            enable = item[1] != ""
            addEvent.Enable(enable)
            ResetCtrls()
            FillButtonsList(item)
            clearEvents.Enable(len(item[2]) > 0)
            EnableButtonsRight(False)
            duplEvent.Enable(False)
            EnableCtrls(False)

        evtPrefSizer2 = wx.BoxSizer(wx.HORIZONTAL)
        evtPrefSizer2.Add((-1, 1), 1, wx.EXPAND)
        evtPrefSizer2.Add(prefLabel2, 0, wx.TOP, 3)
        evtPrefSizer2.Add(prefText2, 0, wx.LEFT, 5)
        w = 0
        for i, colLabel in enumerate(text.header):
            buttonsListCtrl.InsertColumn(i, colLabel)
            buttonsListCtrl.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER)
            w += buttonsListCtrl.GetColumnWidth(i)
        buttonsListCtrl.SetSize((w+SYS_VSCROLL_X+buttonsListCtrl.GetWindowBorderSize()[0], -1))
        w0 = buttonsListCtrl.GetColumnWidth(0)
        w1 = buttonsListCtrl.GetColumnWidth(1)
        w2 = buttonsListCtrl.GetColumnWidth(2)
        suffText.SetMinSize((w0-1, -1))
        labelText.SetMinSize((w1-1, -1))
        suffChoice.SetMinSize((w2-1, -1))
        rightSizer.Add(evtPrefSizer2,(0,0), (1,4),flag = wx.EXPAND|wx.TOP,border = 4)
        rightSizer.Add(buttonsListCtrl,(1,0),(5,4),flag = wx.EXPAND)
        rightSizer.Add(delEvent,(1,4), flag= wx.TOP|wx.ALIGN_RIGHT, border = 24)
        rightSizer.Add(clearEvents,(2,4), flag = wx.ALIGN_RIGHT)
        brdr = 8 + SYS_VSCROLL_X + buttonsListCtrl.GetWindowBorderSize()[0]
        rightSizer.Add(btnUP,(3,4), flag = wx.LEFT, border = brdr)
        rightSizer.Add(btnDOWN,(4,4), flag = wx.LEFT, border = brdr)
        rightSizer.Add(duplEvent,(5,4), flag = wx.ALIGN_BOTTOM|wx.ALIGN_RIGHT)
        rightSizer.Add(suffText,(6,0),flag = wx.EXPAND|wx.LEFT, border = 1)
        rightSizer.Add(labelText,(6,1),flag = wx.EXPAND|wx.LEFT, border = 1)
        rightSizer.Add(suffChoice,(6,2),flag = wx.EXPAND|wx.LEFT, border = 1)
        rightSizer.Add(addEvent,(6,4), flag = wx.LEFT, border = brdr)
        rightSizer.AddGrowableRow(5)
        rightSizer.AddGrowableCol(0,w0)
        rightSizer.AddGrowableCol(1,w1)
        rightSizer.AddGrowableCol(2,w2)
        remListSizer.Add(remListLabel,(0,0))
        remListSizer.Add(listBoxCtrl,(1,0),(4,1), flag = wx.EXPAND)
        remListSizer.Add(labelLbl,(5,0), flag = wx.TOP, border = 8)
        remListSizer.Add(labelCtrl,(6,0), flag = wx.EXPAND)
        remListSizer.Add(btnDEL,(1,1))
        remListSizer.Add(btnImp,(2,1), flag = wx.TOP, border = 8)
        remListSizer.Add(btnExp,(3,1), flag = wx.TOP, border = 8)
        remListSizer.Add((-1, 1),(4,1))
        remListSizer.Add(btnApp,(6,1))
        remListSizer.AddGrowableRow(4)
        panel.sizer.Layout()

        def EnableLeftSide(enable):
            EnableBtns(enable)
            EnableLabel(enable)
            btnApp.Enable(enable)
            remListLabel.Enable(enable)
            listBoxCtrl.Enable(enable)
            labelLbl.Enable(enable)
            labelCtrl.Enable(enable)


        def SetWidth():
            w0 = suffText.GetSize()[0]+1
            w1 = labelText.GetSize()[0]+1
            w2 = suffChoice.GetSize()[0]+1
            buttonsListCtrl.SetSize((w0+w1+w2+SYS_VSCROLL_X + buttonsListCtrl.GetWindowBorderSize()[0], -1))
            buttonsListCtrl.SetColumnWidth(0, w0)
            buttonsListCtrl.SetColumnWidth(1, w1)
            buttonsListCtrl.SetColumnWidth(2, w2)


        def OnSize(event):
            wx.CallAfter(SetWidth)
            panel.Update()
            event.Skip()
        panel.Bind(wx.EVT_SIZE, OnSize)


        def OnDelEvent(evt):
            rem = listBoxCtrl.GetSelection()
            self.remotes[rem][2].pop(self.oldSel)
            buttonsListCtrl.DeleteItem(self.oldSel)
            lngth = len(self.remotes[rem][2])
            prefText2.Enable(True)
            if lngth == 0:
                self.oldSel = -1
                OnPrefText2()
                ResetCtrls()
                evt.Skip()
                return
            elif self.oldSel == lngth:
                row = lngth - 1
            else:
                row = self.oldSel
            self.oldSel = -1
            SelRow(row)
            suffText.ChangeValue(buttonsListCtrl.GetItemText(row))
            labelText.ChangeValue(buttonsListCtrl.GetItem(row, 1).GetText())
            suffChoice.SetStringSelection(buttonsListCtrl.GetItem(row, 2).GetText())
            OnPrefText2()
            Validation()
            evt.Skip()
        delEvent.Bind(wx.EVT_BUTTON, OnDelEvent)


        def OnClearEvents(evt):
            rem = listBoxCtrl.GetSelection()
            self.remotes[rem][2] = []
            buttonsListCtrl.DeleteAllItems()
            self.oldSel = -1
            EnableLeftSide(True)
            prefText2.Enable(True)
            OnPrefText2()
            ResetCtrls()
            evt.Skip()
        clearEvents.Bind(wx.EVT_BUTTON, OnClearEvents)


        def onButtonDelete(evt):
            sel = listBoxCtrl.GetSelection()
            listBoxCtrl.Delete(sel)
            self.remotes.pop(sel)
            lngth = len(self.remotes)
            if lngth > 0:
                if sel == lngth:
                    sel = lngth - 1
                listBoxCtrl.SetSelection(sel)
                onClick()
            else:
                labelCtrl.ChangeValue("")
                EnableBtns(False)
                item = ["", "", []]
                FillRemoteForm(item)
            evt.Skip()
        btnDEL.Bind(wx.EVT_BUTTON, onButtonDelete)


        def OnLabelChange(evt):
            flag = False
            sel = listBoxCtrl.GetSelection()
            label = labelCtrl.GetValue()
            self.remotes[sel][0] = label
            listBoxCtrl.SetString(sel, label)
            enable = label != ""
            if enable:
                if [n[0] for n in self.remotes].count(label) == 1:
                    flag = True
            EnableBtns(enable)
            panel.dialog.buttonRow.okButton.Enable(flag)
            btnApp.Enable(flag)
            item = self.remotes[sel]
            prefText2.Enable(flag)
            OnPrefText2()
            if not flag:
                addEvent.Enable(False)
            evt.Skip()
        labelCtrl.Bind(wx.EVT_TEXT, OnLabelChange)


        def OnButtonAppend(evt):
            EnableLabel(True)
            item = ["","",[]]
            self.remotes.append(item)
            listBoxCtrl.Append("")
            listBoxCtrl.SetSelection(listBoxCtrl.GetCount()-1)
            prefText2.ChangeValue("")
            labelCtrl.SetValue("")
            FillRemoteForm(item)
            labelCtrl.SetFocus()
            addEvent.Enable(False)
            evt.Skip()
        btnApp.Bind(wx.EVT_BUTTON, OnButtonAppend)


        def EnableButtonsRight(enable):
            delEvent.Enable(enable)
            if enable:
                rem = listBoxCtrl.GetSelection()
                if len(self.remotes[rem][2]) < 2:
                    enable = False
            btnUP.Enable(enable)
            btnDOWN.Enable(enable)


        def OnPrefText2(evt = None):
            global prefix
            prefix = prefText2.GetValue()
            rem = listBoxCtrl.GetSelection()
            if rem > -1:
                self.remotes[rem][1] = prefix
                s = None
                if prefix != "":
                    #Conflict test:
                    for i in range(len(self.remotes)):
                        rmt = self.remotes[i]
                        if prefix != rmt[1] or i == rem:
                            continue
                        for suff in self.remotes[rem][2]:
                            for sf in rmt[2]:
                                if suff[0] == sf[0] and suff[2] != sf[2]:
                                    s = suff[0]
                                    n = rmt[0]
                                    n0 = suff[2]
                                    n1 = sf[2]
                                    break
                            if s:
                                break
                        if s:
                            break
                    if s:
                        MessageBox(
                            panel,
                            text.message4 % (prefix, prefix, s, n0, n, n1),
                            text.messBoxTit2,
                            wx.ICON_EXCLAMATION,
                            plugin = self,
                            )
                        EnableLeftSide(False)
                        panel.dialog.buttonRow.okButton.Enable(False)
                    else:
                        EnableLeftSide(True)
                        panel.dialog.buttonRow.okButton.Enable(True)
                enable = prefix != "" and not s
                buttonsListCtrl.Enable(enable)
                if not enable or len(self.remotes[rem][2]) == 0:
                    addEvent.Enable(False)
                    duplEvent.Enable(False)
                    EnableButtonsRight(False)
                    clearEvents.Enable(False)
                    EnableCtrls(False)
                elif enable and len(self.remotes[rem][2]) > 0:
                    clearEvents.Enable(True)
                    if self.oldSel != -1:
                        EnableButtonsRight(True)
                        duplEvent.Enable(True)
                        EnableCtrls(True)
                    else:
                        EnableButtonsRight(False)
                        duplEvent.Enable(False)
                        EnableCtrls(False)
                if enable and len(self.remotes[rem][2]) == 0:
                    addEvent.Enable(True)
                if evt:
                    evt.Skip()
        prefText2.Bind(wx.EVT_TEXT, OnPrefText2)


        def Validation():
            flag = True
            strng = suffText.GetValue()
            prfx = prefText2.GetValue()
            rem = listBoxCtrl.GetSelection()
            newSuff = suffChoice.GetStringSelection()
            name = None
            sfx = None
            for i in range(len(self.remotes)):
                item = self.remotes[i]
                if i == rem or item[1] != prfx:
                    continue
                for suff in item[2]:
                    if suff[0] == strng and suff[2] != newSuff:
                        name = item[0]
                        sfx = suff[2]
                        break
                if name:
                    break
            if name:
                MessageBox(
                    panel,
                    text.message2 % (prfx,strng,newSuff,sfx,name),
                    text.messBoxTit2,
                    wx.ICON_EXCLAMATION,
                    plugin = self,
                    )
                flag = False
            if [item[0] for item in self.remotes[rem][2]].count(strng) > 1:
                suffText.SetValue("")
                MessageBox(
                    panel,
                    text.message6 % (strng),
                    text.messBoxTit3,
                    wx.ICON_EXCLAMATION,
                    plugin = self,
                    time = 7
                    )
            if strng == "":
                flag = False
            if labelText.GetValue().strip() == "":
                flag = False
            if suffChoice.GetSelection() == -1:
                flag = False
            addEvent.Enable(flag)
            duplEvent.Enable(flag)
            prefText2.Enable(flag)
            EnableLeftSide(flag)
            panel.dialog.buttonRow.okButton.Enable(flag)


        def EventRemap(self, suffix = "", payload = None, prefix = "Main", source = eg):
            SetSuffix(prefix, suffix)
            self.string = "%s.%s" % (prefix, suffix)
            self.prefix = prefix
            self.suffix = suffix
            self.payload = payload
            self.source = source
            self.time = clock()
            self.isEnded = False
            self.shouldEnd = Event()
            self.upFuncList = []


        def SetSuffix(eventPrefix, eventSuffix):
            if prefix == eventPrefix:
                suffText.SetValue(eventSuffix)


        def OnButtonAddEvent(evt):
            if self.oldSel == -1:
                self.oldSel = buttonsListCtrl.GetItemCount() - 1
            row = self.oldSel + 1
            self.remotes[listBoxCtrl.GetSelection()][2].insert(row,["", "", ""])
            buttonsListCtrl.InsertStringItem(row, "")
            buttonsListCtrl.SetStringItem(row, 1, "")
            buttonsListCtrl.SetStringItem(row, 2, "")
            buttonsListCtrl.EnsureVisible(row)
            SelRow(row)
            EnableCtrls(True)
            addEvent.Enable(False)
            duplEvent.Enable(False)
            clearEvents.Enable(True)
            prefText2.Enable(False)
            EnableLeftSide(False)
            panel.dialog.buttonRow.okButton.Enable(False)
            ResetCtrls()
            EnableButtonsRight(True)
            evt.Skip()
        addEvent.Bind(wx.EVT_BUTTON, OnButtonAddEvent)


        def OnButtonDuplEvent(evt):
            addEvent.Enable(False)
            duplEvent.Enable(False)
            panel.dialog.buttonRow.okButton.Enable(False)
            suffText.ChangeValue("")
            strng1 = labelText.GetValue()
            strng2 = suffChoice.GetStringSelection()
            row = self.oldSel + 1
            self.remotes[listBoxCtrl.GetSelection()][2].insert(row, ["", strng1, strng2])
            buttonsListCtrl.InsertStringItem(row, "")
            buttonsListCtrl.SetStringItem(row, 1, strng1)
            buttonsListCtrl.SetStringItem(row, 2, strng2)
            SelRow(row)
            buttonsListCtrl.EnsureVisible(row)
            evt.Skip()
        duplEvent.Bind(wx.EVT_BUTTON, OnButtonDuplEvent)


        def OnSuffText(evt):
            strng = evt.GetString()
            self.remotes[listBoxCtrl.GetSelection()][2][self.oldSel][0] = strng
            buttonsListCtrl.SetStringItem(self.oldSel, 0, strng)
            Validation()
            evt.Skip()
        suffText.Bind(wx.EVT_TEXT, OnSuffText)


        def OnLabelText(evt):
            strng = labelText.GetValue()
            self.remotes[listBoxCtrl.GetSelection()][2][self.oldSel][1] = strng
            buttonsListCtrl.SetStringItem(self.oldSel, 1, strng)
            Validation()
            evt.Skip()
        labelText.Bind(wx.EVT_TEXT, OnLabelText)


        def OnSuffChoice(evt):
            strng = suffChoice.GetStringSelection()
            self.remotes[listBoxCtrl.GetSelection()][2][self.oldSel][2] = strng
            buttonsListCtrl.SetStringItem(self.oldSel, 2, strng)
            duplEvent.Enable(True)
            Validation()
            evt.Skip()
        suffChoice.Bind(wx.EVT_CHOICE, OnSuffChoice)


        def SelRow(row):
            if row != self.oldSel:
                if self.oldSel in range(buttonsListCtrl.GetItemCount()):
                    item = buttonsListCtrl.GetItem(self.oldSel)
                    item.SetTextColour(self.fore)
                    item.SetBackgroundColour(self.back)
                    buttonsListCtrl.SetItem(item)
                self.oldSel = row
            if buttonsListCtrl.GetItemBackgroundColour(row) != self.selBack:
                item = buttonsListCtrl.GetItem(row)
                item.SetTextColour(self.selFore)
                item.SetBackgroundColour(self.selBack)
                buttonsListCtrl.SetItem(item)


        def OnSuffixSelect(evt):
            row = evt.GetIndex()
            buttonsListCtrl.SetItemState(row, 0, wx.LIST_STATE_SELECTED)
            if row == self.oldSel:
                evt.Skip()
                return
            if not addEvent.IsEnabled() and self.oldSel > -1:
                old = self.oldSel
                self.oldSel = row
                SelRow(old)
                PlaySound('SystemExclamation', SND_ASYNC)
                evt.Skip()
                return
            EnableCtrls(True)
            SelRow(row)
            duplEvent.Enable(True)
            EnableButtonsRight(True)
            suffText.ChangeValue(buttonsListCtrl.GetItemText(row))
            labelText.ChangeValue(buttonsListCtrl.GetItem(row, 1).GetText())
            suffChoice.SetStringSelection(buttonsListCtrl.GetItem(row, 2).GetText())
            evt.Skip()
        buttonsListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, OnSuffixSelect)


        def OnBtnExp(evt):
            ix = listBoxCtrl.GetSelection()
            name = self.remotes[ix][0]
            dlg = wx.FileDialog(
                panel,
                message = text.save % name,
                defaultDir = eg.configDir,
                defaultFile = name,
                wildcard = text.wildcard,
                style=wx.SAVE
                )
            if dlg.ShowModal() == wx.ID_OK:
                self.dataToXml(self.remotes[ix], dlg.GetPath())
            dlg.Destroy()
            evt.Skip()
        btnExp.Bind(wx.EVT_BUTTON, OnBtnExp)


        def OnBtnImp(evt):
            ix = listBoxCtrl.GetSelection()
            dlg = wx.FileDialog(
                panel,
                message = text.choose % self.remotes[ix][0],
                defaultDir = eg.configDir,
                defaultFile = "",
                wildcard = text.wildcard,
                style = wx.OPEN | wx.CHANGE_DIR
                )
            if dlg.ShowModal() == wx.ID_OK:
                filePath = dlg.GetPath()
                item = self.xmlToData(filePath)
                dlg.Destroy()
            else:
                dlg.Destroy()
                evt.Skip()
                return
            if not item:
                MessageBox(
                    panel,
                    text.message5 % path.split(dlg.GetPath())[1],
                    text.messBoxTit1,
                    wx.ICON_EXCLAMATION,
                    plugin = self,
                    )
                evt.Skip()
                return
            #Conflict test:
            s = None
            for i in range(len(self.remotes)):
                rem = self.remotes[i]
                if item[1] != rem[1] or i == ix:
                    continue
                for suff in item[2]:
                    for sf in rem[2]:
                        if suff[0] == sf[0] and suff[2] != sf[2]:
                            s = suff[0]
                            n = rem[0]
                            n0 = suff[2]
                            n1 = sf[2]
                            break
                    if s:
                        break
                if s:
                    break
            if s:
                MessageBox(
                    panel,
                    text.message3 % (item[1], s, n0, n, n1),
                    text.messBoxTit2,
                    wx.ICON_EXCLAMATION,
                    plugin = self,
                    )
                evt.Skip()
                return
            else:
                for suff in item[2]:
                    if suff[2] not in panel.suffixes:
                        panel.suffixes.append(suff[2])
                item[0] = self.remotes[ix][0]
                self.remotes[ix] = item
                FillRemoteForm(item)
            evt.Skip()
        btnImp.Bind(wx.EVT_BUTTON, OnBtnImp)


        def OnSuffButton(evt):
            dlg = SuffixesFrame(
                parent = panel,
                plugin = self,
            )
            dlg.Centre()
            wx.CallAfter(dlg.ShowSuffixesFrame)
            evt.Skip()
        suffButton.Bind(wx.EVT_BUTTON, OnSuffButton)


        def onButtonUp(evt):
            rem = listBoxCtrl.GetSelection()
            newSel, suffixes = Move(self.remotes[rem][2], self.oldSel, -1)
            self.remotes[rem][2] = suffixes
            FillButtonsList(self.remotes[rem])
            SelRow(newSel)
            buttonsListCtrl.EnsureVisible(self.oldSel)
            evt.Skip()
        btnUP.Bind(wx.EVT_BUTTON, onButtonUp)


        def onButtonDown(evt):
            rem = listBoxCtrl.GetSelection()
            newSel, suffixes = Move(self.remotes[rem][2], self.oldSel, 1)
            self.remotes[rem][2] = suffixes
            FillButtonsList(self.remotes[rem])
            SelRow(newSel)
            buttonsListCtrl.EnsureVisible(self.oldSel)
            evt.Skip()
        btnDOWN.Bind(wx.EVT_BUTTON, onButtonDown)


        def OnApplyBtn(evt):
            panel.dialog.buttonRow.applyButton.Enable(False)
            #evt.Skip() => applyButton work is only fictive !!!
        panel.dialog.buttonRow.applyButton.Bind(wx.EVT_BUTTON, OnApplyBtn)


        def OnCloseBox(evt):
            eg.EventGhostEvent.__init__ =  egEventInit
            evt.Skip()
        panel.dialog.Bind(wx.EVT_CLOSE, OnCloseBox)
        panel.dialog.buttonRow.cancelButton.Bind(wx.EVT_BUTTON, OnCloseBox)


        def onClick(evt = None, init = False):
            if init:
                listBoxCtrl.Set([n[0] for n in self.remotes])
                if listBoxCtrl.GetCount():
                    listBoxCtrl.SetSelection(0)
            if listBoxCtrl.GetCount():
                rem = listBoxCtrl.GetSelection()
                item = self.remotes[rem]
                FillRemoteForm(self.remotes[rem])
                EnableBtns(True)
                EnableLabel(True)
            else:
                item = ["", "", []]
            labelCtrl.ChangeValue(item[0])
            FillRemoteForm(item)
            listBoxCtrl.SetFocus()
            if evt:
                evt.Skip()
        listBoxCtrl.Bind(wx.EVT_LISTBOX, onClick)
        onClick(init = True)

        while panel.Affirmed():
            eg.EventGhostEvent.__init__ =  egEventInit
            panel.SetResult(prefText.GetValue(), self.remotes, panel.suffixes)