Created
January 19, 2021 15:47
-
-
Save anaselli/d9be54e8ca3f49c99834c46b383d6ba6 to your computer and use it in GitHub Desktop.
YMGA_CBTable usage python example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Example that shows how to fill a checkboxes table | |
# | |
# Copyright information | |
# | |
# Author: Angelo Naselli <[email protected]> | |
# | |
# License | |
# | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 2 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
import sys | |
sys.path.insert(0,'../../../build/swig/python') | |
import yui | |
factory = yui.YUI.widgetFactory() | |
MGAPlugin = "mga" | |
mgaFact = yui.YExternalWidgets.externalWidgetFactory(MGAPlugin) | |
extfactory = yui.YMGAWidgetFactory.getYMGAWidgetFactory(mgaFact) | |
dialog = factory.createMainDialog() | |
VBox = factory.createVBox(dialog) | |
checkboxed = True | |
yTableHeader = yui.YCBTableHeader() | |
yTableHeader.addColumn("Priority", not checkboxed, yui.YAlignBegin ) | |
yTableHeader.addColumn("Enabled", checkboxed, yui.YAlignCenter ) | |
yTableHeader.addColumn("Autorefresh", checkboxed, yui.YAlignCenter ) | |
yTableHeader.addColumn("Name", not checkboxed, yui.YAlignBegin ) | |
yTableHeader.addColumn("Service", not checkboxed, yui.YAlignBegin ) | |
yTableHeader.addColumn("Url", not checkboxed, yui.YAlignBegin ) | |
#myTableMinSize = factory.createMinSize(VBox, 10, 12) | |
#myTable = extfactory.createCBTable(myTableMinSize, yTableHeader) | |
#yTableHeader.this.own(False) | |
myTable = extfactory.createCBTable(VBox, yTableHeader) | |
myTable.setNotify( True ) | |
Text = factory.createLabel(VBox, "---------------------------------------------------------------------------------------------"); | |
HBox = factory.createHBox(VBox) | |
myChange = factory.createPushButton(HBox, "Change content") | |
myOK = factory.createPushButton(HBox, "OK") | |
data = [ | |
[ | |
{'p': "99 (Default)", 'en' : True, 'ar': True, 'n': "15.1", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "99 (Default)", 'en' : False, 'ar': True, 'n': "CA", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "99 (Default)", 'en' : False, 'ar': True, 'n': "Main Repository 15.1", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "99 (Default)", 'en' : True, 'ar': True, 'n': "Main Update Repository", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "99 (Default)", 'en' : True, 'ar': True, 'n': "Non-OSS Repository", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "99 (Default)", 'en' : True, 'ar': True, 'n': "Packman Repository", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "99 (Default)", 'en' : False, 'ar': True, 'n': "Source Repository", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "99 (Default)", 'en' : False, 'ar': True, 'n': "Source Repository (Non-OSS)", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
], | |
[ | |
{'p': "88", 'en' : False, 'ar': False, 'n': "15.1", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "88", 'en' : False, 'ar': True, 'n': "CA", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "88", 'en' : True, 'ar': False, 'n': "Main Repository 15.1", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "88", 'en' : True, 'ar': True, 'n': "Main Update Repository", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "88", 'en' : True, 'ar': True, 'n': "Non-OSS Repository", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "88", 'en' : True, 'ar': True, 'n': "Packman Repository", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "88", 'en' : False, 'ar': True, 'n': "Source Repository", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
{'p': "88", 'en' : False, 'ar': True, 'n': "Source Repository (Non-OSS)", 's':"", 'u': "http://download.opensuse.org/xxx"}, | |
] | |
] | |
items = [] | |
for d in data[0]: | |
# Here we show how to add YCBTableCell one by one (as lable or bool) | |
item = yui.YCBTableItem() | |
item.addCell( d['p'] ) | |
item.addCell( d['en'] ) | |
item.addCell( d['ar'] ) | |
item.addCell( d['n'] ) | |
item.addCell( d['s'] ) | |
item.addCell( d['u'] ) | |
item.this.own(False) # comment this to have a crash | |
items.append(item) | |
ic = yui.YItemCollection(items) | |
myTable.addItems(ic) | |
db = 0 | |
while (True): | |
event = dialog.waitForEvent() | |
eventType = event.eventType() | |
if (eventType == yui.YEvent.CancelEvent): | |
break | |
elif (eventType == yui.YEvent.MenuEvent): | |
break | |
elif (eventType == yui.YEvent.WidgetEvent): | |
widget = event.widget() | |
if (widget == myOK) : | |
#### QUIT | |
break | |
elif (widget == myChange) : | |
db = (db + 1) % 2 | |
items = [] | |
for d in data[db]: | |
## Here we show how to use YCBTableItem(YCBTableCell,...) | |
## NOTE that libyui-bindings needs to add cell_X as disown to work, so | |
## the workaround now is to disown them as follow and then pass the list | |
## to YCBTableItem | |
cells = list([ | |
yui.YCBTableCell( d['p'] ), | |
yui.YCBTableCell( d['en'] ), | |
yui.YCBTableCell( d['ar'] ), | |
yui.YCBTableCell( d['n'] ), | |
yui.YCBTableCell( d['s'] ), | |
yui.YCBTableCell( d['u'] ) | |
]) | |
for cell in cells: | |
cell.this.own(False) | |
item = yui.YCBTableItem( *cells ) | |
## NOTE next commented code is still valid | |
#item = yui.YCBTableItem() | |
#item.addCell( d['p'] ) | |
#item.addCell( d['en'] ) | |
#item.addCell( d['ar'] ) | |
#item.addCell( d['n'] ) | |
#item.addCell( d['s'] ) | |
#item.addCell( d['u'] ) | |
item.this.own(False) | |
items.append(item) | |
itemCollection = yui.YItemCollection(items) | |
myTable.startMultipleChanges() | |
# cleanup old changed items since we are removing all of them | |
myTable.setChangedItem(None) | |
myTable.deleteAllItems() | |
myTable.addItems(itemCollection) | |
myTable.doneMultipleChanges() | |
elif (widget == myTable) : | |
wEvent = yui.toYWidgetEvent(event) | |
if (wEvent.reason() == yui.YEvent.ValueChanged) : | |
changedItem = myTable.changedItem() | |
if changedItem: | |
cell = changedItem.cellChanged() | |
if cell: | |
col = cell.column() | |
s = "%s %s %s"%(changedItem.cell(3).label(), myTable.header(col), cell.checked()) | |
Text.setValue(s) | |
dialog.destroy() | |
yui.YDialog.deleteAllDialogs() | |
# next line seems to be a workaround to prevent the qt-app from crashing | |
# see https://github.com/libyui/libyui-qt/issues/41 | |
yui.YUILoader.deleteUI() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment