-
Notifications
You must be signed in to change notification settings - Fork 99
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
PR3: Display changelog/announcement page in SLEAP GUI #1556
base: shrivaths/changelog-announcement-2
Are you sure you want to change the base?
Changes from 39 commits
b7f7748
25eda37
8706ccb
fdf5547
d584de2
f809bda
cce7183
2c68518
ca25347
27f0d28
168056e
5e2fb37
944428f
793faa6
561a109
465eb3f
f7c510d
d071ac8
58ffca8
02aa249
a724ec2
9827510
cd98d7c
a9673d8
b7e475d
2cc02d7
709de70
18974db
cada26c
3c35dda
713c068
86d1a44
1737561
7859b93
ec2b2d7
59f2438
bd8d004
ea2111d
7ff49f0
5391131
6ddb158
895a074
af67d55
b5d5139
150453d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,72 @@ | ||||||||||||||
""" | ||||||||||||||
GUI for displaying the new announcement. | ||||||||||||||
""" | ||||||||||||||
|
||||||||||||||
from qtpy.QtCore import Signal, Qt | ||||||||||||||
from qtpy.QtWebEngineWidgets import QWebEngineView | ||||||||||||||
from qtpy.QtCore import Property, Signal, QObject, QUrl | ||||||||||||||
from qtpy.QtWebChannel import QWebChannel | ||||||||||||||
from qtpy import QtWidgets | ||||||||||||||
from pathlib import Path | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class BulletinWorker(QtWidgets.QMainWindow): | ||||||||||||||
def __init__(self, content, parent=None): | ||||||||||||||
super(BulletinWorker, self).__init__(parent) | ||||||||||||||
self._content = content | ||||||||||||||
# Set the window to stay on top | ||||||||||||||
self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint) | ||||||||||||||
self.setWindowTitle("What's New?") | ||||||||||||||
self.setGeometry(0, 0, 900, 750) | ||||||||||||||
self.center_on_screen() | ||||||||||||||
|
||||||||||||||
def center_on_screen(self): | ||||||||||||||
# Get the screen geometry | ||||||||||||||
screen_geometry = QtWidgets.QDesktopWidget().screenGeometry() | ||||||||||||||
|
||||||||||||||
# Calculate the center of the screen | ||||||||||||||
center_x = (screen_geometry.width() - self.width()) // 2 | ||||||||||||||
center_y = (screen_geometry.height() - self.height()) // 2 | ||||||||||||||
|
||||||||||||||
# Move the window to the center of the screen | ||||||||||||||
self.move(center_x, center_y) | ||||||||||||||
|
||||||||||||||
def show_bulletin(self): | ||||||||||||||
|
||||||||||||||
self.document = Document() | ||||||||||||||
|
||||||||||||||
# Set the webchannel | ||||||||||||||
self.channel = QWebChannel() | ||||||||||||||
self.channel.registerObject("content", self.document) | ||||||||||||||
|
||||||||||||||
self.document.set_text(self._content) | ||||||||||||||
self.view = QWebEngineView() | ||||||||||||||
self.view.page().setWebChannel(self.channel) | ||||||||||||||
|
||||||||||||||
filename = str(Path(__file__).resolve().parent / "bulletin/markdown.html") | ||||||||||||||
url = QUrl.fromLocalFile(filename) | ||||||||||||||
self.view.load(url) | ||||||||||||||
Comment on lines
+46
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The path to the - filename = str(Path(__file__).resolve().parent / "bulletin/markdown.html")
+ filename = Path(__file__).resolve().parent / "bulletin/markdown.html" Committable suggestion
Suggested change
|
||||||||||||||
|
||||||||||||||
self.view.setGeometry(0, 0, 600, 400) | ||||||||||||||
# Set the central window with view | ||||||||||||||
self.setCentralWidget(self.view) | ||||||||||||||
self.show() | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class Document(QObject): | ||||||||||||||
textChanged = Signal(str) | ||||||||||||||
|
||||||||||||||
def __init__(self, parent=None): | ||||||||||||||
super().__init__(parent) | ||||||||||||||
self.m_text = "" | ||||||||||||||
Comment on lines
+59
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per the previous review comment, consider adding an optional - def __init__(self, parent=None):
+ def __init__(self, parent=None, text=""):
super().__init__(parent)
- self.m_text = ""
+ self.m_text = text Committable suggestion
Suggested change
|
||||||||||||||
|
||||||||||||||
Comment on lines
+59
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - def __init__(self, parent=None):
+ def __init__(self, parent=None, text=""):
super().__init__(parent)
- self.m_text = ""
+ self.m_text = text Commitable suggestion (Beta)
Suggested change
|
||||||||||||||
def get_text(self): | ||||||||||||||
return self.m_text | ||||||||||||||
|
||||||||||||||
def set_text(self, text): | ||||||||||||||
if self.m_text == text: | ||||||||||||||
return | ||||||||||||||
self.m_text = text | ||||||||||||||
self.textChanged.emit(self.m_text) | ||||||||||||||
|
||||||||||||||
text = Property(str, fget=get_text, fset=set_text, notify=textChanged) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
body { | ||
font-family: Helvetica, Arial, sans-serif; | ||
} | ||
|
||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5 { | ||
color: #636364; | ||
font-style: italic; | ||
} | ||
|
||
#container { | ||
display: flex; | ||
} | ||
|
||
#navbar { | ||
width: 200px; /* Set the fixed width for the navbar */ | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
height: 100vh; | ||
background-color: #2e2e2e; | ||
color: #fff; | ||
padding: 12px; | ||
box-sizing: border-box; | ||
flex-grow: 1; | ||
list-style: disc; | ||
} | ||
|
||
#navbar ul { | ||
margin-left: 2px; | ||
padding-left: 12px; | ||
|
||
} | ||
|
||
#navbar a { | ||
color: white; | ||
} | ||
|
||
#content { | ||
flex-grow: 1; | ||
padding: 20px; | ||
box-sizing: border-box; | ||
margin-left: 200px; /* Adjust margin to match navbar width */ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>What's New?</title> | ||
<link rel="stylesheet" href="pico.min.css"> | ||
<link rel="stylesheet" type="text/css" href="markdown.css"> | ||
<script src="marked.js"></script> | ||
<script src="qrc:/qtwebchannel/qwebchannel.js"></script> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<div id="content"></div> | ||
<div id="navbar"></div> | ||
</div> | ||
<script> | ||
'use strict'; | ||
|
||
var content = document.getElementById('content'); | ||
var navbar = document.getElementById('navbar'); | ||
|
||
var updateText = function(text) { | ||
content.innerHTML = marked(text); | ||
// Wait till the document is loaded to add navbar | ||
setTimeout(function() { | ||
generateNavbar(); | ||
}, 100); | ||
} | ||
|
||
new QWebChannel(qt.webChannelTransport, | ||
function(channel) { | ||
var content = channel.objects.content; | ||
updateText(content.text); | ||
content.textChanged.connect(updateText); | ||
} | ||
); | ||
|
||
function generateNavbar() { | ||
const h2Tags = document.querySelectorAll('h2'); | ||
const ul = document.createElement('ul'); | ||
var uniqueIdCounter = 1; | ||
|
||
h2Tags.forEach((h2, index) => { | ||
const li = document.createElement('li'); | ||
const link = document.createElement('a'); | ||
if (!h2.id) { | ||
h2.id = `generated-id-${uniqueIdCounter}`; | ||
uniqueIdCounter++; | ||
} | ||
link.href = '#' + h2.id; | ||
link.textContent = h2.textContent; | ||
link.addEventListener('click', function(event) { | ||
event.preventDefault(); | ||
scrollToSection(h2); | ||
}); | ||
li.appendChild(link); | ||
ul.appendChild(li); | ||
}); | ||
navbar.appendChild(ul); | ||
document.body.insertBefore(navbar, document.body.firstChild); | ||
}; | ||
|
||
function scrollToSection(element) { | ||
element.scrollIntoView({ behavior: 'smooth' }); | ||
} | ||
|
||
</script> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class
BulletinWorker
is named as if it performs background work, but it inherits fromQMainWindow
and seems to be responsible for UI presentation. Consider renaming the class to reflect its purpose more accurately.