Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'addition_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from py4j.java_gateway import JavaGateway
class Ui_MainWindow(object):
def setupUi(self, MainWindow, svc):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(452, 247)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget, clicked = lambda : self.press_it(svc))
self.pushButton.setGeometry(QtCore.QRect(330, 140, 81, 31))
self.pushButton.setObjectName("pushButton")
self.varATextBox = QtWidgets.QLineEdit(self.centralwidget)
self.varATextBox.setGeometry(QtCore.QRect(120, 20, 113, 20))
self.varATextBox.setObjectName("varATextBox")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(20, 20, 71, 16))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 50, 71, 16))
self.label_2.setObjectName("label_2")
self.varBTextBox = QtWidgets.QLineEdit(self.centralwidget)
self.varBTextBox.setGeometry(QtCore.QRect(120, 50, 113, 20))
self.varBTextBox.setObjectName("varBTextBox")
self.resultLbl = QtWidgets.QLabel(self.centralwidget)
self.resultLbl.setGeometry(QtCore.QRect(40, 110, 231, 41))
font = QtGui.QFont()
font.setPointSize(20)
font.setBold(True)
font.setWeight(75)
self.resultLbl.setFont(font)
self.resultLbl.setObjectName("resultLbl")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 452, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Add"))
self.label.setText(_translate("MainWindow", "Variable A"))
self.label_2.setText(_translate("MainWindow", "Variable B"))
self.resultLbl.setText(_translate("MainWindow", "TextLabel"))
def press_it(self, svc):
a = int(self.varATextBox.text())
b = int(self.varBTextBox.text())
c = svc.add(a,b)
self.resultLbl.setText("Laus: " + str(c))
if __name__ == "__main__":
import sys
# launch py4j gateway to lib-jar and expose it as a service
gateway = JavaGateway.launch_gateway(jarpath='bin/py4j-0.10.9.2.jar', classpath='bin/addition.jar', java_path='jdk-11.0.11+9-jre/bin/java.exe', die_on_exit=True, use_shell=False)
# create instance of the class of interest within the jar
svc = gateway.jvm.AdditionService()
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
# now startup QT-app and pass reference to java-service
ui.setupUi(MainWindow, svc)
MainWindow.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment