Insert into the middle of MDList kivymd? - list

How do I put a OneLineListItem in the middle of a MDList. For a sort of pop down menu.
Here I explain in an array [Item, item, item, 'spot I want item', item, item]
Here I explain with a dictionary
{Item:item, item:item, item:item, 'spot I want item', item:item, item:item}
Here I explain with a slightly accurate display of what I'm looking for
Item
Item
Item
Spot I want item
Item
Item
Kv = `
MDScrollView:
ValuesAndStuff
MDList:
ValuesAndStuff
OneLineListItem:
OneLineListItem:
OneLineListItem:
`
def insert_middle:
#Code to insert OneLineListItem into middle of MDList.

Related

Tkinter combobox loop again. Getting the results

I created a group of comboboxes from looping a list and
used dict key as item em combolist. Problems: I cannot get back results to a 'results' list. All comboboxes change at same time. I´ve studied other posts about the subject, but I cant understand the concept involved in the solution.
To sum: The code generate 3 combobox but they change togeter, and I cant append results.
Thanks for your help, in advance:
#-----------------------code
from tkinter import
from tkinter import ttk
win = Tk()
win.geometry('400x600')
win.title('combobox')
result =[] #--> the new list with results of comboboxes
opts = StringVar()
anyFruits =['any_grape', 'any_tomato', 'any_banana']
#--> list just to generate the loop
fruits = {'specialgrape':'specialgrape', 'specialtomato':'specialtomato','specialbanana':'specialbanana'}
#--> dictonary to generate drop down options menu (key of dict)
for index, fruit in enumerate(anyFruits):
mycombo = ttk.Combobox(win,
values= (list(fruits.keys())),textvariable=opts)
mycombo.bind('<<ComboboxSelected>>', lambda event, index=index: fruit_callBack(index, event))
mycombo.pack()
def fruit_callBack(index, event):
for opts in mycombo:
result.append(opts)
def print_():
print(result)
bt = Button(win,command= print_)
bt.pack()
win.mainloop()
The value all change together because all Combobox have same textvariable. Hence change in one, will force the others to keep the value same. Anyway, you are appending it wrong too, you do not need to pass in index, just pass the combobox itself and append the value inside it:
for index, fruit in enumerate(anyFruits):
mycombo = ttk.Combobox(win,values=list(fruits.keys()))
mycombo.bind('<<ComboboxSelected>>',lambda e,cmb=mycombo: fruit_callBack(e,cmb))
mycombo.pack()
def fruit_callBack(event,cmb):
result.append(cmb.get())

How to append a element in list forever?

How can i append an element to the list forever?It means if next time i open my file,the element i append still exist.Please help me thanks!
book_list=["good","best"]
new_book=input("Enter new book name")
book_list.append(new_book)
print(book_list)
Every time press one is triggered you init the book_list with empty list, and when user press two you also reinit the list overwriting the previous state. You should do this init before the loop that you have this conditions in.
You are basically creating new empty list ever time an action is triggered and you cannot do that if you want to see your updates.
By the init/clear i mean this line:
book_list = []
So it should look similar to this:
book_list = []
while True:
action = input("Chose 1 for... 2 for...")
if action == "1":
print(book_list)
elif action == "2":
new_book = input("Enter new book name")
book_list.append(new_book)

Delete QListWidget item by text content

I need to delete a qlistwidget item by text content
I tried:
QString mstring = "Programmer II";
QList<QListWidgetItem *> items = ui->listJobs->findItems(mstring, Qt::MatchExactly);
if (items.size() > 0)
ui->listJobs->takeItem( ui->listJobs->currentRow() );
...and various permutations, but I'm missing something. The code above compiles, but does not delete the item from the qlistwidget.
The code doesn't indicate what the value of currentRow is, but findItems doesn't set it, so it's unlikely to correlate with the value you're trying to remove. I don't see any way to use the results of findItems and get the row(s) you want to remove. I think you have to loop through the contents, compare the text of each item, and then remove the ones that match. You'll probably want to do the loop in reverse order; otherwise, once you've removed an item, the loop counter will no longer match the list item's row numbers.

How to properly change focus item in the ListView control?

If I want to change the focus item in the ListView control I do the following:
BOOL setListFocusItem(CListCtrl* pList, int nIndex)
{
return !!pList->SetItemState(nInd, LVIS_FOCUSED, LVIS_FOCUSED);
}
Is this the way you do it?
Because the focus itself changes but there's one issue that this creates. For instance, if the list had 100 items and the focus was on item 1. If I then call my method as such setListFocusItem(99); the focus changes to item 99, but then if I shift-click on item 90, I would expect the list to have items 90 through 99 to be selected. But instead the list selects items 1 through 90. So obviously my setListFocusItem() method does not change the shift-click "first" location. So question is how to make it do it?
Short answer : use the LVM_SETSELECTIONMARK message.
(In MFC-ese, CListCtrl::SetSelectionMark).

Haskell increment the last element of a tuple

Hi could you please help me on how to increment the last element of a tuple.
Currently i have this list of tuples
items :: [Grocery]
items = [("Water", "Drink Section", 1),
("Squash", "Drink Section", 1),
("Apple", "Fruit Section", 1),
("Plates", "Disposable Section", 1),
("Plates", "Ceramic Section", 1)]
and what i wanted to do is increment it by 1 every time the item is bought and output the database. currently i have this
sales:: [database] -> String -> String-> [database]
sales db itemName sectionName = []
sales ((item, section, qty): xs) itemName sectionName
| item == itemName && section== sectionName = [(item, section, qty + 1)]
| otherwise = []
im still in the bit of incrementing it and im stuck. please help me i'm still a newbie on this language. thank you!
Edit
its all working now but how do you output the rest of the list? i tried recordSale xs trackArtist trackTitle but when i test it the old record that i incremented gets printed as well instead of getting modified? lets say that i incremented apple what it'll print is this
[("Apple", "Fruit Section", 2),("Water", "Drink Section", 1),("Squash", "Drink Section", 1), ("Apple", "Fruit Section", 1)]
it duplicates the record instead of just adding 1
That's not bad, but lets pretend you're trying to increment "Squash", the second element down in your example list of items. What does sales do? It checks if the first item in the list, Water, equals Squash. Since water doesn't equal squash it hits the otherwise case and returns [].
So all of that seems right up until we got a [] back - lets change the code in otherwise. Obviously we don't want to throw away the entire list, that would be stupid. You should rewrite it to keep the item that was just compared and concatenate it on to the result of sales applied to the rest of the list (xs).
After you get that otherwise branch fixed you're going to notice the entire list after the item you increment is thrown away - I think that one will pop right out at you once you finish this issue.
P.S. Fire the employee that put Squash in the drinking section.