Reputation: 2141
I'm doing a little python plasmoid that deals with remote resources. Here's the code : glpoid
It offers a view of tickets (the default one), a view that let the user filling and sending a new ticket, and a last one to see a ticket detail...
My problem is that i don't know how to "close" the current layout when i'm passing to another view (or make it disappear).
For each layout, i define items that i add to the layout definition and last i display the new layout :
Initially, i display the default view with self.view_tickets_ui(). Each layout is definied in name_ui() methods which each redefine the layout and pass it to the applet.
To resume it's defined like this:
class GLPIApplet(plasmascript.Applet):
def __init__(self,parent,args=None):
plasmascript.Applet.__init__(self,parent)
def init(self):
self.setHasConfigurationInterface(False)
self.setAspectRatioMode(Plasma.Square)
self.resize(400,650)
# new ticket button
self.new = Plasma.PushButton()
self.new.setText('Nouveau Ticket')
self.connect(self.new, SIGNAL('clicked()'), self.new_ticket_ui)
# refresh button
self.refresh = Plasma.PushButton()
self.refresh.setText('Rafraichir')
self.connect(self.refresh, SIGNAL('clicked()'), self.view_tickets_ui)
# initialize
self.view_tickets_ui()
def view_tickets_ui(self, message=None):
# layout of ticket view
self.layout = QGraphicsLinearLayout(Qt.Vertical)
self.layout.itemSpacing(3)
self.layout.addItem(self.new)
self.view_tickets()
self.layout.addItem(self.refresh)
self.applet.setLayout(self.layout)
def new_ticket_ui(self, message=None):
# layout of a new ticket
self.layout = QGraphicsLinearLayout(Qt.Vertical)
self.layout.itemSpacing(3)
message_label = Plasma.Label()
message_label.setText('the message:')
self.layout.addItem(message_label)
self.applet.setLayout(self.layout)
Here init just defines some buttons, and then call view_tickets_ui() that put some items and display the layout. If i call new_ticket_ui() after, it will add elements to the current layout... so both are displayed on the same place.
How can i manage that please??
Upvotes: 1
Views: 708
Reputation: 4933
You could use a Plasma.TabBar
with hidden tabs and switch between them, as mentioned on IRC. Connect the clicked
signals to slots that switch among tabs and everything should be fine.
Also, a note on style: you should use the new signal/slot API whenever possible:
self.connect(self.refresh, SIGNAL('clicked()'), self.view_tickets_ui)
should become
self.refresh.clicked.connect(self.view_tickets_ui).
Upvotes: 1