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

Adding new MGA plugins files to parse also menubar implementation #35

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SET(VERSION_MAJOR "2")
SET(VERSION_MINOR "0")
SET(VERSION_PATCH "2")
SET(VERSION_PATCH "3")
2 changes: 1 addition & 1 deletion package/libyui-bindings.spec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


Name: libyui-bindings
Version: 2.0.2
Version: 2.0.3
Release: 0
Summary: Bindings for libyui
License: LGPL-2.1-only OR LGPL-3.0-only
Expand Down
132 changes: 132 additions & 0 deletions swig/python/examples/menubar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/env python3
# vim: set et ts=4 sw=4:
#coding:utf-8
#############################################################################
#
# mga-dialogs.py - Show mga msg dialog and about dialog.
#
# License: GPLv3
# Author: Angelo Naselli <anaselli@linux.it>
#############################################################################

###########
# imports #
###########
import sys
sys.path.insert(0,'../../../build/swig/python')
import os

import yui

log = yui.YUILog.instance()
log.setLogFileName("/tmp/debug.log")
log.enableDebugLogging( True )
appl = yui.YUI.application()
appl.setApplicationTitle("Show dialogs example")

#################
# class mainGui #
#################
class Info(object):
def __init__(self,title,richtext,text):
self.title=title
self.richtext=richtext
self.text=text

class mainGui():
"""
Main class
"""

def __init__(self):
self.factory = yui.YUI.widgetFactory()
self.mgafactory = yui.YMGAWidgetFactory.getYMGAWidgetFactory(yui.YExternalWidgets.externalWidgetFactory("mga"))
self.dialog = self.factory.createPopupDialog()
mainvbox = self.factory.createVBox(self.dialog)
self.menubar = self.mgafactory.createMenuBar(mainvbox)

#Items must be "disowned"
mItem = yui.YMGAMenuItem("&File")
mItem.this.own(False)
tmi = yui.YMGAMenuItem(mItem, "&New")
tmi.this.own(False)
item = yui.YMGAMenuItem( tmi, "New &1" , "document-new")
item.this.own(False)
item = yui.YMGAMenuItem( tmi, "New &2" , "contact-new")
item.this.own(False)
item = yui.YMenuSeparator(mItem);
item.this.own(False)
item = yui.YMGAMenuItem(mItem, "&Open", "document-open.png")
item.this.own(False)
item = yui.YMenuSeparator(mItem);
item.this.own(False)
item = yui.YMGAMenuItem(mItem, "&Save", "document-save.png")
item.this.own(False)
item = yui.YMGAMenuItem(mItem, "&Save as", "document-save-as")
item.this.own(False)
item = yui.YMenuSeparator(mItem);
item.this.own(False)
self.quitMenu = yui.YMGAMenuItem(mItem, "&Quit", "application-exit")
self.quitMenu.this.own(False)

self.menubar.addItem(mItem)

mItem1 = yui.YMGAMenuItem("&Edit")
self.editMenu = {
'menu' : mItem1,
'undo' : yui.YMGAMenuItem(mItem1, "&Undo", "edit-undo.png"),
'redo' : yui.YMGAMenuItem(mItem1, "&Redo", "edit-redo.png"),
'sep0' : yui.YMenuSeparator(mItem1),
'cut' : yui.YMGAMenuItem(mItem1, "Cu&t", "edit-cut.png"),
'copy' : yui.YMGAMenuItem(mItem1, "&Copy", "edit-copy.png"),
'paste' : yui.YMGAMenuItem(mItem1, "&Paste", "edit-paste.png"),
}
#Items must be "disowned"
for k in self.editMenu.keys():
self.editMenu[k].this.own(False)
self.menubar.addItem(self.editMenu['menu'])

HBox = self.factory.createHBox(mainvbox)
self.aboutbutton = self.factory.createPushButton(HBox,"&About")
self.closebutton = self.factory.createPushButton(self.factory.createRight(HBox), "&Close")


def aboutDialog(self):
dlg = self.mgafactory.createAboutDialog("About menu bar example", "1.0.0", "GPLv3",
"Angelo Naselli", "This simple example shows how a menubar can work using libyui bindings", "")
dlg.show();


def handleevent(self):
"""
Event-handler for the 'widgets' demo
"""
while True:
event = self.dialog.waitForEvent()
eventType = event.eventType()
if eventType == yui.YEvent.CancelEvent:
break
elif (eventType == yui.YEvent.MenuEvent) :
item = event.item()
if (item) :
if item == self.quitMenu :
break
elif (eventType == yui.YEvent.WidgetEvent) :
# widget selected
widget = event.widget()
if (widget == self.closebutton) :
break
elif widget == self.aboutbutton:
self.aboutDialog()

self.dialog.destroy()

if __name__ == "__main__":
main_gui = mainGui()
main_gui.handleevent()

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()

12 changes: 8 additions & 4 deletions swig/python/examples/mga-dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def ask_YesOrNo(self, info):
dlg.setButtonLabel("Yes", yui.YMGAMessageBox.B_ONE)
dlg.setButtonLabel("No", yui.YMGAMessageBox.B_TWO)
dlg.setMinSize(50, 5);
return dlg.show() == yui.YMGAMessageBox.B_ONE
ret_val = dlg.show() == yui.YMGAMessageBox.B_ONE
return ret_val

def aboutDialog(self):
yui.YUI.widgetFactory;
Expand All @@ -74,16 +75,19 @@ def handleevent(self):
while True:
event = self.dialog.waitForEvent()
if event.eventType() == yui.YEvent.CancelEvent:
self.dialog.destroy()
break
if event.widget() == self.closebutton:
info = Info("Quit confirmation", 1, "Are you sure you want to quit?")
info = Info("Quit confirmation", True, "Are you sure you want to quit?")
if self.ask_YesOrNo(info):
self.dialog.destroy()
break
if event.widget() == self.aboutbutton:
self.aboutDialog()

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()

if __name__ == "__main__":
main_gui = mainGui()
main_gui.handleevent()
4 changes: 4 additions & 0 deletions swig/yui.i
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ SWIGEXPORT void Init__yui(void) {
#include "yui/mga/YMGA_CBTable.h"
#include "yui/mga/YMGAMsgBox.h"
#include "yui/mga/YMGAAboutDialog.h"
#include "yui/mga/YMGAMenuItem.h"
#include "yui/mga/YMGAMenuBar.h"
#include "yui/mga/YMGAWidgetExtensionFactory.h"
#endif

Expand Down Expand Up @@ -265,6 +267,8 @@ class Exception;
#if defined(WITH_MGA)
%include yui/mga/YMGA_CBTable.h
%include yui/mga/YMGAAboutDialog.h
%include yui/mga/YMGAMenuItem.h
%include yui/mga/YMGAMenuBar.h
%include yui/mga/YMGAMsgBox.h
%include yui/mga/YMGAWidgetExtensionFactory.h
#endif
Expand Down