Skip to content

Commit

Permalink
GUI wait GIF
Browse files Browse the repository at this point in the history
  • Loading branch information
emendir committed Sep 25, 2022
1 parent f426bcd commit 8c5bd49
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ build
.gitignore
publish.py
dist
test.py
test.py
.gyte
File renamed without changes
22 changes: 11 additions & 11 deletions MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ def setupUi(self, MainWindow):
self.centralwidget.setObjectName("centralwidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget)
self.horizontalLayout.setObjectName("horizontalLayout")
self.toolBox = QtWidgets.QToolBox(self.centralwidget)
self.toolBox.setToolTip("")
self.toolBox.setObjectName("toolBox")
self.main_widget_tlbx = QtWidgets.QToolBox(self.centralwidget)
self.main_widget_tlbx.setToolTip("")
self.main_widget_tlbx.setObjectName("main_widget_tlbx")
self.SitesPage = QtWidgets.QWidget()
self.SitesPage.setGeometry(QtCore.QRect(0, 0, 787, 449))
self.SitesPage.setObjectName("SitesPage")
self.sitespage_lyt = QtWidgets.QVBoxLayout(self.SitesPage)
self.sitespage_lyt.setObjectName("sitespage_lyt")
self.toolBox.addItem(self.SitesPage, "")
self.main_widget_tlbx.addItem(self.SitesPage, "")
self.PostPublishCodPage = QtWidgets.QWidget()
self.PostPublishCodPage.setGeometry(QtCore.QRect(0, 0, 787, 449))
self.PostPublishCodPage.setObjectName("PostPublishCodPage")
Expand Down Expand Up @@ -125,7 +125,7 @@ def setupUi(self, MainWindow):
self.prepublish_code_save_btn = QtWidgets.QPushButton(self.PostPublishCodPage)
self.prepublish_code_save_btn.setObjectName("prepublish_code_save_btn")
self.verticalLayout.addWidget(self.prepublish_code_save_btn)
self.toolBox.addItem(self.PostPublishCodPage, "")
self.main_widget_tlbx.addItem(self.PostPublishCodPage, "")
self.PostPublishCodPage1 = QtWidgets.QWidget()
self.PostPublishCodPage1.setObjectName("PostPublishCodPage1")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.PostPublishCodPage1)
Expand Down Expand Up @@ -156,8 +156,8 @@ def setupUi(self, MainWindow):
self.postpublish_code_save_btn = QtWidgets.QPushButton(self.PostPublishCodPage1)
self.postpublish_code_save_btn.setObjectName("postpublish_code_save_btn")
self.verticalLayout_2.addWidget(self.postpublish_code_save_btn)
self.toolBox.addItem(self.PostPublishCodPage1, "")
self.horizontalLayout.addWidget(self.toolBox)
self.main_widget_tlbx.addItem(self.PostPublishCodPage1, "")
self.horizontalLayout.addWidget(self.main_widget_tlbx)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 795, 26))
Expand All @@ -171,13 +171,13 @@ def setupUi(self, MainWindow):
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)

