Nicegui example and suggestions #1778
Replies: 6 comments 4 replies
-
Here's my code if anyone wants to see how I did things. import os
from nicegui import ui
true, false, none = True, False, None
# ---------------------------------------------
WIPO_STYLES = '''
<style>
body {
font-size : 20px ;
}
img[src$="pdf.svg"] ,
img[src$="zip.svg"] {
background-image: initial;
background-color: rgb(0, 77, 169);
display : inline-block ;
background: #0067B8;
padding: 3px;
max-height: 16px;
/* vertical-align: text-bottom; */
margin: 0 4px;
}
a {
color: #0059C6 !important;
}
p
{
margin-bottom : 1em !important ;
}
h1, h2, h3, h4, h5, h6 ,
/* .text-h1, .text-h2, .text-h3, */
.text-h4, .text-h5, .text-h6
{
margin-top : 1em !important ;
margin-bottom : 0.5em !important ;
}
</style>
'''
# ---------------------------------------------
async def alert () :
await ui.run_javascript ('alert("Hello!")', respond = false)
# ---------------------------------------------
ISDARK = true
#@ui.page ('/')
def mainpage () :
ui.add_head_html (WIPO_STYLES)
# adding wipo stylesheets breaks the page
#ui.add_head_html ('<link rel="https://www.wipo.int/stylesheet" href="https://www.wipo.int/export/system/modules/org.wipo.internet.rwd.templates/resources/css/styles2016.css">')
#ui.add_head_html ('<link rel="https://www.wipo.int/stylesheet" href="https://www.wipo.int/export/system/modules/org.wipo.internet.rwd.templates/resources/css/styles2016-universal.css">')
#ui.add_head_html ('<link rel="https://www.wipo.int/stylesheet" href="https://www.wipo.int/export/system/modules/org.wipo.internet.rwd.templates/resources/webfonts/ss-standard.css">')
dark = ui.dark_mode ()
# -----
with ui.left_drawer (top_corner = true, bottom_corner = true).style ('background-color: #33c'):
switch = ui.switch ('Dark mode', value = ISDARK, on_change = dark.toggle)
#ui.label ('Switch mode:')
#ui.button ('Dark', on_click = dark.enable)
#ui.button ('Light', on_click = dark.disable)
# -----
ui.label ('WIPO Sequence').classes ('text-h3')
with ui.element ('div').classes ('') :
ui.image ('https://www.wipo.int/export/sites/www/standards/images/wipo-sequence-845.jpg').props ('width=25vw').style ('margin-bottom:2em; margin-left:3em').classes ('float-right')
ui.html ('''
<p>WIPO Sequence is a global software tool that enables patent applicants to prepare amino acid and nucleotide sequence listings compliant with <a href="https://www.wipo.int//export/sites/www/standards/en/pdf/03-26-01.pdf" rel="https://www.wipo.int/noopener">WIPO Standard ST.26 <img src="https://www.wipo.int//export/sites/www/shared/images/icon/new/pdf.svg" alt="PDF, WIPO Standard ST.26"></a> as part of a national or international patent application.</p>
<p class="lead">WIPO Sequence Validator is a web service for patent offices to verify that filed sequence listings comply with WIPO ST.26.</p>
<p>These tools were developed in collaboration with patent offices around the world, under the direction of the <a href="https://www.wipo.int//cws/en/">Committee on WIPO Standards</a>.</p>
<div class="alert alert--warning">
<p><strong>Note</strong>: WIPO Standard ST.26 is now in force.</p>
<p>WIPO Sequence Suite version 2.3.0 was released on 2023.05.08</p>
</div>
''')
ui.separator ()
# -----
with ui.tabs ().classes ('w-full') as tabs :
tabapp = ui.tab ('For Applicants')
taboff = ui.tab ('For Patent Offices')
with ui.tab_panels (tabs, value = tabapp).classes ('w-50') :
with ui.tab_panel (tabapp) :
ui.label ('WIPO Sequence Suite').classes ('text-h4')
ui.html ('''
<p>A standalone desktop application available for Windows, Linux and MacOS. A <a href="https://www.wipo.int/export/sites/www/standards/en/sequence/wipo-sequence-manual.pdf">User Manual <img src="https://www.wipo.int/export/sites/www/shared/images/icon/new/pdf.svg" alt="PDF, WIPO Sequence version 1.1.0 User Manual"></a> is provided to assist applicants with generating compliant sequence listings.</p>
''')
with ui.card ().classes ('bg-stone-200 dark:bg-stone-700 w-50 float-right') :
with ui.element ('div').classes ('text-h6 w-full') :
ui.icon ('help').classes ('float-left')
ui.label ('Need help?')
ui.html ('''
<p>Visit the Knowledge Base for help with WIPO Sequence.</p>
<p>This includes known issues and how to report bugs.</p>
''')
ui.button (
'Knowledge Base',
icon = 'rocket' ,
on_click = 'https://www3.wipo.int/confluence/x/EwAxRg' ,
).classes ('bg-blue-700')
ui.label ('Download').classes ('text-h6')
ui.html ( '''
<p>By downloading and installing WIPO Sequence, you are accepting the following <a href="https://www.wipo.int/export/sites/www/standards/en/sequence/wipo-sequence-terms-use-en.pdf">Terms of Use (October 2021) </a>.</p>
''')
# ---
ui.label ('Select your platform...')
def startdl (link) :
ui.download (link)
ui.notify('Your download has started', type = 'positive')
dlwin = 'https://wiposequence.wipo.int/download/wiposequence/win/WIPO+Sequence+Setup+2.3.0.exe'
dlmac = 'https://wiposequence.wipo.int/download/wiposequence/osx/WIPO Sequence-2.3.0.dmg'
dlnix = 'https://wiposequence.wipo.int/download/wiposequence/linux/WIPO%20Sequence%202.3.0.AppImage'
dlc = 'bg-green-400 dark:bg-green-600'
cls = dlc + ' block m-4'
ui.button ('Mac OS' , icon = 'favorite' , on_click = lambda : startdl (dlmac), color = dlc).classes (cls)
ui.button ('Linux' , icon = 'plumbing' , on_click = lambda : startdl (dlnix), color = dlc).classes (cls)
ui.button ('Windows', icon = 'delete' , on_click = lambda : startdl (dlwin), color = dlc).classes (cls)
# ---
ui.label ('Updates').classes ('text-h6')
ui.html ('''
<p>Sign up for the mailing list to receive notifications of software updates and related issues: <a id="signup" href="/standards/en/sequence/signup.html">WIPO Sequence Updates</a></p>
''')
ui.label ('Test data set — ST.26 DTD version 1.3').classes ('text-h6')
ui.html ('''
<p>The following ZIP file provides both compliant and non-compliant ST.26 instances for testing purposes: Test data set <a href="https://www.wipo.int/standards/en/sequence/valid_and_error.zip"><img src="https://www.wipo.int/export/sites/www/shared/images/icon/new/zip.svg" alt="ZIP, Test data set ST.26 DTD version 1.3"></a></p>
''')
# ---
with ui.tab_panel (taboff) :
ui.label ('WIPO Sequence Validator').classes ('text-h4')
ui.html ('''
<p>A web service that runs in patent office environments to check filed sequence listings for compliance with WIPO Standard ST.26. Patent Offices may obtain WIPO Sequence Validator by <a href="mailto:[email protected]">contacting us</a>.</p>
<h3>Validator Materials</h3>
<ul>
<li><a href="/export/sites/www/standards/en/sequence/wipo-sequence-validator-terms-use-en.pdf" rel="noopener">WIPO Sequence Validator Terms of Use <img src="https://www.wipo.int/export/sites/www/shared/images/icon/new/pdf.svg" alt="PDF, WIPO Sequence Validator Terms of Use"></a></li>
<li><a href="/export/sites/www/standards/en/sequence/wipo-sequence-validator-manual-2-3-0.pdf">WIPO Sequence Validator Operations Manual <img src="https://www.wipo.int/export/sites/www/shared/images/icon/new/pdf.svg" alt="PDF, WIPO Sequence Validator version 1.1.0 Operations Manual"></a></li>
</ul>
''')
ui.separator()
# -----
ui.label ('News').classes ('text-h4')
with ui.timeline (side = 'right') :
ui.timeline_entry (
'' ,
title = 'Version 2.2.0 of WIPO Sequence Suite released for general use' ,
subtitle = 'Oct 2022' ,
icon = 'rocket_launch' ,
)
with ui.timeline_entry (
'' ,
title = 'WIPO Standard ST.26 goes live' ,
subtitle = 'July 2022' ,
icon = 'biotech' ,
) :
ui.link ('Full story ', 'https://www.wipo.int/pct/en/news/2022/news_0039.html', new_tab = true)
ui.icon ('launch')
with ui.timeline_entry (
'' ,
title = 'Version 2.1 of WIPO Sequence Suite released ' ,
subtitle = 'June 2022' ,
icon = 'public' ,
) :
with ui.expansion ('Show more', icon = 'swap_vert').classes ('w-full') :
ui.html ('''
<p>After releasing WIPO Sequence Suite version 2.0 in May, WIPO has continued resolving known issues to ensure the software is production ready for the WIPO ST.26 implementation date of July 1. Improvements in version 2.1 include upgrading the “Help” features and refining import messages. Changes since version 2.0.0 are summarized in the Release Notes on the <a href="https://www.wipo.int/standards/en/sequence/index.html">WIPO Sequence home page</a>.</p>
<p>If you do not receive the auto-update message in WIPO Sequence Suite, please download version 2.1.0 using the links above.</p>
''')
with ui.timeline_entry (
'' ,
title = 'Next stable release of WIPO Sequence; Knowledge Base & email list' ,
subtitle = 'May 2022' ,
icon = 'model_training' ,
) :
with ui.expansion ('Show more', icon = 'swap_vert').classes ('w-full') :
ui.html ('''
<p>Based on the feedback of our testing group, WIPO has continued to improve the WIPO Sequence Suite to ensure that it meets the needs of users for the July 1 WIPO ST.26 implementation date. The result will be WIPO Sequence version 2.0.0, scheduled for release in the week of May 16. Improvements since the last stable version will be summarized in the Version 2.0.0 Release Notes to be provided in the Download section.</p>
<p>To help support users, WIPO is also collaborating with patent Offices to produce a <a href="https://www3.wipo.int/confluence/x/EwAxRg">knowledge base</a> of answers to regularly asked questions and common issues. This knowledge base will be available to the public from June 1.</p>
<p>WIPO Sequence users are encouraged to sign-up to the new <a href="/standards/en/sequence/signup.html">email list</a> for important announcements and information on software updates and related issues. Users will be prompted to register for the list when downloading the software from the WIPO Sequence homepage. </p>
</article>
''')
with ui.timeline_entry (
'' ,
title = 'Second stable release of WIPO Sequence' ,
subtitle = 'Oct 2021' ,
icon = 'build' ,
) :
with ui.expansion ('Show more', icon = 'swap_vert').classes ('w-full') :
ui.html ('''
<p>Since November 2021, WIPO has been developing an improved version of the WIPO Sequence Suite. The latest version of the desktop tool can be downloaded above along with the release notes which indicate the changes since the last stable release was published. Patent Offices interested in the latest version of WIPO Sequence Validator should <a href="mailto:[email protected]">contact us</a>.</p>
''')
with ui.timeline_entry (
'' ,
title = 'WIPO ST.26 Training Webinar Series' ,
subtitle = 'April 2021' ,
icon = 'ondemand_video' ,
) :
with ui.expansion ('Show more', icon = 'swap_vert').classes ('w-full') :
ui.html ('''
<p>WIPO is providing four webinars on preparing sequence listings compliant with WIPO Standard ST.26. The webinars are open to patent applicants and IP Offices. See the <a href="https://www.wipo.int/meetings/en/topic.jsp?group_id=330">webinars page</a> for dates in April and May and other information. Recordings will be available.</p>
''')
ui.separator()
title = 'WIPO Sequence'
if ISDARK :
dark.enable ()
ui.run (
title = title ,
# dark = true , # doesnt work
# port = native_mode.find_open_port () ,
# reload = false,
)
# ---------------------------------------------
if __name__ in { '__main__', '__mp_main__' } :
mainpage () |
Beta Was this translation helpful? Give feedback.
-
I’m experiencing similar issues. Although NiceGUI is a fantastic tool, styling, positioning, and layout can be a bit of a headache for coders without much experience in web development. Your code will be a good reference. Thank you for your effort! |
Beta Was this translation helpful? Give feedback.
-
@stdusr Thank you so much for taking the time to write it all down. You have a lot valuable points. For some we already have separate feature requests. We'll need to go over this list in the next days and extract other points to implement or further discuss in separate topics. |
Beta Was this translation helpful? Give feedback.
-
One thing I'm considering is how to better separate functionality from style. I dislike littering my code with style elements like Does anyone have suggestions how to accomplish this? My thoughts so far:
def add_nodes (root) :
with root :
ui.label ('Are you ready?')
ui.button ('Let's go!')
return root
def add_styles (root) :
for label in root.labels () : # return all labels under root?
label.classes ('bg-blue-200')
for button in root.buttons () : # return all button under root?
button.classes ('w-25 bg-green-500')
return root
def main () :
root = ui.column ()
add_nodes (root)
add_styles (root)
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing your impressions in such detail, @ed2050! I won't be able to address every single point in this thread, but let me share my thoughts, mainly about your suggested improvements:
Oh and one last thing: To conclude: I second your suggestions, even though the concrete realization might be challenging. However, I'd suggest to discuss individual points in separate tickets, since this one is already getting pretty long. Or, even better, if you have specific suggestion on how to improve the documentation, a pull request is always very welcome (and forces us to take action). 🙂 |
Beta Was this translation helpful? Give feedback.
-
I made an example to try out nicegui. It turned out rather well. I'll share my experiences to help guide others. See Conclusions and Suggestions for takeaways.
Test
I decided to recreate this page. The style of that page always frustrated me. Pure white, walls of text, no differentiation. Government organization with outdated tools, what can you do? It's mostly a static page, but shows off nicegui's abilities for modern design.
Screenshots at end of post. Here are thumbnails of my page:
My background: decades of experience as a dabbler in web development. It's not my main role since early in my career, but is a part of what I do. Created many pages with manual html and css, several browser extensions, and a few python web apps from scratch (no frameworks). Developed a few sites with perl and php early in my career. Recently tried a bit of mako and jinja for page generation. Never used flask, tailwind, quasar, or any other python or js frameworks.
Things that were easy to do with nicegui:
Things that should have been easy but were difficult to figure out from nicegui docs:
<h[1-6]>
tags. the only text element available is ui.label, which is neither a header nor a paragraph, but a div. creating actual headers and<p>
text would be nice without resorting to ui.element. Maybe ui.para and ui.h1, ui.h2, ...?with
).ui.element ('div')
.props ()
and.classes ()
and.style ()
. Not clear at all which elements support which methods, or when to use which method. Eg should I set width withprops ('width=50%')
or withclasses ('w-50')
?color =
flag toui.button()
would work, but no. Then you'd tryui.button().classes (color)
but that doesn't work either. Finally I stumbled on the solution - you have to do both together! Very strange behavior.Things I never figured out how to do:
<h1>
shouldn't be 5 times the size of<p>
. h4 in nicegui is the size of h1 on most sites.<div class="text-h4">
instead of a real<h4>
. This makes the content very hard to parse, eg by search engines, web scrapers, and semantic tools.ui.html
orui.element
? Everything in ui.label turns into a<div>
.run (dark = true)
does nothing. had to calldark.enable ()
to start in dark mode.Conclusion
nicegui is fantastic. Very powerful tools for creating complex elements with minimal code. I'm beyond impressed. My demo only scratches the surface of what nicegui can do, but the results are exceptional.
The one thing that can be improved is the docs. They're very good in some ways. The showcase page does a great job showing what elements are available and some basic options. But a number of general topics are missing, such as global styles, composing a complete page, making text elements other than ui.label, etc.
The reference pages make it hard to find key information. I had to resort to things like
help (ui.element.style ())
in the python console to find out that multiple styles should be separated by ; instead of space, and error messages to tell me that the format is name:val, not name=val as withprops ()
.Suggestions to improve the docs
bind_*
methods to scroll through just to find theprops
method. Ref pages can be improved with 1) a clickable index of all function names at the top or side, so you can immediately jump toprops
if that's what you need, and 2) less repetition of common methods that every class has. Methods that many elements share can just link to the base class page, instead of cluttering up every ui.button, ui.icon, etc page with a dozen differentbind_*
methods.Sequence page
News section cut off for some reason
![Screenshot_2023-10-09 WIPO Sequence](https://private-user-images.githubusercontent.com/34918456/273563239-4a348259-f465-4541-ad88-49e7c75040ce.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxODc1MTAsIm5iZiI6MTczOTE4NzIxMCwicGF0aCI6Ii8zNDkxODQ1Ni8yNzM1NjMyMzktNGEzNDgyNTktZjQ2NS00NTQxLWFkODgtNDllN2M3NTA0MGNlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDExMzMzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg5NjM4MjJhOTczMmRlNWQ0NjdjOGE4ODExOWI2Mjk4ZWU1MGZhNzY1NTZkYjg0ZTc1MTg2OGJlNjk4MjYwNTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.b6-1p1k2zobZJ5r9W8x6DL6eN__HLEbYdIbzWh16BPs)
News items
Beta Was this translation helpful? Give feedback.
All reactions