Skip to content

Commit

Permalink
Merge pull request #3 from shaggyz/issue-2-python3-and-qt5-support
Browse files Browse the repository at this point in the history
Port to python3 + Qt5.
  • Loading branch information
shaggyz authored Jun 15, 2020
2 parents c466644 + 9c04e4b commit 6c07eb7
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 292 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package manager like: apt-get, emerge, rpm, yum, etc.

On Debian systems all dependencies can be installed through apt-get:

- python-setuptools
- python-qt4
- python-lxml
- python3-setuptools
- python3-pyqt5
- python3-lxml


Installation:
Expand Down Expand Up @@ -56,14 +56,13 @@ The development still active there are a few features not yet implemented:
- [X] Open menu file via menu
- [X] Save as.. a menu file via menu
- [X] New menu file via menu
- [ ] Port to python3 and Qt5
- [ ] Pipe-menus
- [ ] Links on menu
- [ ] Locale / Internationalization
- [X] Port to python3 and Qt5
- [ ] Refactor the whole thing.
- [ ] Pipe-menus?
- [ ] Links on menu?
- [ ] Debian package

If you find an error/bug (for sure) on this program please report it on github project site:
https://github.com/shaggyz/obmenu-qt (in the issue tracker)
> 7 years later note: I just ported this to python3 and Qt5, and... OMG this needs a major refactor :poop:


17 changes: 8 additions & 9 deletions ob_menu_qt/lib/obmenuxml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from lxml import etree
import copy

Expand Down Expand Up @@ -31,8 +30,8 @@ def load_xml(self):
self.menu = root[0]
return True

except (IOError, Exception), e:
print e
except (IOError, Exception) as e:
print(e)
return False

def new_file(self):
Expand All @@ -59,13 +58,13 @@ def get_tree(self):

def get_root(self):
"""
Return the root xml element: <openbox_menu>
Return the root xml element: <openbox_menu>
"""
root = self.tree.getroot()

if len(root) < 1:
raise Exception("Invalid menu")

return root

