[go: nahoru, domu]

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

TabbedPanel.switch_to() does not appear to work #3493

Closed
ahed87 opened this issue Jul 9, 2015 · 10 comments
Closed

TabbedPanel.switch_to() does not appear to work #3493

ahed87 opened this issue Jul 9, 2015 · 10 comments
Labels
easy Should be easy to fix Type: Documentation Docs should be added/fixed

Comments

@ahed87
Copy link
ahed87 commented Jul 9, 2015

Hi,

first of all I would like to congratulate on the great work that kivy is, keep it up!!
I really hope that it will grow further and become the natural choise for python and gui's.

Using the code below, when the code has run, "tab1" is not selected.
I'm running windows portable installation Kivy-1.9.0-py3.4-win32-x64 and have w8.1
It works fine to select the tab manually.
Maybe .switch_to is not meant to make the tab active, but at least I would assume that this is what it does.
I also made some smaller attempts to see if I could make it selected/active with some of the other methods in TabbedPanel, but could not get it to work.

I decided to skip the "default_tab" (which by the way is preselected also on my computer), since I did not want different ways to assign the tabs.

Is this a bug, or can I get the tab selected another way (not using default tab)?

from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelHeader

class mainw(TabbedPanel):
    def __init__(self, **kwargs):
        super(mainw, self).__init__(**kwargs)

        self.do_default_tab = False
        self.tab_width = 150

        # create the tabs
        tab1 = TabbedPanelHeader(text='tab1')
        self.add_widget(tab1)

        tab2 = TabbedPanelHeader(text='tab2')
        self.add_widget(tab2)

        self.switch_to(tab1) # does not work and also does not throw error...


class tbpApp(App):
     def build(self):
        return mainw()

if __name__ == '__main__':
    tbpApp().run()
@akshayaurora
Copy link
Member

You are inheriting from the widget and trying to add to the widget before it has finished setting up in __init__.

You need to let the widget initiate completely and then add your tabs to it. first tab added is selected by default.

This would be automatically taken care of if you used kv.

Just look at the examples examples/widgets/tabbed*...

@ahed87
Copy link
Author
ahed87 commented Jul 15, 2015

ok, kind of got it, but am still not entirely sure of how to do it in pure python.

Although the "kv-language" seems very easy on the simple examples,I cannot wrap my head around how it works in more complex examples at the moment.
For me it's a deliberate choice not to use the kvl at the moment.
If I don't understand where there is a problem (which I definitely don't if it's done by kvl),
it's kind of hard to fix it on my own as well.And if I'm stuck with the simple examples in kvl
the usability of a tool like kivy falls drastically behind (in my humble opinion)....
So for me at the moment when seriously trying to learn kivy I find it easier todo it in python where at least I think I understand better what's happening.

  From: Akshay Arora <notifications@github.com>

To: kivy/kivy kivy@noreply.github.com
Cc: ahed87 heda87@rocketmail.com
Sent: Thursday, July 9, 2015 9:23 PM
Subject: Re: [kivy] TabbedPanel.switch_to() does not appear to work (#3493)

You are inheriting from the widget and trying to add to the widget before it has finished setting up in init.You need to let the widget initiate completely and then add your tabs to it. first tab added is selected by default.This would be automatically taken care of if you used kv.Just look at the examples examples/widgets/tabbed*... —
Reply to this email directly or view it on GitHub.

@dessant
Copy link
Contributor
dessant commented Jul 15, 2015

@ahed87 this is one way:

from functools import partial

from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelHeader
from kivy.clock import Clock


class mainw(TabbedPanel):
    def __init__(self, **kwargs):
        super(mainw, self).__init__(**kwargs)

        self.do_default_tab = False
        self.tab_width = 150

        # create the tabs
        tab1 = TabbedPanelHeader(text='tab1')
        self.add_widget(tab1)

        tab2 = TabbedPanelHeader(text='tab2')
        self.add_widget(tab2)

        Clock.schedule_once(partial(self.switch, tab1), 0)

    def switch(self, tab, *args):
        self.switch_to(tab)

class tbpApp(App):
     def build(self):
        return mainw()

if __name__ == '__main__':
    tbpApp().run()

If you have further questions, visit our support channels: https://github.com/kivy/kivy#support.

@ahed87
Copy link
Author
ahed87 commented Jul 15, 2015

Great thanks a lot for that working example!

Although it did actually not work with 0 (=next frame) as time on my computer,
When putting 2s it did not work either,
but it did work with 3s callback (I guess that's how long the initiation is on my computer....)

Seeing full examples in work where a particular issue is adressed is for me by far the best way to be able to get a full understanding for what needs to be done in different cases.

PS: I did try once or twice with clock, but never seriously tried also with partial, missed that part

@janssen
Copy link
Contributor
janssen commented Jun 10, 2016

How would we know this by reading the documentation? And why close this? It's still broken for some indeterminate time after you've initialized it, and there's no way to tell when it's "not broken".

@andresbrocco
Copy link
Contributor
andresbrocco commented Jan 17, 2021

How would we know this by reading the documentation? And why close this?

@matham
Copy link
Member
matham commented Jan 22, 2021

Hmm, yeah this needs to be documented.

@matham matham reopened this Jan 22, 2021
@matham matham added Type: Documentation Docs should be added/fixed easy Should be easy to fix labels Jan 22, 2021
@andresbrocco
Copy link
Contributor

Hmm, yeah this needs to be documented.

I'll try to document it as my first contribution to kivy!
@matham, could you instruct me where exactly would be the best place to document it? Would it be in the docstring of the "switch_to()" source code itself?

@matham
Copy link
Member
matham commented Jan 22, 2021

Yeah, in switch_to is a good place!

matham added a commit that referenced this issue Jan 24, 2021
* Fixed reference

Previous reference didn't link to anywhere, and now it links to the
dev-install page.

* Added link for example usage

As discussed in the issue #3493, when calling this method from the
python script, it has to be scheduled to the next clock cycle.

* Update kivy/uix/tabbedpanel.py

Co-authored-by: matham <moiein2000@gmail.com>

Co-authored-by: matham <moiein2000@gmail.com>
hamlet4401 pushed a commit to tytgatlieven/kivy that referenced this issue Jul 3, 2021
* Fixed reference

Previous reference didn't link to anywhere, and now it links to the
dev-install page.

* Added link for example usage

As discussed in the issue kivy#3493, when calling this method from the
python script, it has to be scheduled to the next clock cycle.

* Update kivy/uix/tabbedpanel.py

Co-authored-by: matham <moiein2000@gmail.com>

Co-authored-by: matham <moiein2000@gmail.com>
@Julian-O
Copy link
Contributor
Julian-O commented Dec 3, 2023

Was documented in Jan 2021. Closing as fixed.

@Julian-O Julian-O closed this as completed Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy Should be easy to fix Type: Documentation Docs should be added/fixed
Projects
None yet
Development

No branches or pull requests

7 participants