There is a 'startup.py' file with Python script (1200 rows) written by somebody. It works like a QGIS Plugin, see image below.
What are the steps needed to convert this script into a proper QGIS Plugin? Otherwise, how to get the UI files out of Python code?
My initial idea is to start with the pb_tool
and then break the 'startup.py' file into modules and insert into the plugin skeleton. However, it works with the '..._dialog_base.ui' file which I do not have.
Perhaps it is better to deploy the Plugin Builder, but it is similar to what the pb_tool
does.
The person who created the script used the QtDesigner, however, the UI files were heavily modified by hand. Only an old version of the current layout exists.
There is also left a 'uic.exe' file in the QtCompiler dir. Some information on how to run the is described here : QT designer didn't install uic program for view the code from the application. In my case it must be placed under C:\Program Files\QGIS 3.20.3\apps\qt5\bin\bin
.
The 'startup.py' file consists of the following parts:
imports
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from qgis.core import *
from qgis.utils import *
from qgspasswordlineedit import QgsPasswordLineEdit
----------------------------
configuration files
----------------------------
functions
----------------------------
layouts / pages
###Layouts
#Page1
class IntroPage(QWizardPage):
def __init__(self, parent=None):
super(IntroPage, self).__init__(parent)
...
#Page2
class LayerPage(QWizardPage):
def __init__(self, parent=None):
super(LayerPage, self).__init__(parent)
...
#page 3
class AuthPage(QWizardPage):
def __init__(self, parent=None):
super(AuthPage, self).__init__(parent)
...
#QWizard Class
class Window(QWizard):
def __init__(self):
super(Window, self).__init__()
#adds Pages to Wizard
self.IntroPage = IntroPage()
self.LayerPage = LayerPage()
self.AuthPage = AuthPage()
self.addPage(self.IntroPage)
self.addPage(self.LayerPage)
self.addPage(self.AuthPage)
#Button check if Oracle or Postgre Data selected
self.button(QWizard.NextButton).clicked.connect(lambda x:OraclePostgreCheck(self.AuthPage.frame_2, self.AuthPage.frame_4))
#Readjust GUI size at buttonclick
self.button(QWizard.NextButton).clicked.connect(self.adjustSize)
self.button(QWizard.BackButton).clicked.connect(self.adjustSize)
----------------------------
code that runs the program
###
#Programm starts
#loadConfigCSV(URI,";")
loadPaketConfigJSON(PURI)
loadConfigJSON(URI)
kategoriesJSON()
#loadConfigtoQGIS() #load config for export during development
#GUI
window = Window()
window.setWizardStyle(1)
window.show()
#Programm ends
###
pyuic5
QT5 executable you can convert yourui
file info Python. Secondly, why do you want to changestartup.py
, do you want to load your plugin at QGIS startup and display directly the dialog ?startup.py
file into ayour_plugin_name_or_whatever.py
, do a function calleddef launch_code
and put thestartup.py
"code that runs the program" part into it, and then, in you plugin generated bypb_tool
, put a call tolaunch_code
in thedef run
, function called by plugin menu button click.from .startup import launch_code
with the.
for local folder search orfrom your_plugin_folder_name.startup import launch_code
.