1
I’m writing an interface with wxPython, but I’ve come across a problem so far with no solution, even looking at the documentation.
I have a Listctrl with several items that should be sent to the other Listctrl when pressing a button. The problem is that I have to read this first Listctrl out to get the item that is focused. When I do it the first time, good, bad is how much I click without selecting anything the second time.
Imagery
When I click on the series, the disciplines appear, then I have to click on the discipline before trying to add, so far so good.
When I click add, the discipline goes to the other side... blz.
But when I click again on add the discipline, even without selecting anything, it adds to what was in place.
Code
When I click the button, this function is called, and lstDisciplines indicates the table on the left side and self.lstDisciplines the ones on the right side:
def adicionar_disciplina(self, event):
n_disciplina = self.lstDisciplinasPadroes.GetFocusedItem()
if not self.lstDisciplinasPadroes.IsSelected(n_disciplina):
event.Skip()
if 0 <= n_disciplina:
#### INICIO ADICIONA NAS ESCOLHIDAS ####
abreviacao = self.lstDisciplinasPadroes.GetItem(n_disciplina, 0).GetText()
nomeDisciplina = self.lstDisciplinasPadroes.GetItem(n_disciplina, 1).GetText()
nomeProfessor = self.lstDisciplinasPadroes.GetItem(n_disciplina, 2).GetText()
numeroDisciplinasEscolhidas = self.lstDisciplinasEscolhidas.GetItemCount()
self.lstDisciplinasEscolhidas.InsertItem(numeroDisciplinasEscolhidas, abreviacao)
self.lstDisciplinasEscolhidas.SetItem(numeroDisciplinasEscolhidas, 1, nomeDisciplina)
self.lstDisciplinasEscolhidas.SetItem(numeroDisciplinasEscolhidas, 2, nomeProfessor)
#### FIM ADICIONA NAS ESCOLHIDAS ####
#### INICIO REMOVE PADROES ####
self.lstDisciplinasPadroes.DeleteItem(n_disciplina)
#### FIM REMOVE PADROES ####
self.disciplinasPorTurma[self.turma].update({abreviacao: [nomeDisciplina, nomeProfessor]})
else:
event.Skip()
Notes:
- Apparently, this variable n_disciplina is internal to the function and does not store its value anywhere else.
- That first little if I just added a little bit to try to answer my own question.