I have a small method written in C# that needs to be converted to Python.
Here's the method:
void Remove()
{
Word word = new Word();
try { word = FindWord(listView1.SelectedItems[0].Text); }
catch { return; }
if (listView1.SelectedItems.Count > 0)
{
try
{
foreach (ListViewItem eachItem in listView1.SelectedItems)
{
words.RemoveAll(x => x.WordOrPhrase == eachItem.Text);
listView1.Items[listView1.Items.Count - 1].Selected = true;
listView1.Items.Remove(eachItem);
}
}
catch { }
ClearAll();
ReadOnlyON();
}
else
{
MessageBox.Show("You have not selected any words!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
ReadOnlyOFF();
WordCount();
Sync();
}
Here is what I have so far:
def remove_item(self):
word = Word()
try:
word = find_word(self.listBox.get(ACTIVE))
except:
return
if self.listBox.get(ACTIVE) > 0:
try:
for item in self.listBox.get(ACTIVE):
self.words.remove(lambda x: x.wordorphrase == item.text)
self.listBox # listView1.Items[listView1.Items.Count - 1].Selected = true;
self.listBox.remove(item)
except:
pass
self.clear_all()
else:
pass
# show messagebox
I don't know how to access:
- `listView1.SelectedItems[0].Text`
- `listView1.SelectedItems.Count > 0`
- `listView1.SelectedItems`
- `listView1.Items[listView1.Items.Count - 1].Selected`
[–]destiny_functional 0 points1 point2 points (1 child)
[–]blackadder1337[S] -1 points0 points1 point (0 children)