• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SPF-OST / pytrnsys_gui / 11662562960

29 Oct 2024 03:09PM UTC coverage: 67.508% (-0.08%) from 67.591%
11662562960

push

github

web-flow
Merge pull request #564 from SPF-OST/560-black-change-line-length-to-pep8-standard-of-79-and-check-ci-reaction

changed line length in black to 79

1054 of 1475 new or added lines in 174 files covered. (71.46%)

150 existing lines in 74 files now uncovered.

10399 of 15404 relevant lines covered (67.51%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.42
/trnsysGUI/components/factory.py
1
import collections.abc as _cabc
1✔
2
import dataclasses as _dc
1✔
3
import logging as _log
1✔
4

5
import PyQt5.QtGui as _qtg
1✔
6

7
import pytrnsys.utils.result as _res
1✔
8
import pytrnsys.utils.warnings as _warn
1✔
9

10
import trnsysGUI.blockItems.names as _bnames
1✔
11
import trnsysGUI.images as _img
1✔
12

13
from .plugin import factory as _pfactory
1✔
14

15
_LOGGER = _log.getLogger(__name__)
1✔
16

17

18
@_dc.dataclass
1✔
19
class Component:
1✔
20
    name: str
1✔
21
    icon: _qtg.QIcon
1✔
22

23

24
# This can't be a constant as QPixmaps are created and in order to create those
25
# a QApplication must have already been created
26
def _getHardCodedComponents() -> _cabc.Sequence[Component]:
1✔
27
    return [
1✔
28
        Component("Connector", _img.CONNECTOR_SVG.icon()),
29
        Component("TeePiece", _img.TEE_PIECE_SVG.icon()),
30
        Component("DPTee", _img.DP_TEE_PIECE_SVG.icon()),
31
        Component("SPCnr", _img.SINGLE_DOUBLE_PIPE_CONNECTOR_SVG.icon()),
32
        Component("DPCnr", _img.DOUBLE_DOUBLE_PIPE_CONNECTOR_SVG.icon()),
33
        Component("TVentil", _img.T_VENTIL_SVG.icon()),
34
        Component("WTap_main", _img.TAP_MAINS_SVG.icon()),
35
        Component(_bnames.TAP, _img.TAP_SVG.icon()),
36
        Component("Pump", _img.PUMP_SVG.icon()),
37
        Component("Collector", _img.COLLECTOR_SVG.icon()),
38
        Component("GroundSourceHx", _img.GROUND_SOURCE_HX_SVG.icon()),
39
        Component("PV", _img.PV_SVG.icon()),
40
        Component("HP", _img.HP_SVG.icon()),
41
        Component("HPTwoHx", _img.HP_TWO_HX_SVG.icon()),
42
        Component("HPDoubleDual", _img.HP_DOUBLE_DUAL_SVG.icon()),
43
        Component("HPDual", _img.HP_DUAL_SVG.icon()),
44
        Component("AirSourceHP", _img.AIR_SOURCE_HP_SVG.icon()),
45
        Component("StorageTank", _img.STORAGE_TANK_SVG.icon()),
46
        Component("IceStorage", _img.ICE_STORAGE_SVG.icon()),
47
        Component("IceStorageTwoHx", _img.ICE_STORAGE_TWO_HX_SVG.icon()),
48
        Component("ExternalHx", _img.EXTERNAL_HX_SVG.icon()),
49
        Component("Radiator", _img.RADIATOR_SVG.icon()),
50
        Component("Boiler", _img.BOILER_SVG.icon()),
51
        Component("Sink", _img.SINK_SVG.icon()),
52
        Component("Source", _img.SOURCE_SVG.icon()),
53
        Component("SourceSink", _img.SOURCE_SINK_SVG.icon()),
54
        Component("Geotherm", _img.GEOTHERM_SVG.icon()),
55
        Component("Water", _img.WATER_SVG.icon()),
56
        Component("Crystalizer", _img.CRYSTALIZER_SVG.icon()),
57
        Component("CSP_CR", _img.CENTRAL_RECEVIER_SVG.icon()),
58
        Component("CSP_PT", _img.PT_FIELD_SVG.icon()),
59
        Component("powerBlock", _img.STEAM_POWER_BLOCK_SVG.icon()),
60
        Component("coldSaltTank", _img.SALT_TANK_COLD_SVG.icon()),
61
        Component("hotSaltTank", _img.SALT_TANK_HOT_SVG.icon()),
62
        Component("GenericBlock", _img.GENERIC_BLOCK_PNG.icon()),
63
        Component("GraphicalItem", _img.GENERIC_ITEM_PNG.icon()),
64
    ]
65

66

67
def getComponents() -> _warn.ValueWithWarnings[_cabc.Sequence[Component]]:
1✔
68
    pluginComponentsWithWarnings = _getPluginComponents()
1✔
69

70
    allComponents = [
1✔
71
        *_getHardCodedComponents(),
72
        *pluginComponentsWithWarnings.value,
73
    ]
74

75
    return pluginComponentsWithWarnings.withValue(allComponents)
1✔
76

77

78
def _getPluginComponents() -> (
1✔
79
    _warn.ValueWithWarnings[_cabc.Sequence[Component]]
80
):
81
    pluginFactory = _pfactory.Factory.createDefault()
1✔
82

83
    pluginComponentNames = pluginFactory.getTypeNames()
1✔
84

85
    pluginComponents = []
1✔
86
    namesOfComponentsWhichCouldntBeLoaded = []
1✔
87
    for pluginComponentName in pluginComponentNames:
1✔
88
        result = _createPluginComponent(pluginComponentName, pluginFactory)
1✔
89
        if _res.isError(result):
1✔
90
            namesOfComponentsWhichCouldntBeLoaded.append(pluginComponentName)
×
NEW
91
            error = _res.error(result).withContext(
×
92
                f"Could not load component {pluginComponentName}"
93
            )
94
            _LOGGER.error(error.message)
×
95
            continue
×
96
        pluginComponent = _res.value(result)
1✔
97

98
        pluginComponents.append(pluginComponent)
1✔
99

100
    if namesOfComponentsWhichCouldntBeLoaded:
1✔
NEW
101
        formattedNames = "\n".join(
×
102
            f"\t - {name}" for name in namesOfComponentsWhichCouldntBeLoaded
103
        )
UNCOV
104
        warning = f"""\
×
105
The following plugin components couldn't be loaded (see log file for details):
106
{formattedNames}
107

108
"""
109
    else:
110
        warning = None
1✔
111

112
    valueWithWarnings = _warn.ValueWithWarnings.create(
1✔
113
        pluginComponents, warning
114
    )
115
    return valueWithWarnings
1✔
116

117

118
def _createPluginComponent(
1✔
119
    pluginComponentName: str, pluginFactory: _pfactory.Factory
120
) -> _res.Result[Component]:
121
    result = pluginFactory.create(pluginComponentName)
1✔
122
    if _res.isError(result):
1✔
123
        return _res.error(result)
×
124
    plugin = _res.value(result)
1✔
125

126
    icon = plugin.graphics.accessor.icon()
1✔
127
    pluginComponent = Component(pluginComponentName, icon)
1✔
128
    return pluginComponent
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc