Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Automatic search functionality

[es] :: Python :: Automatic search functionality

[ Pregleda: 4799 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

wraith46

Član broj: 336363
Poruke: 29



+1 Profil

icon Automatic search functionality18.04.2017. u 13:55 - pre 85 meseci
Napravio sam jednostavnu GUI aplikaciju koju koristim za učenje engleskog. Aplikacija, koja se zove Vocabulary, napisana je u C# i load-uje/save-uje reči iz/u XML fajl. Pošto sam se nedavno prebacio sa Windowsa na Linux, pravim ponovo aplikaciju koristeći Python.

Imam problem sa implementiranjem automatskog pretraživanja reči. Kad unesem reč u text widget, treba da je nađe u listboxu. Da bih postigao to što želim, znam da treba da hendlujem text changed event.

Evo moje C# metode:

Code:
 private void txt_Search_TextChanged(object sender, EventArgs e)
    {
        if (txt_Search.Text != "")
        {
            for item in list(listView1):
                if txt_Search.Text.lower() in item.Text.lower():
                    item.BackColor = SystemColors.Highlight;
                    item.ForeColor = SystemColors.HighlightText;
                else:
                    listView1.remove(item);
            }
            if len(listView1.SelectedItems) == 1:
                listView1.Focus();
        }
        else
        {
            LoadWords();
            RefreshAll();
            foreach (ListViewItem item in listView1.Items)
            {
                item.BackColor = SystemColors.Window;
                item.ForeColor = SystemColors.WindowText;
            }
        }
    }


...a evo i moje Python funkcije dosad:

Code:
    def txt_Search_text_changed(self, event = None):

        if self.get_search() != None:

            i = self.listBox.size() - 1

            for x in range(i, 0, -1):
                item = self.listBox[i]
                if get_search().lower() in item.lower():
                    self.listBox.itemconfig(item, {'bg': 'red'})

                else:
                    self.listBox.delete(item)

            if len(self.listBox.curselection()) == 1:
                self.listBox.focus()

        else:
            self.load_words()
            self.refresh_all()
            for item in self.listBox:
                self.listBox.itemconfig(item, {'bg': 'white'})


Ne znam šta je Python ekvivalent za:
Code:

listView1.Items[i]; listView1.Items


Je l' može neko da pomogne, veoma mi je bitno..
 
Odgovor na temu

[es] :: Python :: Automatic search functionality

[ Pregleda: 4799 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.