viktor.core
Color
- class viktor.core.Color(r: int, g: int, b: int)
Bases:
Color
Create an immutable instance of Color
- Parameters:
r – red-value (0-255)
g – green-value (0-255)
b – blue-value (0-255)
- property deltares: int
- static deltares_to_rgb(value)
Conversion from red-green-blue to Deltares-type color value.
- Parameters:
value (
int
) – Integer representation of the color as used in the Deltares software series.- Return type:
Tuple
[int
,int
,int
]
- classmethod from_deltares(value)
Color defined by Deltares-type integer.
- Parameters:
value (
int
) – Integer representation of the color as used in the Deltares software series.- Return type:
- property hex: str
Hexadecimal representation of the color.
- static hex_to_rgb(hex_value)
Conversion from hexadecimal to red-green-blue value
- Return type:
Tuple
[int
,int
,int
]
- property rgb: Tuple[int, int, int]
- static rgb_to_deltares(r, g, b)
Conversion from Deltares-type color value to red-green-blue value.
:return Integer representation of the color as used in the Deltares software series.
- Return type:
int
- static rgb_to_hex(r, g, b, include_hashtag=True)
Conversion from red-green-blue to hexadecimal value
- Return type:
str
Controller
- class viktor.core.Controller(**kwargs)
-
The main function of the ViktorController is to “control” the information flow between the frontend (what is inputted by a user) and the application code (what is returned as a result of the user input).
(new in v14.15.0) The ‘label’ attribute is now optional.
- allow_saving:
Optional
[bool
] = None (new in v14.24.0) Specify whether user is allowed to save entities of this entity-type. May only be set for root entity types in tree-type app.
- children:
Optional
[List
[str
]] = None Optional list of child entity-types.
- label:
Optional
[str
] = None Entity-type label.
- parametrization:
Optional
[Parametrization
] = None viktor.parametrization.Parametrization
that describes the entity-type.
- show_children_as:
Optional
[str
] = None When children are defined, specify how they are shown in the interface (‘Table’ | ‘Cards’).
- summary:
Optional
[Summary
] = None viktor.views.Summary
of the entity-type.
- allow_saving:
File
- class viktor.core.File(*, data=None, path=None, url=None, **kwargs)
-
Creates a File object. Only 1 of data, path or url should be set, or File() for writable file. Or use the corresponding class-methods.
A File object can have one of the following 4 types:
SourceType.DATA: File object with in-memory data as its source
Created with File.from_data(…)
writable: False
SourceType.PATH: File object with an existing file (path) as its source
Created with File.from_path(…)
writable: False
SourceType.URL: File object with a URL as its source
Created with File.from_url(…)
writable: False
SourceType.WRITABLE: File object with a (temporary) writable file on disk as its source
Created with File()
writable: True (writing always takes place at end of file)
Note: Reading from a File with SourceType.URL downloads (part of the) URL content to a (temporary) file on disk, so that re-reading (previously read) content within the same open-context does not require downloading twice. Opening the File object a second time DOES involve downloading the content anew. If such a File needs to be opened multiple times, consider copying the File locally (
copy()
), so that downloading takes place only once.Example usage:
data_file = File.from_data("my content") path_file = File.from_path(Path(__file__).parent / "my_file.txt") url_file = File.from_url("https://...") writable_file = File() data_content = data_file.getvalue_binary() # bytes (b"my content") path_content = path_file.getvalue() # str with url_file.open() as r: # open in text-mode, so read -> str first_character = r.read(1) # downloads only partially all_other_characters = r.read() # downloads the rest with writable_file.open_binary() as w: # open as binary-mode, so read/write -> bytes w.write(b"my content") writable_content = writable_file.getvalue() # "my content"
- Parameters:
data (
Union
[str
,bytes
,None
]) – in-memory data source (alsofrom_data()
)path (
Union
[str
,bytes
,PathLike
,None
]) – existing file path source (alsofrom_path()
)url (
Optional
[str
]) – URL source (alsofrom_url()
)
- class SourceType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- DATA:
SourceType
= 1
- PATH:
SourceType
= 2
- URL:
SourceType
= 3
- WRITABLE:
SourceType
= 4
- DATA:
- copy(writable=False)
Make a local copy of the file to disk.
Example usages:
URL-file that needs to be opened multiple times:
# copying to path-file prevents re-downloading if opening more than once. path_file = url_file.copy() # download the complete content locally with path_file.open() as r: # no downloading ... with path_file.open() as r: # no downloading ...
Make writable file from read-only file:
writable_file = read_only_file.copy(writable=True) with writable_file.open() as w: w.write("my content")
- Parameters:
writable (
bool
) – True to return writable file, False for read-only (default: False).- Return type:
- Returns:
File object (SourceType.WRITABLE if writable = True, else SourceType.PATH).
- classmethod from_data(data)
Create a File object with in-memory data as its source.
- Return type:
- classmethod from_path(path)
Create a File object with an existing file (path) as its source.
- Return type:
- classmethod from_url(url, *, headers=None)
Create a File object with a URL as its source.
- Return type:
- getvalue(encoding=None)
Read the content (text) of the file in memory. For large files, open the file and read in chunks, to prevent the app from running out of memory.
- Return type:
str
- getvalue_binary()
Read the content (binary) of the file in memory. For large files, open the file and read in chunks, to prevent the app from running out of memory.
- Return type:
bytes
- open(encoding=None)
Open the file in text-mode.
- Parameters:
encoding (
str
) – encoding used for reading the bytes -> str (default: default local encoding)- Return type:
TextIO
- Returns:
opened text file
- open_binary()
Open the file in binary-mode.
- Return type:
BinaryIO
- Returns:
opened binary file