浏览代码

code review

Falko Schindler 2 年之前
父节点
当前提交
4887362639
共有 3 个文件被更改,包括 11 次插入11 次删除
  1. 8 8
      examples/svg_clock/main.py
  2. 1 1
      main.py
  3. 2 2
      tests/test_chart.py

+ 8 - 8
examples/svg_clock/main.py

@@ -1,13 +1,13 @@
 #!/usr/bin/env python3
 #!/usr/bin/env python3
-import datetime
+from datetime import datetime
 
 
 from nicegui import ui
 from nicegui import ui
 
 
 
 
-def build_svg():
-    '''returns svg showing the current time.
-    Original was taken from https://de.m.wikipedia.org/wiki/Datei:Station_Clock.svg.'''
-    now = datetime.datetime.now()
+def build_svg() -> str:
+    '''Returns an SVG showing the current time.
+    Original was borrowed from https://de.m.wikipedia.org/wiki/Datei:Station_Clock.svg.'''
+    now = datetime.now()
     return f'''
     return f'''
 <svg width="800" height="800" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
 <svg width="800" height="800" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
 	<circle cx="400" cy="400" r="400" fill="#fff"/>
 	<circle cx="400" cy="400" r="400" fill="#fff"/>
@@ -28,13 +28,13 @@ def build_svg():
 		</g>
 		</g>
 		<use transform="rotate(90 400 400)" xlink:href="#d"/>
 		<use transform="rotate(90 400 400)" xlink:href="#d"/>
 	</g>
 	</g>
-    <g transform="rotate({(250 + now.hour*6*5)%360} 400 400)">
+    <g transform="rotate({250 + now.hour / 12 * 360} 400 400)">
     	<path d="m334.31 357.65-12.068 33.669 283.94 100.8 23.565-10.394-13.332-24.325z"/>
     	<path d="m334.31 357.65-12.068 33.669 283.94 100.8 23.565-10.394-13.332-24.325z"/>
     </g>
     </g>
-    <g transform="rotate({(117.3 + now.minute*6)%360} 400 400)">
+    <g transform="rotate({117 + now.minute / 60 * 360} 400 400)">
     	<path d="m480.73 344.98 11.019 21.459-382.37 199.37-18.243-7.2122 4.768-19.029z"/>
     	<path d="m480.73 344.98 11.019 21.459-382.37 199.37-18.243-7.2122 4.768-19.029z"/>
     </g>
     </g>
-    <g transform="rotate({(169 + now.second*6)%360} 400 400)">
+    <g transform="rotate({169 + now.second / 60 * 360} 400 400)">
         <path d="m410.21 301.98-43.314 242.68a41.963 41.963 0 0 0-2.8605-0.091 41.963 41.963 0 0 0-41.865 42.059 41.963 41.963 0 0 0 30.073 40.144l-18.417 103.18 1.9709 3.9629 3.2997-2.9496 21.156-102.65a41.963 41.963 0 0 0 3.9771 0.1799 41.963 41.963 0 0 0 41.865-42.059 41.963 41.963 0 0 0-29.003-39.815l49.762-241.44zm-42.448 265.56a19.336 19.336 0 0 1 15.703 18.948 19.336 19.336 0 0 1-19.291 19.38 19.336 19.336 0 0 1-19.38-19.291 19.336 19.336 0 0 1 19.291-19.38 19.336 19.336 0 0 1 3.6752 0.3426z" fill="#a40000"/>
         <path d="m410.21 301.98-43.314 242.68a41.963 41.963 0 0 0-2.8605-0.091 41.963 41.963 0 0 0-41.865 42.059 41.963 41.963 0 0 0 30.073 40.144l-18.417 103.18 1.9709 3.9629 3.2997-2.9496 21.156-102.65a41.963 41.963 0 0 0 3.9771 0.1799 41.963 41.963 0 0 0 41.865-42.059 41.963 41.963 0 0 0-29.003-39.815l49.762-241.44zm-42.448 265.56a19.336 19.336 0 0 1 15.703 18.948 19.336 19.336 0 0 1-19.291 19.38 19.336 19.336 0 0 1-19.38-19.291 19.336 19.336 0 0 1 19.291-19.38 19.336 19.336 0 0 1 3.6752 0.3426z" fill="#a40000"/>
     </g>
     </g>
 </svg>
 </svg>

+ 1 - 1
main.py

@@ -206,7 +206,7 @@ ui.run()
             example_link('Image Mask Overlay', 'shows how to overlay an image with a mask')
             example_link('Image Mask Overlay', 'shows how to overlay an image with a mask')
             example_link('Infinite Scroll', 'presents an infinitely scrolling image gallery')
             example_link('Infinite Scroll', 'presents an infinitely scrolling image gallery')
             example_link('OpenCV Webcam', 'uses OpenCV to capture images from a webcam')
             example_link('OpenCV Webcam', 'uses OpenCV to capture images from a webcam')
-            example_link('SVG Clock', 'display an analog clock by updating an svg with `ui.timer`')
+            example_link('SVG Clock', 'displays an analog clock by updating an SVG with `ui.timer`')
 
 
     with ui.row().classes('bg-primary w-full min-h-screen mt-16'):
     with ui.row().classes('bg-primary w-full min-h-screen mt-16'):
         link_target('why')
         link_target('why')

+ 2 - 2
tests/test_chart.py

@@ -27,10 +27,10 @@ def test_change_chart_data(screen: Screen):
     ui.button('Update', on_click=update)
     ui.button('Update', on_click=update)
 
 
     screen.open('/')
     screen.open('/')
-    screen.wait(.5)
+    screen.wait(0.5)
     before = [bar.size['width'] for bar in get_series_0(screen.selenium)]
     before = [bar.size['width'] for bar in get_series_0(screen.selenium)]
     screen.click('Update')
     screen.click('Update')
-    screen.wait(.5)
+    screen.wait(0.5)
     after = [bar.size['width'] for bar in get_series_0(screen.selenium)]
     after = [bar.size['width'] for bar in get_series_0(screen.selenium)]
     assert before[0] < after[0]
     assert before[0] < after[0]
     assert before[1] < after[1]
     assert before[1] < after[1]