self.retranslateUi(MainWindow)
self.toolBox.setCurrentIndex(0)
self.main_widget_tlbx.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.toolBox.setItemText(self.toolBox.indexOf(self.SitesPage), _translate("MainWindow", "Sites"))
self.main_widget_tlbx.setItemText(self.main_widget_tlbx.indexOf(self.SitesPage), _translate("MainWindow", "Sites"))
self.label.setText(_translate("MainWindow", "<html><head/><body><p>Here you can add python code to be run every time you press a Site\'s &quot;Update from path&quot; button. This code gets executed just before the site folder/file is uploaded to IPFS, so it\'s a great way to automate adding some finishing touches to the site before it\'s published.</p><p>You have access to the following variables that belong to that Site, as well as the <a href=\"https://github.com/emendir/IPFS-Toolkit-Python\"><span style=\" text-decoration: underline; color:#2eb8e6;\">IPFS-Toolkit </span></a>module and os, shutil, pathlib, json &amp; sys:</p></body></html>"))
self.label_2.setText(_translate("MainWindow", "source_path\n"
"old_ipfs_cid\n"
Expand All @@ -186,7 +186,7 @@ def retranslateUi(self, MainWindow):
self.prepublish_codebox.setToolTip(_translate("MainWindow", "enter your python code here"))
self.prepublish_code_save_btn.setToolTip(_translate("MainWindow", "save your custom python code"))
self.prepublish_code_save_btn.setText(_translate("MainWindow", "Save"))
self.toolBox.setItemText(self.toolBox.indexOf(self.PostPublishCodPage), _translate("MainWindow", "Pre-Publish Code Execution"))
self.main_widget_tlbx.setItemText(self.main_widget_tlbx.indexOf(self.PostPublishCodPage), _translate("MainWindow", "Pre-Publish Code Execution"))
self.label_4.setText(_translate("MainWindow", "<html><head/><body><p>Here you can add python code to be run every time you press a Site\'s &quot;Update from path&quot; button. This code gets executed right after the site folder/file is uploaded to IPFS, so it\'s a great way round off your content delivery system by automating the last finish-up processing steps.</p><p>You have access to the following variables that belong to that Site, as well as the <a href=\"https://github.com/emendir/IPFS-Toolkit-Python\"><span style=\" text-decoration: underline; color:#2eb8e6;\">IPFS-Toolkit </span></a>module and os, shutil, pathlib, json &amp; sys:</p></body></html>"))
self.label_3.setText(_translate("MainWindow", "source_path\n"
"old_ipfs_cid\n"
Expand All @@ -196,5 +196,5 @@ def retranslateUi(self, MainWindow):
self.postpublish_codebox.setToolTip(_translate("MainWindow", "enter your python code here"))
self.postpublish_code_save_btn.setToolTip(_translate("MainWindow", "save your custom python code"))
self.postpublish_code_save_btn.setText(_translate("MainWindow", "Save"))
self.toolBox.setItemText(self.toolBox.indexOf(self.PostPublishCodPage1), _translate("MainWindow", "Post-Publish Code Execution"))
self.main_widget_tlbx.setItemText(self.main_widget_tlbx.indexOf(self.PostPublishCodPage1), _translate("MainWindow", "Post-Publish Code Execution"))
self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar"))
2 changes: 1 addition & 1 deletion MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ color: rgb(238, 238, 236);</string>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolBox" name="toolBox">
<widget class="QToolBox" name="main_widget_tlbx">
<property name="toolTip">
<string/>
</property>
Expand Down
105 changes: 105 additions & 0 deletions Plugins/UpdateHomepage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""
This file contains a plugin for IPNS-Manager that will automatically pin IPNS
Sites to another computer via an SSH connection whenever the user updates the
Site's content.
This plugin requires the SSHRemotePinningUI.ui file (which defubes the
graphical UI elements and their layout) to be in the same folder.
The SSHRemotePinningUI.ui was created with and can be edited with Qt Designer,
a GUI program for creating Qt GUIs. On linux, this can be installed by running:
sudo apt -y install qttools5-dev-tools
sudo apt -y install qttools5-dev
For other operating systes, check out Qt's website:
https://www.qt.io/download-open-source
You can use this plugin as a starting point for building your own plugins.
To do so, simply make copies of this file and SSHRemotePinningUI.ui in the same
directory, renaming the copies appropriately, and modify them accordingly.
This file is clearly documented, so if you are familiar with programming in
Python and using the Qt framework with Python via the PyQt5 library, you
should learn to understand how this plugin system works fairly quickly.
More explicit documetation is coming soon.
"""


import os # various utilities for interacting with operating system
import IPFS_API


class Plugin:
"""
This class must be called 'Plugin'. It inherits the user interface class
'SSHRemotePinningWidget' created with QtDesigner in the
'SSHRemotePinningUI.ui' file.
This class 'Plugin' contains all the functionality for controlling the
user-interface. Most significantly, however, this class contains the
functions 'PrePublish()' and 'PostPublish()', which get executed before and
after a site is updated in IPNS-Manager's main page respectively.
"""
# human readable name for this plugin, any characters allowed:
plugin_friendly_name = "Update Homepage"
# machine-preferred name for this plugin, preferably without spaces
plugin_code_name = os.path.basename(__file__)[:-3]

# SSH connection details for the computer
# which this plugin shout to pin content to:
pinner_username = ""
pinner_ip = ""
password = None

def __init__(self):
"""This is the constructor for this Pulgin class, meaning that it
gets executed once when the plugin is loaded."""

# Functions to be run when the user updates an IPNS Site ------------------

def PrePublish(self, source_path, old_ipfs_cid, ipns_key_id, ipns_key_name):
"""
This function gets executed every time the user clicks a Site's
'Update from Source' button, before the source is actually uploaded
to IPFS. This allows you to manipulate the folder/file before it is
actually published.
"""
if ipns_key_id != "k2k4r8nismm5mmgrox2fci816xvj4l4cudnuc55gkfoealjuiaexbsup":
return

sites = [
['/mnt/Uverlin/Programming/IPFS-Toolkit', 'IPFS-Toolkit'],
['/mnt/Uverlin/Programming/Brenthy', 'Brenthy'],
['/mnt/Uverlin/Programming/IPNS-Manager', 'IPNS-Manager'],
['/mnt/Uverlin/Programming/QR-ScanGen', 'QR-ScanGen'],
['/mnt/Uverlin/Programming/PupilCore/CursorControl', 'PupilCore-CursorControl'],
['/mnt/Uverlin/Programming/PupilCore/WinkDetection', 'PupilCore-WinkDetection'],
['/mnt/Uverlin/Programming/Atom/export-project-html', 'Atom--export-project-html']
]

os.system("ipfs files rm -r /Homepage")
# os.system("ipfs files mkdir /Homepage")

website_cid = IPFS_API.Publish("/mnt/Uverlin/Website")
os.system(f"ipfs files cp /ipfs/{website_cid}/ /Homepage")
os.system(f"ipfs files mkdir /Homepage/Sites")

website_cid
for path, name in sites:
cid = IPFS_API.Publish(os.path.join(path, "WebSite"))
os.system(f"ipfs files cp /ipfs/{cid}/ /Homepage/Sites/{name}")

from subprocess import Popen, PIPE

proc = Popen(['ipfs', 'files', 'stat', '/Homepage'], stdout=PIPE)
proc.wait()
lines = []
for line in proc.stdout:
lines.append(line.decode('utf-8'))
return {"ipfs_cid": lines[0].strip("\n")}

def PostPublish(self, source_path, old_ipfs_cid, new_ipfs_cid,
ipns_key_id, ipns_key_name):
"""
This function gets executed every time the user clicks a Site's
'Update from Source' button, after the source is uploaded to IPFS.
This allows you to execute post-publishing tasks, such as in this case,
pinning the newly published content on another computer.
"""
pass
33 changes: 20 additions & 13 deletions SiteList/SiteListObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,26 @@ def AddSiteWidget(self, site):

def UpdateRecord(e):
"""Function to be executed when the 'Update from Path' is pressed"""
nonlocal site_widget
old_ipfs_cid = site_widget.ipfs_cid_txbx.text()
site_widget.site.path = site_widget.path_txbx.text()
site_widget.site.name = site_widget.name_txbx.text()
plugin_defined_cid = self.mainwindow.RunPrePublishCode(site_widget.site.path, old_ipfs_cid,
site_widget.site.ipns_key_id, site_widget.site.ipns_key_name)

# upload to IPFS, update site.cid, update IPNS record
site_widget.site.UpdateIPNS_Record(plugin_defined_cid)
site_widget.ipfs_cid_txbx.setText(site_widget.site.ipfs_cid)
# execute the user's custom code
_thread.start_new_thread(self.mainwindow.RunPostPublishCode, (site_widget.site.path, old_ipfs_cid, site_widget.site.ipfs_cid,
site_widget.site.ipns_key_id, site_widget.site.ipns_key_name))
def update_record():
nonlocal site_widget
old_ipfs_cid = site_widget.ipfs_cid_txbx.text()
site_widget.site.path = site_widget.path_txbx.text()
site_widget.site.name = site_widget.name_txbx.text()
self.mainwindow.gui_wait.emit()

plugin_defined_cid = self.mainwindow.RunPrePublishCode(site_widget.site.path, old_ipfs_cid,
site_widget.site.ipns_key_id, site_widget.site.ipns_key_name)

# upload to IPFS, update site.cid, update IPNS record
site_widget.site.UpdateIPNS_Record(plugin_defined_cid)
site_widget.ipfs_cid_txbx.setText(site_widget.site.ipfs_cid)

self.mainwindow.gui_resume.emit()

# execute the user's custom code
self.mainwindow.RunPostPublishCode(site_widget.site.path, old_ipfs_cid, site_widget.site.ipfs_cid,
site_widget.site.ipns_key_id, site_widget.site.ipns_key_name)
_thread.start_new_thread(update_record, ())

def RemoveSite(e):
"""Function to delete this IPNS Site"""
Expand Down
4 changes: 3 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ plugin docs

RemotePinning plugin: password

PrepublishCode change IPFS_CID: apply to code-box? documentation + release
PrepublishCode change IPFS_CID: apply to code-box? documentation + release

Move GUI_Wait GIF from mainwindow to SiteWidget
Loading

0 comments on commit 8c5bd49

Please sign in to comment.