How to show and hide QtGui.QGridLayout in PySide - python-2.7

Here I am creating a layout called _grid and putting few labels and slider in the layout .
Now I want this layout to be hide first then onclick I want to show it .
If there is any simple function associated with QtGui.QGridLayout to show and hide.
I googled and found this is available for QWidget by QWidget.hide()
class TimeSlider (QtGui.QVBoxLayout):
def __init__ (self):
QtGui.QVBoxLayout.__init__ (self)
# Put everything in a grid
_grid = QtGui.QGridLayout ()
self.addLayout (_grid)
# Slider limit labels
_grid.addWidget (QtGui.QLabel (''), 0, 0)
_labelLayout = QtGui.QHBoxLayout ()
_grid.addLayout (_labelLayout, 0, 1)
self.lower = QtGui.QLabel ('LOW')
_labelLayout.addWidget (self.lower)
self.higher = QtGui.QLabel ('HIGH')
self.higher.setAlignment (QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
_labelLayout.addWidget (self.higher)
# Slider
_grid.addWidget (QtGui.QLabel (''), 1, 0)
self.sliderBarLayout = QtGui.QHBoxLayout ()
self.sliderBarLayout.setSpacing (0)
_grid.addLayout (self.sliderBarLayout, 1, 1)
self.sliderBarLayout.addWidget (self.leftEndstop)
self.slider = QtGui.QSlider (QtCore.Qt.Horizontal)
self.slider.setTickPosition (QtGui.QSlider.TicksBelow)
self.slider.setTracking (True)
self.slider.setMinimumWidth (40)
self.slider.setPageStep (1)
self.sliderBarLayout.addWidget (self.slider)
self.rightEndstop = RightEndstop (self, self.root)
self.sliderBarLayout.addWidget (self.rightEndstop)

import sys, time
from PyQt4 import QtGui, QtCore
class TimeSlider (QtGui.QVBoxLayout):
def __init__ (self):
QtGui.QVBoxLayout.__init__ (self)
# Put everything in a grid
_manLayout = QtGui.QVBoxLayout ()
self._frame = QtGui.QFrame();
_manLayout.addWidget(self._frame)
_grid = QtGui.QGridLayout (self._frame)
# Slider limit labels
_grid.addWidget (QtGui.QLabel (''), 0, 0)
_labelLayout = QtGui.QHBoxLayout ()
_grid.addLayout (_labelLayout, 0, 1)
self.lower = QtGui.QLabel ('LOW')
_labelLayout.addWidget (self.lower)
self.higher = QtGui.QLabel ('HIGH')
self.higher.setAlignment (QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
_labelLayout.addWidget (self.higher)
# Slider
_grid.addWidget (QtGui.QLabel (''), 1, 0)
self.sliderBarLayout = QtGui.QHBoxLayout ()
self.sliderBarLayout.setSpacing (0)
_grid.addLayout (self.sliderBarLayout, 1, 1)
# self.sliderBarLayout.addWidget (self.leftEndstop)
self.slider = QtGui.QSlider (QtCore.Qt.Horizontal)
self.slider.setTickPosition (QtGui.QSlider.TicksBelow)
self.slider.setTracking (True)
self.slider.setMinimumWidth (40)
self.slider.setPageStep (1)
self.sliderBarLayout.addWidget (self.slider)
self._frame.setLayout(_grid)
self.addLayout (_manLayout)
#self.rightEndstop = RightEndstop (self, self.root)
# self.sliderBarLayout.addWidget (self.rightEndstop)
def show(self):
self._frame.show()
def hide(self):
self._frame.hide()
def isHidden(self):
return self._frame.isHidden()
class NewTimeSliderTest(QtGui.QWidget):
def __init__(self, parent=None, total=20):
super(NewTimeSliderTest, self).__init__(parent)
self.newTimeSlider = TimeSlider()
self.resize(841, 474)
self.newTimeSlider.hide()
self.button = QtGui.QPushButton('Show/Hide')
self.button.clicked.connect(self.handleButton)
main_layout = QtGui.QGridLayout()
main_layout.addWidget(self.button, 0, 0)
main_layout.addLayout(self.newTimeSlider, 0, 1)
self.setLayout(main_layout)
self.setWindowTitle('Test')
self._active = False
def handleButton(self):
#self.newTimeSlider.show()
isHidden = self.newTimeSlider.isHidden()
if isHidden:
self.newTimeSlider.show()
else:
self.newTimeSlider.hide()
app = QtGui.QApplication(sys.argv)
bar = NewTimeSliderTest(total=101)
bar.show()
sys.exit(app.exec_())
How about this ?
Any time you can all like this.
self.newTimeSlider.show()
or
self.newTimeSlider.hide()

Related

how to get the all products in dictionary in each iteration of the for loop

Here is my sample code i want to show all my products in widget so i took as dictionary in for loop, but i am not getting the all products in the dictionary last product is overwrite the previous one.Can any one please help me where i did a mistake.Thank you in advance.
Given below is my code:
products_list = {"Givers":{"price": 140,"Quantity":100,"Discount":0,"Total_price":14000,"Paid_amount":14000},"New_Member":{"price": 1200,"Quantity":10,"Discount":0,"Total_price":12000,"Paid_amount":12000},"YearMembers_Ribbons":{"price": 110,"Quantity":0,"Discount":0,"Total_price":1100,"Paid_amount":1100}}
for key,value in products_list.items():
self.widget_orders_info = QtGui.QWidget()
self.widget_orders_info.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.widget_orders_info.setStyleSheet("QWidget {background-color: blue;color: white;}")
self.order_info_vbox = QtGui.QVBoxLayout(self.widget_orders_info)
self.title_hbox = QtGui.QHBoxLayout()
self.orderdetail_label = QtGui.QLabel("Order_Details(22HRS)",alignment =QtCore.Qt.AlignCenter,objectName="small")
self.close_pushbtn = QtGui.QPushButton("Close")
self.title_hbox.addWidget(self.orderdetail_label)
self.title_hbox.addStretch()
self.title_hbox.addWidget(self.close_pushbtn)
self.close_pushbtn.clicked.connect(self.widget_orders_info.close)
self.order_info_vbox.addLayout(self.title_hbox)
self.line = QtGui.QFrame(frameShape=QtGui.QFrame.HLine)
self.order_info_vbox.addWidget(self.line)
self.order_hbox = QtGui.QHBoxLayout()
keys = value.keys()
values = value.values()
self.line1 = QtGui.QFrame(frameShape=QtGui.QFrame.VLine)
self.order_hbox.addWidget(self.line1)
self.items_Vboxlay = QtGui.QVBoxLayout()
self.vbox2 = QtGui.QVBoxLayout()
self.item_label = QtGui.QLabel(str(key), objectName="small")
self.vbox2.addWidget(self.item_label)
self.hbox1 = QtGui.QHBoxLayout()
self.price = QtGui.QLabel(keys[1]+": " +str(values[1]))
self.qnty =QtGui.QLabel(keys[4]+": "+str(values[4]))
self.discount = QtGui.QLabel(keys[0]+ ": " +u'\u20B9 '+ str(values[0]))
self.totalprice =QtGui.QLabel(keys[2]+ ": "+u'\u20B9 '+ str(values[2]))
self.paid = QtGui.QLabel(keys[3] + ": "+u'\u20B9 '+ str(values[3]))
self.hbox1.addWidget(self.price)
self.hbox1.addWidget(self.qnty)
self.hbox1.addWidget(self.discount)
self.hbox1.addWidget(self.totalprice)
self.hbox1.addWidget(self.paid)
self.line4 = QtGui.QFrame();self.line4.setFrameShape(QtGui.QFrame.HLine)
self.vbox2.addLayout(self.hbox1)
self.vbox2.addLayout(self.h2box)
self.vbox2.addWidget(self.line1)
self.items_Vboxlay.addLayout(self.vbox2)
self.order_hbox.addLayout(self.items_Vboxlay)
self.order_info_vbox.addLayout(self.order_hbox)
self.add_hbox = QtGui.QHBoxLayout()
self.print_btn = QtGui.QPushButton("Print")
self.print_btn.clicked.connect(partial(self.print_function,type))
self.add_hbox.setAlignment(QtCore.Qt.AlignCenter)
self.add_hbox.addWidget(self.print_btn)
self.order_info_vbox.addLayout(self.add_hbox)
self.widget_orders_info.show()
self.widget_orders_info.resize(500,300)
Sorry, I have Python-3 andPyQt5. I think my example should help you.
import sys
from functools import partial
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Window(QMainWindow):
def __init__(self):
super().__init__()
products_list = {
"Givers":{
"price": 140,
"Quantity": 100,
"Discount": 0,
"Total_price":14000,
"Paid_amount":14000},
"New_Member":{
"price": 1200,
"Quantity": 10,
"Discount": 0,
"Total_price":12000,
"Paid_amount":12000},
"YearMembers_Ribbons":{
"price": 110,
"Quantity": 0,
"Discount": 0,
"Total_price":1100,
"Paid_amount":1100}
}
# *1 +++
self.widget_orders_info = QWidget()
self.widget_orders_info.setWindowFlags(Qt.FramelessWindowHint)
self.widget_orders_info.setStyleSheet("QWidget {background-color: blue;color: white;}")
self.order_info_vbox = QVBoxLayout(self.widget_orders_info)
self.title_hbox = QHBoxLayout()
self.orderdetail_label = QLabel("Order_Details(22HRS)",
alignment=Qt.AlignCenter,
objectName="small")
self.close_pushbtn = QPushButton("Close")
self.title_hbox.addWidget(self.orderdetail_label)
self.title_hbox.addStretch()
self.title_hbox.addWidget(self.close_pushbtn)
self.close_pushbtn.clicked.connect(self.widget_orders_info.close)
self.order_info_vbox.addLayout(self.title_hbox)
self.line = QFrame(frameShape=QFrame.HLine)
self.order_info_vbox.addWidget(self.line)
self.order_hbox = QHBoxLayout()
# *2 +++
self.line1 = QFrame(frameShape = QFrame.VLine)
self.order_hbox.addWidget(self.line1)
self.items_Vboxlay = QVBoxLayout()
self.vbox2 = QVBoxLayout()
for key, value in products_list.items():
# self.widget_orders_info = QWidget()
# ...
# transferred from the `for` loop, see `* 1 +++`
# ...
# self.order_hbox = QHBoxLayout()
# keys = value.keys()
# values = value.values()
keys = [ vk for vk in value.keys()]
values = [ vv for vv in value.values()]
# self.line1 = QFrame(frameShape = QFrame.VLine)
# ...
# transferred from the `for` loop, see `* 2 +++`
# ...
# self.vbox2 = QVBoxLayout()
self.item_label = QLabel(str(key), objectName="small")
self.vbox2.addWidget(self.item_label)
self.hbox1 = QHBoxLayout()
self.price = QLabel(keys[1] + ": " + str(values[1]))
self.qnty = QLabel(keys[4] + ": " + str(values[4]))
self.discount = QLabel(keys[0] + ": " + u'\u20B9 ' + str(values[0]))
self.totalprice = QLabel(keys[2] + ": " + u'\u20B9 ' + str(values[2]))
self.paid = QLabel(keys[3] + ": " + u'\u20B9 ' + str(values[3]))
self.hbox1.addWidget(self.price)
self.hbox1.addWidget(self.qnty)
self.hbox1.addWidget(self.discount)
self.hbox1.addWidget(self.totalprice)
self.hbox1.addWidget(self.paid)
self.line4 = QFrame()
self.line4.setFrameShape(QFrame.HLine)
self.vbox2.addLayout(self.hbox1)
# self.vbox2.addLayout(self.h2box) # ??????????????????????????
self.vbox2.addWidget(self.line1)
self.items_Vboxlay.addLayout(self.vbox2)
self.order_hbox.addLayout(self.items_Vboxlay)
self.order_info_vbox.addLayout(self.order_hbox)
self.add_hbox = QHBoxLayout()
self.print_btn = QPushButton("Print")
self.print_btn.clicked.connect(partial(self.print_function, type))
self.add_hbox.setAlignment(Qt.AlignCenter)
self.add_hbox.addWidget(self.print_btn)
self.order_info_vbox.addLayout(self.add_hbox)
self.widget_orders_info.show()
self.widget_orders_info.resize(500,300)
def print_function(self, t):
print("--- t ->", t)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
w = Window()
# w.show()
sys.exit(app.exec_())

How to draw a line between the widgets in Qscrollarea using pyqt4

Here is my code i created multiple widget in qscrollarea. In between the each widget i want to draw a line.Can any one please tell me how can i draw line in between the each widget of the scroll area.
self.mainw = QtGui.QWidget()
self.scrollArea_left.setWidget(self.mainw)
self.ordersvbox = QtGui.QGridLayout(self.mainw)
self.w1 = QtGui.QWidget()
self.v1 = QtGui.QVBoxLayout(spacing=0)
self.v1.setContentsMargins(0, 0, 0, 0)
self.w1.setLayout(self.v1)
self.h1 = QtGui.QHBoxLayout()
self.l1 = QtGui.QLabel("#A")
self.lprogress = QtGui.QLabel("Porgress")
self.lamount = QtGui.QLabel("200 Rs")
self.items_count = QtGui.QLabel("2 items")
self.h1.addWidget(self.l1)
self.h1.addWidget(self.lprogress)
self.h1.addWidget(self.lamount)
self.v1.addLayout(self.h1)
self.v1.addWidget(self.items_count)
self.ordersvbox.addWidget(self.w1,0,0)
self.w2 = QtGui.QWidget()
self.v2 = QtGui.QVBoxLayout(self.w2)
self.h2 = QtGui.QHBoxLayout()
self.l2 = QtGui.QLabel("#B")
self.lprogress2 = QtGui.QLabel("x")
self.lamount2 = QtGui.QLabel("300 RS")
self.items_count2 = QtGui.QLabel(" 2 items")
self.h2.addWidget(self.l2)
self.h2.addWidget(self.lprogress2)
self.h2.addWidget(self.lamount2)
self.v2.addLayout(self.h2)
self.v2.addWidget(self.items_count2)
self.ordersvbox.addWidget(self.w2,1,0)
self.w3 = QtGui.QWidget()
self.v3 = QtGui.QVBoxLayout(self.w3)
self.h3 = QtGui.QHBoxLayout()
self.l3 = QtGui.QLabel("#C")
self.lprogress3 = QtGui.QLabel("z")
self.lamount3 = QtGui.QLabel("200 RS")
self.items_count3 = QtGui.QLabel(" 2 items")
self.h3.addWidget(self.l3)
self.h3.addWidget(self.lprogress3)
self.h3.addWidget(self.lamount3)
self.v3.addLayout(self.h3)
self.v3.addWidget(self.items_count3)
self.ordersvbox.addWidget(self.w3,2,0)

replacing a new interface with old one in tkinter

I've created a class that has a function called mainScreen(). It simply prints the main screen with two buttons on it. If you press any button, it must go to another function called signup(). I want to clear the whole frame and create new widgets but I can't clear the widgets
class graphics:
def __init__(self, master):
self.root = master
def mainscreen(self):
helv36 = tkFont.Font(family='Century Gothic', size=20)
mainFrame = Frame(self.root)
mainFrame.config(relief='sunken', width=1280, height=720, bg='light
blue')
mainFrame.pack(expand='yes', fill='both')
inButton = Button(mainFrame, text = "Sign up", bd = 10, relief =
GROOVE, font = helv36)
inButton.bind("<Button-1>", self.signup)
inButton.place(bordermode = OUTSIDE, width =160, height = 60, x =
600, y = 300)
upButton = Button(mainFrame, text = "Sign in", bd = 10, relief =
GROOVE, font = helv36)
upButton.bind("<Button-1>", self.signup)
upButton.place(bordermode = OUTSIDE, width =160, height = 60, x =
600, y = 400)
mainFrame.pack_propagate(FALSE)
self.root.mainloop()
def signup(self,event):
signUpShow = Frame(self.root)
signUpShow.config(relief='sunken', width=1280, height=720, bg='light
yellow')
signUpShow.pack(expand='yes', fill='both')
You __init__ needs to have its code indented and it needs a call to mainscreen. The solution to mainFrame being local within mainscreen is to make it also an attribute.
self.mainframe = mainFrame = Frame(self.root)
Then you can access self.mainframe within signup.

How to make a toggle cell in GTK TreeView editable by using Glade?

I'm using Glade 3.20 but i don't known how to make a toggle column editable. I do not see any options.
screenshots
Please help me!
Look at this CellRendererToggle usage example (in python).
The source (in case the link breaks someday):
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class CellRendererToggleWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="CellRendererToggle Example")
self.set_default_size(200, 200)
self.liststore = Gtk.ListStore(str, bool, bool)
self.liststore.append(["Debian", False, True])
self.liststore.append(["OpenSuse", True, False])
self.liststore.append(["Fedora", False, False])
treeview = Gtk.TreeView(model=self.liststore)
renderer_text = Gtk.CellRendererText()
column_text = Gtk.TreeViewColumn("Text", renderer_text, text=0)
treeview.append_column(column_text)
renderer_toggle = Gtk.CellRendererToggle()
renderer_toggle.connect("toggled", self.on_cell_toggled)
column_toggle = Gtk.TreeViewColumn("Toggle", renderer_toggle, active=1)
treeview.append_column(column_toggle)
renderer_radio = Gtk.CellRendererToggle()
renderer_radio.set_radio(True)
renderer_radio.connect("toggled", self.on_cell_radio_toggled)
column_radio = Gtk.TreeViewColumn("Radio", renderer_radio, active=2)
treeview.append_column(column_radio)
self.add(treeview)
def on_cell_toggled(self, widget, path):
self.liststore[path][1] = not self.liststore[path][1]
def on_cell_radio_toggled(self, widget, path):
selected_path = Gtk.TreePath(path)
for row in self.liststore:
row[2] = (row.path == selected_path)
win = CellRendererToggleWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

python 2.7 gtk 3+ listbox connect print active row

I am just downloaded gtk3+, and I'm working through some sample code from:
https://python-gtk-3-tutorial.readthedocs.io/en/latest/layout.html#listbox
Here is the sample code:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class ListBoxRowWithData(Gtk.ListBoxRow):
def __init__(self, data):
super(Gtk.ListBoxRow, self).__init__()
self.data = data
self.add(Gtk.Label(data))
class ListBoxWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="ListBox Demo")
self.set_border_width(10)
box_outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.add(box_outer)
listbox = Gtk.ListBox()
listbox.set_selection_mode(Gtk.SelectionMode.NONE)
box_outer.pack_start(listbox, True, True, 0)
row = Gtk.ListBoxRow()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
row.add(hbox)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
hbox.pack_start(vbox, True, True, 0)
label1 = Gtk.Label("Automatic Date & Time", xalign=0)
label2 = Gtk.Label("Requires internet access", xalign=0)
vbox.pack_start(label1, True, True, 0)
vbox.pack_start(label2, True, True, 0)
switch = Gtk.Switch()
switch.props.valign = Gtk.Align.CENTER
hbox.pack_start(switch, False, True, 0)
listbox.add(row)
row = Gtk.ListBoxRow()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
row.add(hbox)
label = Gtk.Label("Enable Automatic Update", xalign=0)
check = Gtk.CheckButton()
hbox.pack_start(label, True, True, 0)
hbox.pack_start(check, False, True, 0)
listbox.add(row)
row = Gtk.ListBoxRow()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
row.add(hbox)
label = Gtk.Label("Date Format", xalign=0)
combo = Gtk.ComboBoxText()
combo.insert(0, "0", "24-hour")
combo.insert(1, "1", "AM/PM")
hbox.pack_start(label, True, True, 0)
hbox.pack_start(combo, False, True, 0)
listbox.add(row)
listbox_2 = Gtk.ListBox()
items = 'This is a sorted ListBox Fail'.split()
for item in items:
listbox_2.add(ListBoxRowWithData(item))
def sort_func(row_1, row_2, data, notify_destroy):
return row_1.data.lower() > row_2.data.lower()
def filter_func(row, data, notify_destroy):
return False if row.data == 'Fail' else True
listbox_2.set_sort_func(sort_func, None, False)
listbox_2.set_filter_func(filter_func, None, False)
listbox_2.connect('row-activated', lambda widget, row: print(row.data))
box_outer.pack_start(listbox_2, True, True, 0)
listbox_2.show_all()
win = ListBoxWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
I get an error of "incorrect syntax" in
listbox_2.connect('row-activated', lambda widget, row: print(row.data))
This is straight from the sample code, and I'm completely at a loss here. Please help.
Other way for your problem instead of import print function is use repr()
listbox_2.connect('row-activated', lambda widget, row: repr(row.data))
You can use this way too:
def on_row_activated(listbox, row):
print(row.data)
listbox_2.connect('row-activated', on_row_activated)
References: https://github.com/ailtonbsj/course-python-gtk3/blob/master/listBoxLayout.py
https://lazka.github.io/pgi-docs/Gtk-3.0/classes/ListBox.html#Gtk.ListBox.signals.row_activated