ngwidgets API Documentation
ai_chat
Created on 2024-02-05
based on https://raw.githubusercontent.com/zauberzeug/nicegui/main/examples/chat_app/main.py
@author: wf
basetest
Created on 2021-08-19
@author: wf
Basetest
Bases: TestCase
base test case
Source code in ngwidgets/basetest.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
inPublicCI()
staticmethod
are we running in a public Continuous Integration Environment?
Source code in ngwidgets/basetest.py
33 34 35 36 37 38 39 40 |
|
isUser(name)
staticmethod
Checks if the system has the given name
Source code in ngwidgets/basetest.py
42 43 44 45 |
|
setUp(debug=False, profile=True)
setUp test environment
Source code in ngwidgets/basetest.py
19 20 21 22 23 24 25 26 27 |
|
cmd
Created on 2023-09-10
@author: wf
WebserverCmd
Bases: object
Baseclass for command line handling of Webservers
Source code in ngwidgets/cmd.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
__init__(config, webserver_cls, debug=False)
constructor
Source code in ngwidgets/cmd.py
21 22 23 24 25 26 27 28 29 |
|
cmd_main(argv)
main program as an instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
argv(list) |
list of command line arguments |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
exit code - 0 of all went well 1 for keyboard interrupt and 2 for exceptions |
Source code in ngwidgets/cmd.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
cmd_parse(argv=None)
parse the argument lists and prepare
Parameters:
Name | Type | Description | Default |
---|---|---|---|
argv(list) |
list of command line arguments |
required |
Source code in ngwidgets/cmd.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
getArgParser(description=None, version_msg=None)
Setup command line argument parser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
description(str) |
the description |
required | |
version_msg(str) |
the version message |
required |
Returns:
Name | Type | Description |
---|---|---|
ArgumentParser |
ArgumentParser
|
the argument parser |
Source code in ngwidgets/cmd.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
to_apache_config(config, domain)
Generate Apache configuration based on the given WebserverConfig.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
WebserverConfig
|
The webserver configuration object. |
required |
domain(str) |
the base domain to use |
required |
Returns: str: The Apache configuration as a string.
Source code in ngwidgets/cmd.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
color_map
Created on 2024-07-17
@author: wf
ColorMap
A map of color ranges.
the first column of each row has the color range from start_color to end_color the other columns are interpolated using the lum_min, lum_max and sat_f parameters
Attributes:
Name | Type | Description |
---|---|---|
start_color |
Color
|
The starting color of the range. |
end_color |
Color
|
The ending color of the range. |
num_levels |
int
|
The number of levels in the color range. |
lum_min |
float
|
The minimum luminance |
lum_max |
float
|
The maximum luminance |
sat_f |
float
|
The saturation factor |
Source code in ngwidgets/color_map.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
get_color(row, col)
Retrieves the color hex code at the specified row and column indices.
Source code in ngwidgets/color_map.py
64 65 66 67 68 |
|
color_schema
Created on 2023-09-13
@author: wf
ColorSchema
dataclass
a nicegui color schema
Source code in ngwidgets/color_schema.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
amber()
classmethod
Return a color schema for the Amber color palette from Material Palette. see https://www.materialpalette.com/amber/amber
Source code in ngwidgets/color_schema.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
apply()
Apply this color schema to the current UI theme.
Source code in ngwidgets/color_schema.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
blue()
classmethod
Return a color schema for the Blue color palette from Material Palette. see https://www.materialpalette.com/blue/blue
Source code in ngwidgets/color_schema.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
blue_grey()
classmethod
Return a color schema for the Blue Grey color palette from Material Palette. see https://www.materialpalette.com/grey/blue-grey
Source code in ngwidgets/color_schema.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
brown()
classmethod
Return a color schema for the Brown color palette from Material Palette. see https://www.materialpalette.com/brown/brown
Source code in ngwidgets/color_schema.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
|
cyan()
classmethod
Return a color schema for the Cyan color palette from Material Palette. see https://www.materialpalette.com/blue/cyan
Source code in ngwidgets/color_schema.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
deep_orange()
classmethod
Return a color schema for the Deep Orange color palette from Material Palette. see https://www.materialpalette.com/orange/deep-orange
Source code in ngwidgets/color_schema.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
deep_purple()
classmethod
Return a color schema for the Deep Purple color palette from Material Palette. see https://www.materialpalette.com/purple/deep-purple
Source code in ngwidgets/color_schema.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
default()
classmethod
Return the default color schema.
Source code in ngwidgets/color_schema.py
71 72 73 74 75 76 |
|
display()
Display all available color schemas visually in the UI.
Source code in ngwidgets/color_schema.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
get_schemas()
classmethod
Return a list of all available color schemas.
Source code in ngwidgets/color_schema.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
green()
classmethod
Return a color schema for the Green color palette from Material Palette. see https://www.materialpalette.com/green/green
Source code in ngwidgets/color_schema.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
grey()
classmethod
Return a color schema for the Grey color palette from Material Palette. see https://www.materialpalette.com/grey/grey
Source code in ngwidgets/color_schema.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
indigo()
classmethod
Return a color schema for the Indigo color palette from Material Palette. see https://www.materialpalette.com/indigo/indigo
Source code in ngwidgets/color_schema.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
light_blue()
classmethod
Return a color schema for the Light Blue color palette from Material Palette. see https://www.materialpalette.com/blue/light-blue
Source code in ngwidgets/color_schema.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
light_green()
classmethod
Return a color schema for the Light Green color palette from Material Palette. see https://www.materialpalette.com/green/light-green
Source code in ngwidgets/color_schema.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
lime()
classmethod
Return a color schema for the Lime color palette from Material Palette. see https://www.materialpalette.com/lime/lime
Source code in ngwidgets/color_schema.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
orange()
classmethod
Return a color schema for the Orange color palette from Material Palette. see https://www.materialpalette.com/orange/orange
Source code in ngwidgets/color_schema.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
|
pink_red()
classmethod
Return a color schema for the Pink/Red color palette from Material Palette. see https://www.materialpalette.com/pink/red
Source code in ngwidgets/color_schema.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
purple()
classmethod
Return a color schema for the Purple color palette from Material Palette. see https://www.materialpalette.com/purple/purple
Source code in ngwidgets/color_schema.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
red()
classmethod
Return a color schema for the Red color palette from Material Palette. see https://www.materialpalette.com/red/red
Source code in ngwidgets/color_schema.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
teal()
classmethod
Return a color schema for the Teal color palette from Material Palette. see https://www.materialpalette.com/teal/teal
Source code in ngwidgets/color_schema.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
yellow()
classmethod
Return a color schema for the Yellow color palette from Material Palette. see https://www.materialpalette.com/yellow/yellow
Source code in ngwidgets/color_schema.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
combobox
Created on 2024-07-04
@author: wf
ComboBox
A ComboBox class that encapsulates a UI selection control which allows both drop-down and free-form text input, suitable for dynamic user interfaces.
Attributes:
Name | Type | Description |
---|---|---|
label_base |
str
|
The base text for the combobox label. |
options |
Iterable[str]
|
The current list of options available in the combobox. |
select |
Select
|
The UI component instance, allowing for both selection and direct input. |
Source code in ngwidgets/combobox.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
setup_ui()
Initializes the UI component for the combobox with optional text input capability.
Source code in ngwidgets/combobox.py
45 46 47 48 49 50 51 52 53 |
|
update_options(new_options, limit=None, options_count=None)
Updates the options available in the combobox and refreshes the label, applying a limit to the number of items displayed if specified, and showing total available options if different from displayed due to the limit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_options |
Interable[str]
|
The new options to update in the combobox. |
required |
limit |
int
|
Maximum number of options to display. If None, all options are displayed. |
None
|
options_count |
int
|
The total count of available options, relevant only if a limit is set. |
None
|
Source code in ngwidgets/combobox.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
components
Created on 2023-12-16
This components module has the classes Component and Components for managing components of an online software components bazaar It was created for nicegui components but may be adapted to other context by modifying the topic,
Prompts for LLM: - Create Python classes Component and Components for managing UI components, including loading and saving functionality. - Develop a data class in Python to represent a UI component with the attributes: name: The title or identifier of the component. source: A web link directing to where the component's code can be found. demo_url: A web link to an image or video showing the component in action. doc_url: A web link to any documentation or detailed information about the component. issue: Reference to any known issues or bugs related to the component, typically tracked on platforms like GitHub. fixed: Date marking when any known issues or bugs with the component were resolved. - Implement methods in Components to load and save a collection of Component instances from/to a YAML file.
Main author: OpenAI's language model (instructed by WF)
Component
Represents a single component with its associated metadata.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the component. |
description(str) |
str
|
a multiline description of the component |
source |
Optional[str]
|
The source code URL of the component, if available. |
demo_url |
Optional[str]
|
The URL of an online demo of the component, if available. |
demo_image_url |
Optional[str]
|
The URL of a picture and/or video demonstrating the component, if available. |
doc_url |
Optional[str]
|
The URL of the documentation for the component, if available. |
issue |
Optional[str]
|
The identifier for any related issue (github), if applicable. |
fixed |
Optional[str]
|
The date on which any related issue was fixed, if applicable. |
Source code in ngwidgets/components.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
Components
Components
Source code in ngwidgets/components.py
55 56 57 58 59 60 61 62 |
|
components_view
Created on 2023-12-16
@author: wf
ComponentView
Display a single component
Source code in ngwidgets/components_view.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
setup(container)
Setup a card for the component
Source code in ngwidgets/components_view.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
ComponentsView
Display a collection of components in a grid layout
Source code in ngwidgets/components_view.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
setup()
Set up the UI elements to render the collection of components as a grid layout with four columns.
Source code in ngwidgets/components_view.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
update_display(*_args)
Update the displayed components based on the slider's position
Source code in ngwidgets/components_view.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
dateparser
Created on 2023-12-03
@author: wf
DateParser
A parser for converting date strings with timezone information into ISO 8601 format.
Attributes:
Name | Type | Description |
---|---|---|
aliases |
list
|
A list of tuples mapping timezone string aliases to their canonical form. |
whois_timezone_info |
dict
|
A dictionary mapping timezone abbreviations to their UTC offsets. |
Source code in ngwidgets/dateparser.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
parse_date(date_str)
Parses a date string and converts it to ISO 8601 format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_str |
str
|
The date string to be parsed. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the ISO 8601 date string |
Source code in ngwidgets/dateparser.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
debouncer
Debouncing module for managing rapid function calls and providing UI feedback. Created on 2024-06-08
Debouncer
A class to manage debouncing of function calls.
This class allows for debouncing function calls which can be either CPU-bound or I/O-bound. It includes optional callbacks that execute at the start and completion of the debounced function.
Source code in ngwidgets/debouncer.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
__init__(delay=0.33, debounce_cpu_bound=False, debounce_task_name='Debounce Task', debug=False)
Initialize the Debouncer with a specific delay.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
delay |
float
|
The debouncing delay in seconds. Default is 0.330 seconds. |
0.33
|
debounce_cpu_bound |
bool
|
If True, use CPU-bound execution; otherwise use I/O-bound execution. |
False
|
debounce_task_name |
str
|
The name to use for the task. |
'Debounce Task'
|
debug(bool) |
if True show debug info |
required |
Source code in ngwidgets/debouncer.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
debounce(func, *args, on_start=None, on_done=None, **kwargs)
async
Debounce the given function call, using either CPU-bound or I/O-bound execution based on the flag. Optional callbacks can be specified for execution at the start and end of the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable
|
The function to be debounced. |
required |
on_start |
Optional[Callable[[], Any]]
|
Function to call just before the delay starts. |
None
|
on_done |
Optional[Callable[[], Any]]
|
Function to call after the function execution completes. |
None
|
*args |
Positional arguments passed to the function. |
()
|
|
**kwargs |
Keyword arguments passed to the function. |
{}
|
Source code in ngwidgets/debouncer.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
log(call_type, func, *args, **kwargs)
log the call
Source code in ngwidgets/debouncer.py
43 44 45 46 47 48 49 50 |
|
DebouncerUI
A class to manage UI feedback for debouncing, using a specific UI container.
Source code in ngwidgets/debouncer.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
__init__(parent, delay=0.33, debounce_cpu_bound=False, debounce_task_name='Debounce Task', debug=False)
Initialize the Debouncer UI within a specified parent container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent |
The container in which the UI feedback should be managed. |
required | |
delay |
float
|
The debouncing delay in seconds. |
0.33
|
debounce_cpu_bound |
bool
|
If True, use CPU-bound execution; otherwise use I/O-bound execution. |
False
|
debounce_task_name |
str
|
The name to use for the task. |
'Debounce Task'
|
debug(bool) |
if True show debug info |
required |
Source code in ngwidgets/debouncer.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
debounce(func, *args, on_start=None, on_done=None, **kwargs)
Debounce the given function call, managing UI feedback appropriately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable
|
The function to be debounced. |
required |
*args |
Positional arguments passed to the function. |
()
|
|
**kwargs |
Keyword arguments passed to the function. |
{}
|
Source code in ngwidgets/debouncer.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
dict_edit
Created on 2023-06-22
@author: wf
DictEdit
NiceGUI based user interface for dictionary or dataclass editing that can be customized for each field in a form.
Attributes:
Name | Type | Description |
---|---|---|
d |
Union[dict, dataclass]
|
The data to be edited, converted to a dict if a dataclass. |
form_ui_def |
FormUiDef
|
The UI definition for the form (if any). |
card |
card
|
The card element containing the form. |
inputs |
Dict[str, Input]
|
A dictionary mapping field names to input elements. |
Source code in ngwidgets/dict_edit.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
__init__(data_to_edit, form_ui_def=None, customization=None)
Initialize the DictEdit instance with the given data and optional UI definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_to_edit |
Union[dict, dataclass]
|
The dictionary or dataclass to be edited. |
required |
form_ui_def |
Optional[FormUiDef]
|
The UI definition for the form. If not provided, it will be generated automatically. |
None
|
customization |
Optional[Dict[str, Dict[str, Any]]]
|
Customizations for the form fields. |
None
|
Source code in ngwidgets/dict_edit.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
add_on_change_handler(key, handler)
Adds an on_change event handler to the input corresponding to the given key.
Source code in ngwidgets/dict_edit.py
192 193 194 195 |
|
customize(customization)
Customizes the UI fields based on the given customization dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
customization |
Dict[str, Dict[str, Any]]
|
A dictionary where each key corresponds to a field name, and the value is another dictionary specifying 'label', 'size', and optionally 'validation'. |
required |
Example
customization = { 'given_name': {'label': 'Given Name', 'size': 50}, 'family_name': {'label': 'Family Name', 'size': 50} }
Source code in ngwidgets/dict_edit.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
setup()
Sets up the UI by creating a card and expansion for the form based on form_ui_def.
Source code in ngwidgets/dict_edit.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
FieldUiDef
dataclass
A generic user interface definition for a field.
Source code in ngwidgets/dict_edit.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
from_field(field)
staticmethod
Automatically creates a FieldUiDef from a dataclass field
Source code in ngwidgets/dict_edit.py
28 29 30 31 32 33 |
|
from_key_value(key, value)
staticmethod
Automatically create a FieldUiDef from a key,value pair
Source code in ngwidgets/dict_edit.py
35 36 37 38 39 40 |
|
FormUiDef
dataclass
A definition for the entire form's UI.
Source code in ngwidgets/dict_edit.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
from_dataclass(data)
staticmethod
Automatically creates a FormUiDef from a dataclass.
Source code in ngwidgets/dict_edit.py
53 54 55 56 57 58 59 |
|
from_dict(dictionary)
staticmethod
Automatically creates a FormUiDef from a dictionary.
Source code in ngwidgets/dict_edit.py
61 62 63 64 65 66 67 68 |
|
editor
Created on 2022-11-27
@author: wf
Editor
helper class to open the system defined editor
see https://stackoverflow.com/questions/1442841/lauch-default-editor-like-webbrowser-module
Source code in ngwidgets/editor.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
extract_text(html_text)
classmethod
extract the text from the given html_text
Parameters:
Name | Type | Description | Default |
---|---|---|---|
html_text(str) |
the input for the html text |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the plain text |
Source code in ngwidgets/editor.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
open(file_source, extract_text=True, default_editor_cmd='/usr/local/bin/atom')
classmethod
open an editor for the given file_source
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_source(str) |
the path to the file |
required | |
extract_text(bool) |
if True extract the text from html sources |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the path to the file e.g. a temporary file if the file_source points to an url |
Source code in ngwidgets/editor.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
open_tmp_text(text, file_name=None)
classmethod
open an editor for the given text in a newly created temporary file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text(str) |
the text to write to a temporary file and then open |
required | |
file_name(str) |
the name to use for the file |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the path to the temp file |
Source code in ngwidgets/editor.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
file_selector
Created on 2023-07-24
@author: wf
FileSelector
nicegui FileSelector
Source code in ngwidgets/file_selector.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
__init__(path, extensions=None, handler=None, filter_func=None, create_ui=True)
constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path to the directory to start building the tree from. |
required |
extensions(dict) |
the extensions to filter for as a dictionary with name as key and extension as value |
required | |
handler(Callable) |
handler function to call on selection |
required | |
filter_func(Callable) |
optional filter function |
required | |
create_ui(bool) |
if True create the self.tree ui.tree nicegui component - allows for testing the structure without ui by setting to False |
required |
Source code in ngwidgets/file_selector.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
expand(node_ids)
expand the nodes with the given ids
node_ids(list): the list of node ids to be expanded
Source code in ngwidgets/file_selector.py
179 180 181 182 183 184 185 186 |
|
find_node_by_id(tree, id_to_find)
Recursive function to find a node (file or directory) by its ID in a directory tree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree |
dict
|
A dictionary representing the directory tree. The tree is constructed with each node containing 'id' (str) as a unique identifier, 'value' (str) as the path to the file or directory, and 'children' (list of dict) as a list of child nodes. |
required |
id_to_find |
str
|
The ID of the node to find in the directory tree. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
Optional[Dict[str, Union[str, List[Dict]]]]
|
The node associated with the found ID. Returns None if the ID is not found. |
Source code in ngwidgets/file_selector.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
get_dir_tree(path, extensions, id_path=[1])
Recursive function to construct a directory tree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path to the directory to start building the tree from. |
required |
extensions(dict) |
the extensions to filter for as a dictionary with name as key and extension as value |
required | |
id_path |
List[int]
|
List of integers representing the current path in the tree. |
[1]
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Optional[Dict[str, Union[str, List[Dict]]]]
|
A dictionary representing the directory tree. For each directory or .scad file found, |
Optional[Dict[str, Union[str, List[Dict]]]]
|
it will add a dictionary to the 'children' list of its parent directory's dictionary. |
Source code in ngwidgets/file_selector.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
get_path_items(path)
Get sorted list of items in a specified directory path, filtering out non-relevant files like ._
files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The directory path to list items from. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A sorted list of relevant items from the directory. Returns an empty list if an error occurs. |
Source code in ngwidgets/file_selector.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
select_file(vcea)
async
select the given file and call my handler on the file path of it
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vcea(ValueChangeEventArguments) |
the tree selection event |
required |
Source code in ngwidgets/file_selector.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
input_webserver
Created on 2023-09-12
@author: wf
InputWebSolution
Bases: WebSolution
A WebSolution that is focused on handling a single input.
Attributes:
Name | Type | Description |
---|---|---|
is_local |
bool
|
Indicates if the input source is local or remote. |
input |
str
|
The input data or path to be processed. |
Source code in ngwidgets/input_webserver.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
__init__(webserver, client)
Initializes the InputWebSolution instance with the webserver and client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
webserver |
NiceGuiWebserver
|
The webserver instance this solution is part of. |
required |
client |
Client
|
The client interacting with this solution. |
required |
Source code in ngwidgets/input_webserver.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
about()
async
show about
Source code in ngwidgets/input_webserver.py
154 155 156 157 158 |
|
configure_menu()
Configures the menu items specific to this web solution. This method is intended to be overridden by subclasses to provide custom menu behavior. The base method does nothing and can be extended in subclasses.
Source code in ngwidgets/input_webserver.py
218 219 220 221 222 223 224 |
|
configure_settings()
Configures settings specific to this web solution. This method is intended to be overridden by subclasses to provide custom settings behavior. The base method does nothing and can be extended in subclasses.
Source code in ngwidgets/input_webserver.py
211 212 213 214 215 216 |
|
home()
async
provide the main content page
Source code in ngwidgets/input_webserver.py
147 148 149 150 151 152 |
|
input_changed(cargs)
react on changed input
Source code in ngwidgets/input_webserver.py
79 80 81 82 83 84 |
|
open_file()
async
Opens a Local filer picker dialog and reads the selected input file.
Source code in ngwidgets/input_webserver.py
132 133 134 135 136 137 138 139 140 141 142 143 |
|
prepare_ui()
handle the command line arguments
Source code in ngwidgets/input_webserver.py
226 227 228 229 230 231 232 233 234 235 |
|
read_and_optionally_render(input_str, with_render=False)
async
Reads the given input and optionally renders the given input
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_str |
str
|
The input string representing a URL or local file. |
required |
with_render(bool) |
if True also render |
required |
Source code in ngwidgets/input_webserver.py
100 101 102 103 104 105 106 107 108 109 110 111 |
|
read_input(input_str)
Reads the given input and handles any exceptions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_str |
str
|
The input string representing a URL or local file. |
required |
Source code in ngwidgets/input_webserver.py
86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
reload_file()
async
reload the input file
Source code in ngwidgets/input_webserver.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
settings()
async
Generates the settings page
Source code in ngwidgets/input_webserver.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
setup_about()
display an About
Source code in ngwidgets/input_webserver.py
160 161 162 163 164 |
|
setup_footer(with_log=True, handle_logging=True, max_lines=20, log_classes='w-full h-40')
async
setup a footer with an optional log view
Source code in ngwidgets/input_webserver.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
InputWebserver
Bases: NiceGuiWebserver
a webserver around a single input file of given filetypes
Source code in ngwidgets/input_webserver.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
__init__(config=None)
constructor
Source code in ngwidgets/input_webserver.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
configure_run()
override the run configuration
Source code in ngwidgets/input_webserver.py
42 43 44 45 46 47 48 49 50 51 52 |
|
leaflet
https://github.com/zauberzeug/nicegui/blob/main/examples/map/leaflet.py
@author: rodja
modified 2023-08-16 to handle set_zoom and draw_path @author: wf
leaflet
Bases: element
nicegui Leaflet integration
see https://leafletjs.com/
Source code in ngwidgets/leaflet.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
draw_path(path)
Draw a path on the map based on list of lat-long tuples.
Source code in ngwidgets/leaflet.py
38 39 40 |
|
llm
Created on 2023-06-23
@author: wf
LLM
Large Language Model access wrapper
Source code in ngwidgets/llm.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
__init__(api_key=None, model=DEFAULT_MODEL, force_key=False, prompts_filepath=None)
constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key(str) |
the access key |
required | |
model(str) |
the model to use |
required | |
prompt_filepath(str) |
the filepath for the prompt logging |
required |
Source code in ngwidgets/llm.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
ask(prompt_text, model=None, temperature=0.7)
ask a prompt
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt_text(str) |
The text of the prompt to send to the model. |
required | |
model(str) |
the model to use - if None self.model is used |
required | |
temperature(float) |
Controls randomness in the response. Lower is more deterministic. |
required |
Returns: str: the answer
Source code in ngwidgets/llm.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
available()
check availability of API by making sure there is an api_key
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the Large Language Model is available |
Source code in ngwidgets/llm.py
136 137 138 139 140 141 142 143 |
|
Prompt
a single prompt with response
Source code in ngwidgets/llm.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
Prompts
keep track of a series of prompts
Source code in ngwidgets/llm.py
44 45 46 47 48 49 50 |
|
local_filepicker
LocalFilePicker
Bases: dialog
see https://raw.githubusercontent.com/zauberzeug/nicegui/main/examples/local_file_picker/local_file_picker.py
Source code in ngwidgets/local_filepicker.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
__init__(directory, *, upper_limit=..., multiple=False, show_hidden_files=False)
Local File Picker
This is a simple file picker that allows you to select a file from the local filesystem where NiceGUI is running.
:param directory: The directory to start in. :param upper_limit: The directory to stop at (None: no limit, default: same as the starting directory). :param multiple: Whether to allow multiple files to be selected. :param show_hidden_files: Whether to show hidden files.
Source code in ngwidgets/local_filepicker.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
lod_grid
Created on 2023-10-3
@author: wf
GridConfig
dataclass
Configuration for initializing a ListOfDictsGrid.
Source code in ngwidgets/lod_grid.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
ListOfDictsGrid
ag grid based on list of dict
see https://nicegui.io/documentation/ag_grid see https://github.com/zauberzeug/nicegui/discussions/1833
Source code in ngwidgets/lod_grid.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
__init__(lod=None, config=None)
Initialize the ListOfDictsGrid object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lod |
Optional[List[Dict]]
|
List of dictionaries to be displayed. |
None
|
config(GridConfig) |
configuration for the grid behavior |
required |
Source code in ngwidgets/lod_grid.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
delete_selected_rows(_args)
async
Delete the currently selected rows based on the key column.
Source code in ngwidgets/lod_grid.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
get_cell_value(key_value, col_key)
get the value for the given cell
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_value |
Any
|
The value of the key column for the row to update. |
required |
row_key |
str
|
The column key of the cell to update. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
the value of the cell or None if the row doesn't exist |
Source code in ngwidgets/lod_grid.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
get_column_def(col)
get the column definition for the given column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
col |
str
|
The field name of the column where checkboxes should be enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
Dict |
Dict
|
the column definition |
Source code in ngwidgets/lod_grid.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
get_row_data()
get the complete row data
Source code in ngwidgets/lod_grid.py
270 271 272 273 274 275 |
|
get_row_for_key(key_value)
the the row for the given key_value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_value |
str
|
str |
required |
Source code in ngwidgets/lod_grid.py
227 228 229 230 231 232 233 234 235 |
|
get_rows_by_key()
Organize rows in a dictionary of dictionaries, indexed by the key column value specified in GridConfig.
Returns:
Type | Description |
---|---|
Dict[Any, Dict[str, Any]]
|
Dict[Any, Dict[str, Any]]: A dictionary of dictionaries, with each sub-dictionary representing a row, indexed by the key column values. |
Source code in ngwidgets/lod_grid.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
get_selected_rows()
async
get the currently selected rows
Source code in ngwidgets/lod_grid.py
365 366 367 368 369 370 |
|
handle_exception(ex)
Handles exceptions thrown during grid initialization or operation.
In debug mode, this method prints the stack trace and re-raises the exception for further debugging. In non-debug mode, it notifies the user of a general error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ex |
Exception
|
The exception that was caught. |
required |
Raises:
Type | Description |
---|---|
Exception
|
Re-raises the exception in debug mode for further debugging. |
Source code in ngwidgets/lod_grid.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
load_lod(lod, columnDefs=None)
load the given list of dicts
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lod(list) |
a list of dicts to be loaded into the grid |
required | |
columnDefs(list) |
a list of column definitions |
required |
Source code in ngwidgets/lod_grid.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|
new_row(_args)
async
add a new row
Source code in ngwidgets/lod_grid.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
onSizeColumnsToFit(_msg)
async
see https://www.reddit.com/r/nicegui/comments/17cg0o5/aggrid_autosize_columns_to_data_width/
Source code in ngwidgets/lod_grid.py
295 296 297 298 299 300 |
|
select_all_rows()
select all my ag_grid rows
Source code in ngwidgets/lod_grid.py
372 373 374 375 376 |
|
setDefaultColDef()
set the default column definitions
Source code in ngwidgets/lod_grid.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
set_checkbox_renderer(checkbox_col)
set cellRenderer to checkBoxRenderer for the given column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
checkbox_col |
str
|
The field name of the column where |
required |
Source code in ngwidgets/lod_grid.py
157 158 159 160 161 162 163 164 165 166 167 |
|
set_checkbox_selection(checkbox_col)
Set the checkbox selection for a specified column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
checkbox_col |
str
|
The field name of the column where checkboxes should be enabled. |
required |
Source code in ngwidgets/lod_grid.py
169 170 171 172 173 174 175 176 177 178 |
|
set_column_def(col, key, value)
Set a value in a column definition dictionary for a specified column.
This method updates the column definition dictionary for a given column by setting a specific key to a provided value. If the column definition exists, the key-value pair is updated; if not, no changes are made.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
col |
str
|
The name of the column to update. |
required |
key |
str
|
The key in the column definition dictionary to set. |
required |
value |
Any
|
The value to assign to the key in the dictionary. |
required |
Returns:
Name | Type | Description |
---|---|---|
Dict |
Dict
|
The updated column definition dictionary, or None if the column does not exist. |
Source code in ngwidgets/lod_grid.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
setup_button_row()
set up a button row
Source code in ngwidgets/lod_grid.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
update()
update my aggrid
Source code in ngwidgets/lod_grid.py
358 359 360 361 362 363 |
|
update_cell(key_value, col_key, value)
Update a cell in the grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_value |
Any
|
The value of the key column for the row to update. |
required |
row_key |
str
|
The column key of the cell to update. |
required |
value |
Any
|
The new value for the specified cell. |
required |
Source code in ngwidgets/lod_grid.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
update_index(lenient=False)
update the index based on the given key column
Source code in ngwidgets/lod_grid.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
log_view
Created on 2023-11-15
@author: wf
LogElementHandler
Bases: Handler
A logging handler that emits messages to a log element.
Source code in ngwidgets/log_view.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
login
Created on 2023-10-31
@author: wf
Login
Bases: object
nicegui login support
Source code in ngwidgets/login.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
__init__(webserver, users)
Constructor
Source code in ngwidgets/login.py
16 17 18 19 20 21 |
|
authenticated()
check whether the current user is authenticated
Source code in ngwidgets/login.py
23 24 25 26 27 28 |
|
get_username()
Get the username of the currently logged-in user
Source code in ngwidgets/login.py
36 37 38 39 40 |
|
login(solution)
async
login
Source code in ngwidgets/login.py
42 43 44 45 46 47 48 49 50 |
|
logout()
async
logout
Source code in ngwidgets/login.py
30 31 32 33 34 |
|
show_login()
async
show the login view
Source code in ngwidgets/login.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
markup_header
Created on 2023-11-19
@author: wf
MarkupHeader
Helper to generate tabulate compatible markup header lines.
Source code in ngwidgets/markup_header.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
get_markup(title, markup_format, level=1)
classmethod
Generates a formatted header string based on the specified markup format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
The title to be formatted as the header. |
required |
markup_format |
str
|
The markup format for the header. |
required |
level |
int
|
The section level to generate a header for. |
1
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The formatted header string. |
Source code in ngwidgets/markup_header.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
ngwidgets_cmd
Created on 2023-09-10
@author: wf
NiceguiWidgetsCmd
Bases: WebserverCmd
command line handling for ngwidgets
Source code in ngwidgets/ngwidgets_cmd.py
13 14 15 16 |
|
main(argv=None)
main call
Source code in ngwidgets/ngwidgets_cmd.py
19 20 21 22 23 24 25 26 27 28 |
|
orjson_response
Created on 2023-11-19
@author: wf
ORJSONResponse
Bases: JSONResponse
A FastAPI response class that uses orjson for JSON serialization.
Source code in ngwidgets/orjson_response.py
13 14 15 16 17 18 19 20 21 22 23 24 |
|
render(content)
Override the render method to use orjson for serialization.
Source code in ngwidgets/orjson_response.py
20 21 22 23 24 |
|
pdfviewer
Created on 2023-09-17
@author: wf
pdfjs_urls
dataclass
see https://mozilla.github.io/pdf.js/getting_started/#download
setup the content delivery network urls
Source code in ngwidgets/pdfviewer.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
configure()
Source code in ngwidgets/pdfviewer.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
pdfviewer
Bases: element
nicegui PDF.js integration
see https://mozilla.github.io/pdf.js/
Source code in ngwidgets/pdfviewer.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
__init__(version='3.11.174', cdn='cdnjs', debug=False)
constructor
Source code in ngwidgets/pdfviewer.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
profiler
Created on 2022-11-18
@author: wf
Profiler
simple profiler
Source code in ngwidgets/profiler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
__init__(msg, profile=True, with_start=True)
construct me with the given msg and profile active flag
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg(str) |
the message to show if profiling is active |
required | |
profile(bool) |
True if messages should be shown |
required |
Source code in ngwidgets/profiler.py
15 16 17 18 19 20 21 22 23 24 25 26 |
|
start()
start profiling
Source code in ngwidgets/profiler.py
28 29 30 31 32 33 34 |
|
time(extraMsg='')
time the action and print if profile is active
Source code in ngwidgets/profiler.py
36 37 38 39 40 41 42 43 |
|
progress
NiceguiProgressbar
Bases: Progressbar
Nicegui progress bar wrapper.
Source code in ngwidgets/progress.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
__init__(total, desc, unit, label_color='#8D92C4 ')
Initialize the NiceguiProgressbar instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
total |
int
|
The total value (maximum) of the progress bar. |
required |
desc |
str
|
A short description of the task for which the progress is being shown. |
required |
unit |
str
|
The unit of measurement for the progress (e.g., 'step', 'item'). |
required |
label_color(str) |
the color to use for the label |
required |
The progress bar is initially set to invisible and its value to 0.
Source code in ngwidgets/progress.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
reset()
reset
Source code in ngwidgets/progress.py
68 69 70 71 72 73 |
|
set_description(desc)
set my description
Source code in ngwidgets/progress.py
75 76 77 78 79 80 |
|
Progressbar
dataclass
Generic progress bar
Source code in ngwidgets/progress.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
update_total()
Update the total value in the progress bar.
Source code in ngwidgets/progress.py
29 30 31 32 33 |
|
TqdmProgressbar
Bases: Progressbar
Tqdm progress bar wrapper.
Source code in ngwidgets/progress.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
projects
Created on 2023-12-14
This module, developed as part of the ngwidgets package under the instruction of WF, provides
classes and methods for interacting with the Python Package Index (PyPI). It includes the
Project
data class for representing software projects and the PyPi
class for searching
and retrieving package information from PyPI. The code facilitates the creation of tools and
applications that interact with PyPI for information about Python packages.
Prompts for LLM: - Create Python classes Project and Projects (holding a list of Project elements) for interacting with PyPI and github, including search functionality. - Develop a data class in Python to represent a software project with the attributes. name (str): The name of the project. package (str): The package name on PyPI. demo (str): A URL to a demo of the project, if available. forum_post (str): A URL to a forum post discussing the project. github (str): A URL to the GitHub repository of the project. pypi (str): A URL to the PyPI page of the project. image_url (str): A URL to an image representing the project. stars (int): Number of stars on GitHub. github_description (str): Description of the project from GitHub. pypi_description (str): Description of the project from PyPI. avatar (str): A URL to the avatar image of the author/maintainer. search_text (str): Text used for searching the project. github_author (str): The GitHub username of the project's author. pypi_author (str): The PyPI username of the project's author. created_at (datetime): The date when the project was created. downloads (int): Number of downloads from PyPI. categories (List[str]): Categories associated with the project. version (str): The current version of the project on PyPI.
- Implement methods to search PyPI and github for packages/repos that represent projects and retrieve detailed package information on a given topic.
- allow saving and loading the collected projects
Main author: OpenAI's language model (instructed by WF)
GitHubAccess
A class to handle GitHub API access.
This class provides functionalities to access the GitHub API, either with authenticated or unauthenticated access. It can read a GitHub access token from a YAML file in a specified directory for authenticated access, which increases the rate limit for API requests. If no access token is provided or found in the YAML file, it defaults to unauthenticated access with lower rate limits.
Attributes:
Name | Type | Description |
---|---|---|
github |
Github
|
An instance of the Github class from the PyGithub library, configured for either authenticated or unauthenticated access. |
Source code in ngwidgets/projects.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
__init__(default_directory=None, access_token=None)
Initialize the GitHub instance.
If an access_token is provided, use it for authenticated access to increase the rate limit. Otherwise, attempt to read the access token from a YAML file in the default directory. If no token is found, access is unauthenticated with lower rate limits.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default_directory |
str
|
Path to the directory where the access token file is stored. |
None
|
access_token |
Optional[str]
|
A GitHub personal access token. Defaults to None. |
None
|
Source code in ngwidgets/projects.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
search_repositories(query)
Search for GitHub repositories matching a given query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
str
|
The search query string. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary of repository objects keyed by their full names. |
Source code in ngwidgets/projects.py
106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
Project
A data class representing a software project, potentially from PyPI or GitHub.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the project. |
package |
str
|
The package name on PyPI. |
demo |
str
|
A URL to a demo of the project, if available. |
forum_post |
str
|
A URL to a forum post discussing the project. |
github |
str
|
A URL to the GitHub repository of the project. |
pypi |
str
|
A URL to the PyPI page of the project. |
image_url |
str
|
A URL to an image representing the project. |
stars |
int
|
Number of stars on GitHub. |
github_description |
str
|
Description of the project from GitHub. |
pypi_description |
str
|
Description of the project from PyPI. |
avatar |
str
|
A URL to the avatar image of the author/maintainer. |
search_text |
str
|
Text used for searching the project. |
github_author |
str
|
The GitHub username of the project's author. |
pypi_author |
str
|
The PyPI username of the project's author. |
created_at |
datetime
|
The date when the project was created. |
downloads |
int
|
Number of downloads from PyPI. |
categories |
List[str]
|
Categories associated with the project. |
version |
str
|
The current version of the project on PyPI. |
Solution bazaar attributes
component_url(str): the url of a yaml file with component declarations, demo, install and usage information solution_tags(str): a list of comma separated tags for checking the conformance of the project to the solution bazaar guidelines
Source code in ngwidgets/projects.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
component_count: int
property
Counts the number of components associated with the project. Returns 0 if there are no components or if components_url is not set.
install_instructions: str
property
Get the installation instructions for the project.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Installation instructions for the project. |
from_github(repo)
classmethod
Class method to create a Project instance from a GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo(Repository.Repository) |
The github repository |
required | |
github_access |
GitHubAccess
|
Instance of GitHubAccess for API calls. |
required |
Returns:
Name | Type | Description |
---|---|---|
Project |
Project
|
An instance of the Project class filled with GitHub repository details. |
Source code in ngwidgets/projects.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
from_pypi(package_info)
classmethod
Class method to create a Project instance from a PyPI package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_info |
Dict
|
Dictionary containing package data from PyPI. |
required |
Returns:
Name | Type | Description |
---|---|---|
Project |
Project
|
An instance of the Project class filled with PyPI package details. |
Source code in ngwidgets/projects.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
get_components(cache_directory=None, cache_valid_secs=3600)
method to lazy-loaded components. Loads components from URL if components_url is set. If a cache directory is provided, it caches the YAML file in that directory. The cache validity period can be specified in seconds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_directory |
str
|
Directory for caching the YAML files. If None, caching is disabled. |
None
|
cache_valid_secs |
int
|
The number of seconds for which the cache is considered valid. Defaults to 3600 seconds (1 hour). |
3600
|
Returns:
Name | Type | Description |
---|---|---|
Components |
Components
|
The components associated with the project. |
Source code in ngwidgets/projects.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
get_raw_url(owner, repo_name, branch_name, file_path)
classmethod
Construct the URL for the raw file_path from the owner, repository name, and branch name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owner |
str
|
The owner of the GitHub repository. |
required |
repo_name |
str
|
The name of the GitHub repository. |
required |
branch_name |
str
|
The name of the branch. |
required |
file_path(str) |
the file_path to get the raw content for |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The URL of the raw file_path if it exists |
Source code in ngwidgets/projects.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
merge_pypi(pypi)
merge the given pypi project info to with mine
Source code in ngwidgets/projects.py
266 267 268 269 270 271 272 273 |
|
Projects
handle a list of python projects on a specific topic
Source code in ngwidgets/projects.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
|
default_directory: Path
property
writable
The default directory for saving and loading projects. Returns: Path: The default directory path.
file_path: Path
property
The file path for saving and loading projects, based on the topic. Returns: Path: The file path.
__post_init__()
Post-initialization to set non-static attributes.
Source code in ngwidgets/projects.py
391 392 393 394 395 396 |
|
extract_repo_name_from_url(url)
Extract the repository name in 'user/repo' format from a GitHub URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The GitHub URL. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The repository name or None if not extractable. |
Source code in ngwidgets/projects.py
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
|
get_file_update_time()
Get the last modification time of the projects file.
Returns:
Name | Type | Description |
---|---|---|
datetime |
The last modification time of the file or None if file does not exist. |
Source code in ngwidgets/projects.py
398 399 400 401 402 403 404 405 406 407 408 |
|
get_github_projects(repo_dict, progress_bar=None)
Get GitHub projects related to the specified topic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
github_access |
GitHubAccess
|
An instance of GitHubAccess for API calls. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Project]
|
Dict[str, Project]: A dictionary of GitHub projects with their URLs as keys and Project instances as values. |
Source code in ngwidgets/projects.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
|
get_project4_solution_id(solution_id)
Get a project based on the provided solution_id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
solution_id |
str
|
The solution_id to search for. |
required |
Returns:
Name | Type | Description |
---|---|---|
Project |
Project
|
The Project instance matching the provided solution_id, or None if not found. |
Source code in ngwidgets/projects.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
|
load(directory=None, set_self=True, lenient=True)
Load a list of Project instances from a JSON file. Args: directory (str, optional): The directory where the file is located. If None, uses the default directory. set_self(bool): if True set self.projects with the result lenient(bool): if True allow that there is no projects json file Returns: List[Project]: A list of Project instances loaded from the file.
Source code in ngwidgets/projects.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
save(projects=None, directory=None)
Save a list of Project instances to a JSON file. Args: projects (List[Project]): A list of Project instances to be saved. directory (str, optional): The directory where the file will be saved. If None, uses the default directory.
Source code in ngwidgets/projects.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
sort_projects(projects, sort_key)
Sorts a list of projects based on the specified sort key, converting integers to fixed-length strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projects |
list
|
List of Project instances. |
required |
sort_key |
str
|
Attribute name to sort the projects by. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
Sorted list of projects. |
Source code in ngwidgets/projects.py
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
|
update(progress_bar=None, limit_github=None, limit_pypi=None)
Update the list of projects by retrieving potential projects from PyPI and GitHub based on the topic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
progress_bar |
Optional[Progressbar]
|
A progress bar instance to update during the process. |
None
|
limit_github |
Optional[int]
|
If set, limit the maximum number of GitHub projects to retrieve. |
None
|
limit_pypi |
Optional[int]
|
If set, limit the maximum number of PyPI projects to retrieve. |
None
|
Source code in ngwidgets/projects.py
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
|
PyPi
Wrapper class for interacting with PyPI, including search functionality.
Source code in ngwidgets/projects.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 |
|
get_package_info(package_name)
Get detailed information about a package from PyPI using urllib.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_name |
str
|
The name of the package to retrieve information for. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing package information. |
Raises:
Type | Description |
---|---|
URLError
|
If there is an issue with the URL. |
ValueError
|
If the response status code is not 200. |
Source code in ngwidgets/projects.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
|
search_packages(term, limit=None)
Search a package in the pypi repositories and retrieve detailed package information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
term |
str
|
The search term. |
required |
limit |
int
|
Maximum number of results to return. |
None
|
Returns:
Type | Description |
---|---|
list
|
List[Dict]: A list of dictionaries containing detailed package information. see https://raw.githubusercontent.com/shubhodeep9/pipsearch/master/pipsearch/api.py |
Source code in ngwidgets/projects.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 |
|
search_projects(term, limit=None)
Search for packages on PyPI and return them as Project instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
term |
str
|
The search term. |
required |
limit |
int
|
Maximum number of results to return. |
None
|
Returns:
Type | Description |
---|---|
List[Project]
|
List[Project]: A list of Project instances representing the search results. |
Source code in ngwidgets/projects.py
653 654 655 656 657 658 659 660 661 662 663 664 665 |
|
projects_view
Created on 2023-15-12
This module, developed as part of the ngwidgets package under the instruction of WF, provides
classes for displaying software projects in a NiceGUI application. It defines the
ProjectView
class for rendering a single project and the ProjectsView
class for
managing a collection of ProjectView
instances in a searchable and sortable card layout.
see https://github.com/WolfgangFahl/nicegui_widgets/issues/50
The implementation is inspired by a Streamlit application, as analyzed from a provided screenshot,
which includes UI elements such as a date picker widget, package metadata display, and installation
command. These will be recreated using NiceGUI's elements such as ui.date_picker()
, ui.label()
,
ui.link()
, ui.card()
, ui.text()
, and ui.input()
for a similar user experience.
For details on the original Streamlit implementation, refer to: https://raw.githubusercontent.com/jrieke/projects-hub/main/streamlit_app.py
Prompts for LLM: - Incorporate the Project and Projects classes from ngwidgets into NiceGUI. - Implement the setup method for ProjectView to render project details in a UI card. - Implement the setup method for ProjectsView to manage a searchable and sortable display of projects. - Adapt the webserver class from ngwidgets to use ProjectsView for displaying projects.
Main author: OpenAI's language model (instructed by WF)
ProjectView
display a single project
Source code in ngwidgets/projects_view.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
setup(container)
setup a card for my project
Source code in ngwidgets/projects_view.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
ProjectsView
display the available projects as rows and columns sorted by user preference (default: stars) and allows to search/filter
Source code in ngwidgets/projects_view.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
__init__(webserver, projects=None)
Initialize the ProjectsView with an optional collection of Projects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
webserver |
InputWebserver
|
The webserver that serves the projects. |
required |
projects |
Projects
|
The collection of software projects. If None, projects are loaded from storage. |
None
|
Source code in ngwidgets/projects_view.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
setup()
Set up the UI elements to render the collection of projects as a searchable and sortable card layout in NiceGUI.
Source code in ngwidgets/projects_view.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
update_last_update_label()
Update the label showing the last update time.
Source code in ngwidgets/projects_view.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
update_projects(p)
async
update the projects
Source code in ngwidgets/projects_view.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
update_view()
Update the view to render the filtered and sorted projects.
Source code in ngwidgets/projects_view.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
tristate
tristate.py
Created on 2023-12-10
@author: WF @author: OpenAI Assistant (ChatGPT Version 4)
This module provides a Tristate class for use in NiceGUI applications, creating a tri-state toggle input that cycles through predefined icon sets.
The implementation is inspired by examples and discussions from: - NiceGUI Custom Vue Component example: https://github.com/zauberzeug/nicegui/tree/main/examples/custom_vue_component - JSFiddle by WF: https://jsfiddle.net/wf_bitplan_com/941std72/8/ - Stack Overflow answer by WF: https://stackoverflow.com/a/27617418/1497139
Prompts for Reproducing this Code:
1. "Create a Python class Tristate in a module tristate for a NiceGUI component that serves as a tri-state toggle input."
2. "Implement icon cycling within the Python class to handle state changes without relying on JavaScript logic."
3. "Utilize Unicode icon sets within the Python class for the visual representation of each state."
4. "Ensure the Python class handles the reactivity and updates the Vue component's props when the state changes."
5. "Apply google style doc-strings and type hints for better code clarity and leverage black and isort for code formatting and import sorting."
6. "Provide comprehensive documentation within the Python class to explain the functionality and usage of each method and property."
7. "add proper authorship and iso-date of creation information in the module header"
8. "add a prompts for reproducing this code in the header comment section that will allow any proper LLM to reproduce this code"
9. "Introduce an update
method invocation within the state change logic to trigger a re-render of the component in NiceGUI.
10. "add links to https://github.com/zauberzeug/nicegui/tree/main/examples/custom_vue_component, https://jsfiddle.net/wf_bitplan_com/941std72/8/ and https://stackoverflow.com/a/27617418/1497139 for proper reference"
11. "Include the following Unicode icon sets in the Tristate component for NiceGUI:
'arrows' with Left Arrow ('←'), Up-Down Arrow ('↕️'), and Right Arrow ('→');
'ballot' with Ballot Box ('☐'), Ballot Box with Check ('☑️'), and Ballot Box with X ('☒️');
'check' with Checkbox ('☐'), Question Mark ('❔'), and Checkmark ('✔️');
'circles' with Circle ('⭘'), Bullseye ('🎯'), and Fisheye ('🔘');
'electrical' with Plug ('🔌'), Battery Half ('🔋'), and Lightning ('⚡');
'faces' with Sad Face ('☹️'), Neutral Face ('😐'), and Happy Face ('☺️');
'hands' with Thumbs Down ('👎'), Hand ('✋'), and Thumbs Up ('👍');
'hearts' with Empty Heart ('♡'), Half Heart ('❤️'), and Full Heart ('❤️');
'locks' with Unlocked ('🔓'), Locked with Pen ('🔏'), and Locked ('🔒');
'marks' with Question Mark ('❓'), Check Mark ('✅'), and Cross Mark ('❌');
'moons' with New Moon ('🌑'), Half Moon ('🌓'), and Full Moon ('🌕');
'musical_notes' with Single Note ('♪'), Double Note ('♫'), and Multiple Notes ('🎶');
'stars' with Empty Star ('☆'), Half Star ('★'), and Full Star ('★');
'traffic_lights' with Red ('🔴'), Yellow ('🟡'), and Green ('🟢');
'weather' with Cloud ('☁️'), Sun ('☀️'), and Thunderstorm ('⛈️')."
Tristate
Bases: Element
A Tristate toggle component for NiceGUI.
Attributes:
Name | Type | Description |
---|---|---|
icon_set |
str
|
The name of the icon set to use. |
current_icon_index |
int
|
The index of the current icon in the set. |
style |
str
|
CSS styling for the input element. |
Source code in ngwidgets/tristate.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
__init__(icon_set_name='marks', style='border: none;', on_change=None)
Initializes the Tristate component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
icon_set_name |
str
|
The name of the icon set to use. Default is 'marks'. |
'marks'
|
style |
str
|
CSS styling for the input element. Default is 'border: none;'. |
'border: none;'
|
on_change |
Optional[Callable]
|
Callback function for state changes. |
None
|
Source code in ngwidgets/tristate.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
cycle_icon(_=None)
Cycles through the icons in the set and updates the component.
Source code in ngwidgets/tristate.py
118 119 120 121 |
|
on_change(_=None)
Handles the change event, cycles the icon, and calls user-defined callback if any.
Source code in ngwidgets/tristate.py
112 113 114 115 116 |
|
update_props()
Updates the component properties with the current icon and style.
Source code in ngwidgets/tristate.py
123 124 125 126 127 128 |
|
users
Created on 2023-08-15
@author: wf
Users
A class to manage user credentials stored in a JSON file.
Attributes:
Name | Type | Description |
---|---|---|
dir_path |
str
|
The directory path where the JSON file resides. |
file_path |
str
|
The full path to the JSON file. |
Source code in ngwidgets/users.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
__init__(path_str)
Initialize the Users class and set file paths.
Source code in ngwidgets/users.py
23 24 25 26 27 28 29 |
|
add_user(username, password)
Add a new user with a hashed password to the data file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
username |
str
|
The username of the new user. |
required |
password |
str
|
The password for the new user. |
required |
Source code in ngwidgets/users.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
check_password(username, password)
Validate a password against its hashed version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
username |
str
|
The username of the user. |
required |
password |
str
|
The password to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the password matches, False otherwise. |
Source code in ngwidgets/users.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
load_password_data()
Load user data from the JSON file.
Returns:
Name | Type | Description |
---|---|---|
dict |
Dictionary containing username: password pairs. |
Source code in ngwidgets/users.py
46 47 48 49 50 51 52 53 54 55 56 |
|
save_password_data(data)
Save user data to the JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
dict
|
Dictionary containing username: password pairs. |
required |
Source code in ngwidgets/users.py
36 37 38 39 40 41 42 43 44 |
|
version
Created on 2023-09-12
@author: wf
Version
Version handling for nicegui widgets
Source code in ngwidgets/version.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
webserver
Created on 2023-09-10
@author: wf
NiceGuiWebserver
Bases: object
a basic NiceGuiWebserver
Source code in ngwidgets/webserver.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
__init__(config=None)
Constructor
Source code in ngwidgets/webserver.py
113 114 115 116 117 118 119 120 121 122 |
|
configure_run()
Configures specific before run steps of a web server. This method is intended to be overridden by subclasses to provide custom run behavior. The base method does nothing and can be extended in subclasses.
Source code in ngwidgets/webserver.py
219 220 221 222 223 224 225 226 |
|
optionalDebug(args)
classmethod
start the remote debugger if the arguments specify so
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args() |
The command line arguments |
required |
Source code in ngwidgets/webserver.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
page(client, wanted_action, *args, **kwargs)
async
Handle a page request for a specific client. This method ensures that a specific type of WebSolution (or its subclass) is created for each client and used throughout the client's interaction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client |
Client
|
The client making the request. |
required |
wanted_action(Callable) |
The function of the solution to perform. Might be overriden so we check the solution_instance |
required | |
*args, |
**kwargs
|
Additional arguments to pass to the action. |
required |
Returns:
Type | Description |
---|---|
The result of the action performed. |
Source code in ngwidgets/webserver.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
run(args)
Runs the UI of the web server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
list
|
The command line arguments. |
required |
Source code in ngwidgets/webserver.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
stop()
stop the server
Source code in ngwidgets/webserver.py
228 229 230 231 |
|
WebSolution
the user/client specific web context of a solution
Source code in ngwidgets/webserver.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
__init__(webserver, client)
construct a client specific WebSolution
Source code in ngwidgets/webserver.py
239 240 241 242 243 244 245 246 247 248 |
|
add_select(title, selection, background_color='#e6e6e6', **kwargs)
Add a select widget with a given title, selection options, and optional styling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
The title or label for the select widget. |
required |
selection |
Union[List[Any], Dict[str, Any]]
|
The options available for selection. - If a List, each element represents an option. - If a Dict, keys are option labels and values are the corresponding values. |
required |
background_color |
str
|
Hex color code for the background of the label. Defaults to "#e6e6e6". |
'#e6e6e6'
|
**kwargs |
Additional keyword arguments passed to the select widget creation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The created nicegui ui.select widget. |
Source code in ngwidgets/webserver.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
do_read_input(input_str)
Reads the given input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_str |
str
|
The input string representing a URL or local path. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the input content as a string |
Source code in ngwidgets/webserver.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
handle_exception(e, trace=None)
Handles an exception by creating an error message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
e |
BaseException
|
The exception to handle. |
required |
trace |
bool
|
Whether to include the traceback in the error message. Default is False. |
None
|
Source code in ngwidgets/webserver.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
link_button(name, target, icon_name, new_tab=True)
Creates a button with a specified icon that opens a target URL upon being clicked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name to be displayed on the button. |
required |
target |
str
|
The target URL that should be opened when the button is clicked. |
required |
icon_name |
str
|
The name of the icon to be displayed on the button. |
required |
new_tab(bool) |
if True open link in new tab |
required |
Returns:
Type | Description |
---|---|
The button object. |
see https://fonts.google.com/icons?icon.set=Material+Icons for potential icon names
Source code in ngwidgets/webserver.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
notify(msg)
call ui.notify with a context
Source code in ngwidgets/webserver.py
250 251 252 253 254 255 |
|
prepare()
async
make sure this solution context is ready for use
Source code in ngwidgets/webserver.py
257 258 259 260 261 262 263 |
|
prepare_ui()
call any code necessary before the first nicegui.ui call is done e.g. handling command line arguments
The base method does nothing and serves as a placeholder for subclasses to define their own UI preparation logic.
Source code in ngwidgets/webserver.py
265 266 267 268 269 270 271 272 |
|
round_label(title, background_color='#e6e6e6', **kwargs)
Creates a label with rounded corners and optional background color.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
The text to be displayed in the label. |
required |
background_color |
str
|
Hex color code for the label's background. Defaults to a light grey color ("#e6e6e6"). |
'#e6e6e6'
|
**kwargs |
Additional keyword arguments passed to the select widget creation. |
{}
|
Returns:
Type | Description |
---|---|
label
|
ui.label: A NiceGUI label element with rounded corners and the specified background color. |
Source code in ngwidgets/webserver.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
setup_content_div(setup_content=None, with_exception_handling=True, **kwargs)
async
Sets up the content frame div of the web server's user interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
setup_content |
Optional[Callable]
|
A callable for setting up the main content. It can be a regular function or a coroutine. |
None
|
with_exception_handling(bool) |
if True handle exceptions |
required |
Note
This method is asynchronous and should be awaited when called.
Source code in ngwidgets/webserver.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
|
setup_footer()
async
setup the footer
Source code in ngwidgets/webserver.py
429 430 431 432 433 434 435 |
|
setup_menu(detailed=None)
set up the default menu home/settings and about
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detailed(bool) |
if True add github,chat and help links |
required |
Source code in ngwidgets/webserver.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
|
toggle_icon(button)
toggle the icon of the given button
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ui.button |
the button that needs the icon to be toggled |
required |
Source code in ngwidgets/webserver.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
tool_button(tooltip, icon, handler=None, toggle_icon=None)
Creates a button with icon that triggers a specified function upon being clicked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tooltip |
str
|
The tooltip to be displayed. |
required |
icon |
str
|
The name of the icon to be displayed on the button. |
required |
handler |
function
|
The function to be called when the button is clicked. |
None
|
toggle_icon |
str
|
The name of an alternative icon to be displayed when the button is clicked. |
None
|
Returns:
Type | Description |
---|---|
button
|
ui.button: The icon button object. |
Source code in ngwidgets/webserver.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
WebserverConfig
configuration of a webserver
Source code in ngwidgets/webserver.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
__post_init__()
make sure the necessary fields exist
Source code in ngwidgets/webserver.py
43 44 45 46 47 48 49 50 |
|
get(config)
classmethod
Retrieves or initializes a WebserverConfig instance based on the provided 'config' parameter. This method ensures that essential properties like 'storage_secret', 'config_path', and 'storage_path' are set in the 'config' object. If a configuration file already exists at the 'yaml_path', it's loaded, and its values are used to update the provided 'config'. However, certain key properties like 'version', 'short_name', and 'default_port' can still be overridden by the provided 'config' if they are set.
If the configuration file does not exist, this method will create the necessary directories and save the provided 'config' as the initial configuration to the 'yaml_path', which is derived from 'config_path' and 'short_name' and typically located under the user's home directory in the '.solutions' folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
WebserverConfig
|
The configuration object with preferred or default settings. |
required |
Returns:
Name | Type | Description |
---|---|---|
WebserverConfig |
WebserverConfig
|
The configuration loaded from the YAML file, or the provided 'config' if the YAML file does not exist. |
Source code in ngwidgets/webserver.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
webserver_test
Created on 2023-11-03
@author: wf
ThreadedServerRunner
run the Nicegui Server in a thread
Source code in ngwidgets/webserver_test.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
__init__(ws, args=None, shutdown_timeout=5.0, debug=False)
Initialize the ThreadedServerRunner with a web server instance, optional arguments, and a shutdown timeout.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ws |
Any
|
The web server instance to run. |
required |
args |
Optional[Namespace]
|
Optional arguments to pass to the web server's run method. |
None
|
shutdown_timeout |
float
|
The maximum time in seconds to wait for the server to shutdown. |
5.0
|
debug |
bool
|
sets the debugging mode |
False
|
Source code in ngwidgets/webserver_test.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
start()
Start the web server thread.
Source code in ngwidgets/webserver_test.py
54 55 56 |
|
stop()
Stop the web server thread, signaling the server to exit if it is still running.
Source code in ngwidgets/webserver_test.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
warn(msg)
show the given warning message
Source code in ngwidgets/webserver_test.py
58 59 60 61 62 63 |
|
WebserverTest
Bases: Basetest
a webserver test environment
Attributes:
Name | Type | Description |
---|---|---|
ws |
An instance of the web server being tested. |
|
ws_thread |
The thread running the web server. |
|
client |
A test client for interacting with the web server. |
Source code in ngwidgets/webserver_test.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
getHtml(path)
get the html content for the given path
Source code in ngwidgets/webserver_test.py
193 194 195 196 197 198 |
|
get_html(path, expected_status_code=200)
get the html content for the given path
Source code in ngwidgets/webserver_test.py
182 183 184 185 186 187 188 189 190 191 |
|
get_html_for_post(path, data)
get the html content for the given path by posting the given data
Source code in ngwidgets/webserver_test.py
200 201 202 203 204 205 206 207 208 209 210 |
|
get_json(path, expected_status_code=200)
Sends a GET request to a specified path, verifies the response status code, and returns the JSON content of the response.
This method is useful for testing API endpoints that return JSON data. It ensures that the request to a given path returns the expected status code and then parses and returns the JSON response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The URL path to which the GET request is sent. |
required |
expected_status_code |
int
|
The expected HTTP status code for the response. Defaults to 200. |
200
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The parsed JSON data from the response. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the response status code does not match the expected status code. |
JSONDecodeError
|
If the response body cannot be parsed as JSON. |
Source code in ngwidgets/webserver_test.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
get_response(path, expected_status_code=200)
Sends a GET request to a specified path and verifies the response status code.
This method is used for testing purposes to ensure that a GET request to a given path returns the expected status code. It returns the response object for further inspection or testing if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The URL path to which the GET request is sent. |
required |
expected_status_code |
int
|
The expected HTTP status code for the response. Defaults to 200. |
200
|
Returns:
Name | Type | Description |
---|---|---|
Response |
Response
|
The response object from the GET request. |
Source code in ngwidgets/webserver_test.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
setUp(server_class, cmd_class, debug=False, profile=True)
Create and start a test instance of a web server using the specified server and command classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
server_class |
The class of the server to be tested. This should be a class reference that
includes a static |
required | |
cmd_class |
The command class used to parse command-line arguments for the server.
This class should have an initialization accepting |
required |
Returns:
Type | Description |
---|---|
An instance of WebserverTest containing the started server thread and test client. |
Raises:
Type | Description |
---|---|
ValueError
|
If an invalid server_class or cmd_class is provided. |
Example
test_server = WebserverTest.get_webserver_test(MyServerClass, MyCommandClass) test_server.client.get('/')
Source code in ngwidgets/webserver_test.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
tearDown()
tear Down everything
Source code in ngwidgets/webserver_test.py
154 155 156 157 158 159 160 |
|
widgets
Created on 2023-09-10
common nicegui widgets and tools
@author: wf
About
Bases: element
About Div for a given version
Source code in ngwidgets/widgets.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
__init__(version, font_size=24, font_family='Helvetica, Arial, sans-serif', **kwargs)
construct an about Div for the given version
Source code in ngwidgets/widgets.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
HideShow
A class representing a hideable/showable section in a NiceGUI application.
Source code in ngwidgets/widgets.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
__init__(hide_show_label=None, show_content=True, content_div=None, lazy_init=False, **kwargs)
Initialize the HideShow component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hide_show_label |
tuple[str, str]
|
Labels for shown/hidden states. |
None
|
show_content |
bool
|
Initial visibility state (default True). |
True
|
content_div |
Div with content to hide/show. |
None
|
|
lazy_init |
bool
|
If True, content_div initialized later. |
False
|
**kwargs |
Additional args for button element. |
{}
|
Source code in ngwidgets/widgets.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
add(widget)
Add a widget to content div.
Source code in ngwidgets/widgets.py
301 302 303 304 305 |
|
set_content(content_div=None)
Set or update content div.
Source code in ngwidgets/widgets.py
313 314 315 316 317 318 |
|
toggle_hide_show(_=None)
Toggle visibility of content.
Source code in ngwidgets/widgets.py
295 296 297 298 299 |
|
update()
Update the content div.
Source code in ngwidgets/widgets.py
307 308 309 310 311 |
|
Lang
A class representing languages, providing utility methods related to language data.
Source code in ngwidgets/widgets.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
get_language_dict()
classmethod
Get a dictionary of supported languages.
Returns:
Type | Description |
---|---|
dict
|
dict[str, str]: A dictionary where the keys are language codes (e.g., "en" for English) and the values are the corresponding names/representations in HTML entity format. |
Source code in ngwidgets/widgets.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
Link
a link
Source code in ngwidgets/widgets.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
create(url, text, tooltip=None, target=None, style=None, url_encode=False)
staticmethod
Create a link for the given URL and text, with optional URL encoding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL. |
required |
text |
str
|
The link text. |
required |
tooltip |
str
|
An optional tooltip. |
None
|
target |
str
|
Target attribute, e.g., _blank for opening the link in a new tab. |
None
|
style |
str
|
CSS style to be applied. |
None
|
url_encode |
bool
|
Flag to indicate if the URL needs encoding. default: False |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
HTML anchor tag as a string. |
Source code in ngwidgets/widgets.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
widgets_demo
Created on 2023-09-13
@author: wf
NiceGuiWidgetsDemo
Bases: InputWebSolution
Demonstration Solution
Source code in ngwidgets/widgets_demo.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 |
|
__init__(webserver, client)
Initialize the NiceGuiWidgetsDemoContext.
Calls the constructor of the base class ClientWebContext to ensure proper initialization and then performs any additional setup specific to NiceGuiWidgetsDemoContext.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
webserver |
NiceGuiWebserver
|
The webserver instance associated with this context. |
required |
client |
Client
|
The client instance this context is associated with. |
required |
Source code in ngwidgets/widgets_demo.py
51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
home()
async
provide the main content page
Source code in ngwidgets/widgets_demo.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 |
|
on_grid_event(event, source)
async
React on ag_grid event See https://www.ag-grid.com/javascript-data-grid/grid-events/
Source code in ngwidgets/widgets_demo.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
show_colormap_demo()
async
Display the ColorMap demo interactively allowing to set grid size, start and end color and luminance and saturation parameters
Source code in ngwidgets/widgets_demo.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
|
show_combobox_demo()
async
Demo to showcase the ComboBox class with both predefined options and user input capability, including a button to dynamically change the options using a list of chemical elements.
Source code in ngwidgets/widgets_demo.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
|
show_debounce_demo()
async
Show an input field and search wikipedia
Source code in ngwidgets/widgets_demo.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
|
show_dictedit()
async
show the DictEdit examples
Source code in ngwidgets/widgets_demo.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
show_grid()
async
show the lod grid
Source code in ngwidgets/widgets_demo.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
|
show_hide_show_demo()
async
Demonstrate the HideShow project.
Source code in ngwidgets/widgets_demo.py
492 493 494 495 496 497 498 499 500 501 502 503 504 |
|
show_issue_1786()
async
https://github.com/zauberzeug/nicegui/discussions/1786
Source code in ngwidgets/widgets_demo.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
show_langs()
async
show languages selection
Source code in ngwidgets/widgets_demo.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
show_tristate_demo()
async
Demonstrate the Tristate project.
Source code in ngwidgets/widgets_demo.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
|
NiceGuiWidgetsDemoWebserver
Bases: InputWebserver
webserver to demonstrate ngwidgets capabilities
Source code in ngwidgets/widgets_demo.py
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
|
__init__()
Constructor
Source code in ngwidgets/widgets_demo.py
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
|
wikipedia
wikipedia.py Conduct detailed searches against the Wikipedia API using the 'query' action to fetch article titles, summaries, and direct URLs.
Created on 2024-06-22 @author: wf
WikipediaSearch
A class for performing search queries against Wikipedia. This class leverages the MediaWiki API to obtain detailed article information including titles, summaries, and direct URLs.
Source code in ngwidgets/wikipedia.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
__init__(country='en')
Initializes the WikipediaSearch class with the base URL for the Wikipedia API tailored to the specified language.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
country |
str
|
country code to configure the API URL, defaults to 'en' for English. |
'en'
|
Source code in ngwidgets/wikipedia.py
19 20 21 22 23 24 25 26 27 28 29 30 |
|
search(query, limit=10, explain_text=False)
Performs a detailed search on Wikipedia by leveraging the 'query' action to fetch summaries, in addition to using the 'opensearch' API for quick search results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
str
|
The search string to query Wikipedia with. |
required |
limit |
int
|
The maximum number of search results to return. Default is 10. |
10
|
explain_text |
bool
|
If True, return extracts as plain text. Default is True. |
False
|
Returns:
Name | Type | Description |
---|---|---|
list |
A list of dictionaries, each containing the title, summary, and direct URL of an article. |
Source code in ngwidgets/wikipedia.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
yamlable
Created on 2023-12-08, Extended on 2023-16-12 and 2024-01-25
@author: wf, ChatGPT
Prompts for the development and extension of the 'YamlAble' class within the 'yamable' module:
- Develop 'YamlAble' class in 'yamable' module. It should convert dataclass instances to/from YAML.
- Implement methods for YAML block scalar style and exclude None values in 'YamlAble' class.
- Add functionality to remove None values from dataclass instances before YAML conversion.
- Ensure 'YamlAble' processes only dataclass instances, with error handling for non-dataclass objects.
- Extend 'YamlAble' for JSON serialization and deserialization.
- Add methods for saving/loading dataclass instances to/from YAML and JSON files in 'YamlAble'.
- Implement loading of dataclass instances from URLs for both YAML and JSON in 'YamlAble'.
- Write tests for 'YamlAble' within the pyLodStorage context. Use 'samples 2' example from pyLoDStorage https://github.com/WolfgangFahl/pyLoDStorage/blob/master/lodstorage/sample2.py as a reference.
- Ensure tests cover YAML/JSON serialization, deserialization, and file I/O operations, using the sample-based approach..
- Use Google-style docstrings, comments, and type hints in 'YamlAble' class and tests.
- Adhere to instructions and seek clarification for any uncertainties.
- Add @lod_storable annotation support that will automatically YamlAble support and add @dataclass and @dataclass_json prerequisite behavior to a class
DateConvert
date converter
Source code in ngwidgets/yamlable.py
76 77 78 79 80 81 82 83 84 |
|
YamlAble
Bases: Generic[T]
An extended YAML handler class for converting dataclass objects to and from YAML format, and handling loading from and saving to files and URLs.
Source code in ngwidgets/yamlable.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
from_dict2(data)
classmethod
Creates an instance of a dataclass from a dictionary, typically used in deserialization.
Source code in ngwidgets/yamlable.py
318 319 320 321 322 323 324 325 326 |
|
from_yaml(yaml_str)
classmethod
Deserializes a YAML string to a dataclass instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_str |
str
|
A string containing YAML formatted data. |
required |
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
An instance of the dataclass. |
Source code in ngwidgets/yamlable.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
load_from_json_file(filename)
classmethod
Loads a dataclass instance from a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
The path to the JSON file. |
required |
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
An instance of the dataclass. |
Source code in ngwidgets/yamlable.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
load_from_json_url(url)
classmethod
Loads a dataclass instance from a JSON string obtained from a URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL pointing to the JSON data. |
required |
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
An instance of the dataclass. |
Source code in ngwidgets/yamlable.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
load_from_yaml_file(filename)
classmethod
Loads a dataclass instance from a YAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
The path to the YAML file. |
required |
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
An instance of the dataclass. |
Source code in ngwidgets/yamlable.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
load_from_yaml_url(url)
classmethod
Loads a dataclass instance from a YAML string obtained from a URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL pointing to the YAML data. |
required |
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
An instance of the dataclass. |
Source code in ngwidgets/yamlable.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
read_from_url(url)
classmethod
Helper method to fetch content from a URL.
Source code in ngwidgets/yamlable.py
253 254 255 256 257 258 259 260 261 262 |
|
remove_ignored_values(value, ignore_none=True, ignore_underscore=False, ignore_empty=True)
classmethod
Recursively removes specified types of values from a dictionary or list. By default, it removes keys with None values. Optionally, it can also remove keys starting with an underscore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Any
|
The value to process (dictionary, list, or other). |
required |
ignore_none |
bool
|
Flag to indicate whether None values should be removed. |
True
|
ignore_underscore |
bool
|
Flag to indicate whether keys starting with an underscore should be removed. |
False
|
ignore_empty |
bool
|
Flag to indicate whether empty collections should be removed. |
True
|
Source code in ngwidgets/yamlable.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
represent_literal(dumper, data)
Custom representer for block scalar style for strings.
Source code in ngwidgets/yamlable.py
111 112 113 114 115 116 117 |
|
represent_none(_, __)
Custom representer for ignoring None values in the YAML output.
Source code in ngwidgets/yamlable.py
105 106 107 108 109 |
|
save_to_json_file(filename, **kwargs)
Saves the current dataclass instance to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
The path where the JSON file will be saved. |
required |
**kwargs |
Additional keyword arguments for the |
{}
|
Source code in ngwidgets/yamlable.py
241 242 243 244 245 246 247 248 249 250 251 |
|
save_to_yaml_file(filename)
Saves the current dataclass instance to a YAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
The path where the YAML file will be saved. |
required |
Source code in ngwidgets/yamlable.py
199 200 201 202 203 204 205 206 207 208 |
|
to_yaml(ignore_none=True, ignore_underscore=True, allow_unicode=True, sort_keys=False)
Converts this dataclass object to a YAML string, with options to omit None values and/or underscore-prefixed variables, and using block scalar style for strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ignore_none |
bool
|
Flag to indicate whether None values should be removed from the YAML output. |
True
|
ignore_underscore |
bool
|
Flag to indicate whether attributes starting with an underscore should be excluded from the YAML output. |
True
|
allow_unicode |
bool
|
Flag to indicate whether to allow unicode characters in the output. |
True
|
sort_keys |
bool
|
Flag to indicate whether to sort the dictionary keys in the output. |
False
|
Returns:
Type | Description |
---|---|
str
|
A string representation of the dataclass object in YAML format. |
Source code in ngwidgets/yamlable.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
lod_storable(cls)
Decorator to make a class LoDStorable by inheriting from YamlAble. This decorator also ensures the class is a dataclass and has JSON serialization/deserialization capabilities.
Source code in ngwidgets/yamlable.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|