def get_menu(self):
Expand Down Expand Up @@ -97,7 +96,7 @@ def edit_item(self, type_, parent_id=None, index=0, label=None, action=None, exe
Edit a menu item
"""
if "separator" == type_:
return
return

item = self._get_item(type_, index, parent_id)

Expand Down Expand Up @@ -165,7 +164,7 @@ def _get_item_element(self, element_name, item):

def save_menu(self, file_path=None):
"""
Saves the current xml loaded on memory to a file
Saves the current xml loaded on memory to a file
If file file path is none the current file will be overwritten
"""
try:
Expand All @@ -174,8 +173,8 @@ def save_menu(self, file_path=None):

self.tree.write(file_path, pretty_print=True, xml_declaration=True, encoding="utf-8")
return True
except Exception, e:
print e
except Exception as e:
print(e)
return False

def add_item(self, label, execute_, action="Execute", parent_id="root-menu", index=0):
Expand Down
27 changes: 14 additions & 13 deletions ob_menu_qt/ob_menu_qt.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#!/usr/bin/env python3

import sys
import os
import argparse
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QStyle
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtWidgets import QStyle

from .ui.main import UiMainWindow

class ObMenuQt(object):
"""
Main program static bootstrap
"""
VERSION = "1.0"


VERSION="1.1"

def __init__(self):
"""
Initial configuration
"""
self.file = None

# argument parser
parser = argparse.ArgumentParser(prog="obmenu-qt",
description="Openbox menu editor based on QT4",
epilog="For more info visit: https://github.com/shaggyz/obmenu-qt",
version=self.VERSION)

parser = argparse.ArgumentParser(
prog="obmenu-qt",
description="Openbox menu editor based on QT4",
epilog="For more info visit: https://github.com/shaggyz/obmenu-qt",
)

# arguments
parser.add_argument("-f", "--file", help="Load this menu file on start")
arguments = parser.parse_args()
Expand All @@ -38,7 +39,7 @@ def start(self):
"""
Starts the main window
"""
QTApp = QtGui.QApplication(sys.argv)
QTApp = QtWidgets.QApplication(sys.argv)

app_dir = os.path.dirname(os.path.realpath(__file__))
icon_dir = app_dir + os.path.sep + "icons" + os.path.sep
Expand All @@ -64,4 +65,4 @@ def main():
Static application entry poiny
"""
if __name__ == "__main__":
main()
main()
48 changes: 25 additions & 23 deletions ob_menu_qt/ui/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,35 @@
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from PyQt5 import QtCore, QtGui, QtWidgets

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s

def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
return QtWidgets.QApplication.translate(context, text, disambig)

class Ui_frmAbout(object):
def setupUi(self, frmAbout):
frmAbout.setObjectName(_fromUtf8("frmAbout"))
frmAbout.resize(608, 325)
self.verticalLayout = QtGui.QVBoxLayout(frmAbout)
self.verticalLayout = QtWidgets.QVBoxLayout(frmAbout)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.verticalLayout_2 = QtGui.QVBoxLayout()
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.label = QtGui.QLabel(frmAbout)
self.label = QtWidgets.QLabel(frmAbout)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(12)
Expand All @@ -44,36 +46,36 @@ def setupUi(self, frmAbout):
self.label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout.addWidget(self.label)
self.label_10 = QtGui.QLabel(frmAbout)
self.label_10 = QtWidgets.QLabel(frmAbout)
self.label_10.setLayoutDirection(QtCore.Qt.LeftToRight)
self.label_10.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_10.setObjectName(_fromUtf8("label_10"))
self.horizontalLayout.addWidget(self.label_10)
self.lblVersion = QtGui.QLabel(frmAbout)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
self.lblVersion = QtWidgets.QLabel(frmAbout)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lblVersion.sizePolicy().hasHeightForWidth())
self.lblVersion.setSizePolicy(sizePolicy)
self.lblVersion.setObjectName(_fromUtf8("lblVersion"))
self.horizontalLayout.addWidget(self.lblVersion)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.line = QtGui.QFrame(frmAbout)
self.line.setFrameShape(QtGui.QFrame.HLine)
self.line.setFrameShadow(QtGui.QFrame.Sunken)
self.line = QtWidgets.QFrame(frmAbout)
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName(_fromUtf8("line"))
self.verticalLayout_2.addWidget(self.line)
self.label_2 = QtGui.QLabel(frmAbout)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
self.label_2 = QtWidgets.QLabel(frmAbout)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
self.label_2.setSizePolicy(sizePolicy)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.verticalLayout_2.addWidget(self.label_2)
spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem)
self.label_7 = QtGui.QLabel(frmAbout)
self.label_7 = QtWidgets.QLabel(frmAbout)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(12)
Expand All @@ -83,13 +85,13 @@ def setupUi(self, frmAbout):
self.label_7.setFont(font)
self.label_7.setObjectName(_fromUtf8("label_7"))
self.verticalLayout_2.addWidget(self.label_7)
self.label_8 = QtGui.QLabel(frmAbout)
self.label_8 = QtWidgets.QLabel(frmAbout)
self.label_8.setOpenExternalLinks(True)
self.label_8.setObjectName(_fromUtf8("label_8"))
self.verticalLayout_2.addWidget(self.label_8)
spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem1)
self.label_3 = QtGui.QLabel(frmAbout)
self.label_3 = QtWidgets.QLabel(frmAbout)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(12)
Expand All @@ -98,13 +100,13 @@ def setupUi(self, frmAbout):
self.label_3.setFont(font)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.verticalLayout_2.addWidget(self.label_3)
self.label_4 = QtGui.QLabel(frmAbout)
self.label_4 = QtWidgets.QLabel(frmAbout)
self.label_4.setOpenExternalLinks(True)
self.label_4.setObjectName(_fromUtf8("label_4"))
self.verticalLayout_2.addWidget(self.label_4)
spacerItem2 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem2)
self.label_5 = QtGui.QLabel(frmAbout)
self.label_5 = QtWidgets.QLabel(frmAbout)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(12)
Expand All @@ -113,7 +115,7 @@ def setupUi(self, frmAbout):
self.label_5.setFont(font)
self.label_5.setObjectName(_fromUtf8("label_5"))
self.verticalLayout_2.addWidget(self.label_5)
self.label_6 = QtGui.QLabel(frmAbout)
self.label_6 = QtWidgets.QLabel(frmAbout)
self.label_6.setOpenExternalLinks(True)
self.label_6.setObjectName(_fromUtf8("label_6"))
self.verticalLayout_2.addWidget(self.label_6)
Expand Down
10 changes: 4 additions & 6 deletions ob_menu_qt/ui/aboutwidget.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# -*- coding: utf-8 -*-

from PyQt4 import QtGui
from PyQt5 import QtGui, QtWidgets
import os

from ob_menu_qt.ui.about import Ui_frmAbout


class ObAboutWidget(Ui_frmAbout, QtGui.QDialog):
class ObAboutWidget(Ui_frmAbout, QtWidgets.QDialog):
"""
About widget container
"""
def __init__(self, icon_path):
"""
Constructs the about window
"""
super(QtGui.QDialog, self).__init__()
super(QtWidgets.QDialog, self).__init__()

self.setupUi(self)
self.icon_path = icon_path
Expand All @@ -26,4 +24,4 @@ def set_version(self, version):
"""
Sets the program version
"""
self.lblVersion.setText(version)
self.lblVersion.setText(version)
Loading

0 comments on commit 6c07eb7

Please sign in to comment.