Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature: Option reordering #18

Merged
merged 3 commits into from
Oct 15, 2023

Conversation

CheemaOTB
Copy link
Contributor

This pull request addresses the open issue #17 by introducing a new feature: Option Reordering. Users can now easily reorder options as needed. The changes include two new methods, move_up and move_down. This enhancement aims to resolve the reported issue and improve the overall usability of the widget.

Below is an example code snippet demonstrating how the new option reordering feature can be implemented by users:

import customtkinter
from CTkListbox import *

# Create the main application window
root = customtkinter.CTk()

# Function to move the selected item up in the list
def moveup():
    index = animalBox.curselection()
    if index > 0:
        animalBox.move_up(index)
        animalList[index - 1], animalList[index] = animalList[index], animalList[index - 1]

# Function to move the selected item down in the list
def movedown():
    index = animalBox.curselection()
    if index < animalBox.size() - 1:
        animalBox.move_down(index)
        animalList[index], animalList[index + 1] = animalList[index + 1], animalList[index]

# Function to handle the selection event in the listbox
def show_value(selected_option):
    print(selected_option)

# Initial list of animals
animalList = ['Cat', 'Dog', 'Bear', 'Dolphin', 'Kangaroo']

# Create a Tkinter StringVar with the initial list
animalString = customtkinter.StringVar(value=animalList)

# Create a custom listbox using CTkListbox
animalBox = CTkListbox(root, command=show_value, listvariable=animalString)
animalBox.grid(row=1, column=0, padx=20, pady=10)

# Create buttons for moving items up and down
moveupButton = customtkinter.CTkButton(root, text="Move Up", command=moveup, width=200, height=35)
moveupButton.grid(row=2, column=0, padx=20, pady=10)

movedownButton = customtkinter.CTkButton(root, text="Move Down", command=movedown, width=200, height=35)
movedownButton.grid(row=3, column=0, padx=20, pady=10)

# Start the Tkinter main loop
root.mainloop()

@SilasPDJ
Copy link

SilasPDJ commented Oct 3, 2023

Esteemed @CheemaOTB,

First of all: as a user I appreciate your PR.
However, in my humble opinion there's a issue:

The scroll bar isn't going up/down, which is expected when some invisible option gets selected, so this way it'll be into user's visibility

I used this testing list for this feedback
animalList = [ 'Cat', 'Dog', 'Bear', 'Dolphin', 'Kangaroo', 'Cat', 'Dog', 'Bear', 'Dolphin', 'Kangaroo', 'Cat', 'Dog', 'Bear', 'Dolphin', 'Kangaroo', 'Cat', 'Dog', 'Bear', 'Dolphin', 'Kangaroo', 'Cat', 'Dog', 'Bear', 'Dolphin', 'Kangaroo', 'Cat', 'Dog', 'Bear', 'Dolphin', 'Kangaroo', 'Cat', 'Dog', 'Bear', 'Dolphin', 'Kangaroo', 'Cat', 'Dog', 'Bear', 'Dolphin', 'Kangaroo', ]

Edit:

I know this is not a big deal, I'd appreciate if it was implemented together though.

Thanks in advance.

@CheemaOTB
Copy link
Contributor Author

Hey @SilasPDJ

Thanks for the heads up! I'll look into the scroll bar issue right away and make sure to address it.

Appreciate it!

refractor: Tidied up the code for a sleeker, more efficient implementation.
@Akascape Akascape added the enhancement New feature or request label Oct 3, 2023
@Akascape Akascape self-requested a review October 3, 2023 07:50
@Akascape Akascape merged commit 8c9f1f0 into Akascape:main Oct 15, 2023
@CheemaOTB CheemaOTB deleted the feature-option-reordering branch October 18, 2023 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants