Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/workspace.xml
  • Loading branch information
SanPen committed Nov 16, 2023
2 parents 14670ae + 1278b05 commit e7b31d4
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 238 deletions.
4 changes: 1 addition & 3 deletions src/GridCal/Gui/Main/GridCalMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MainGUI(ScriptingMain):
MainGUI
"""

def __init__(self):
def __init__(self) -> None:
"""
Main constructor
"""
Expand Down Expand Up @@ -76,8 +76,6 @@ def __init__(self):
# this is the contingency planner tab, invisible until done
self.ui.tabWidget_3.setTabVisible(4, True)

# self.view_cascade_menu()

self.clear_results()

self.load_gui_config()
Expand Down
65 changes: 6 additions & 59 deletions src/GridCal/Gui/Main/SubClasses/Model/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

import networkx as nx
import numpy as np
import qdarktheme
from PySide6 import QtGui, QtWidgets, QtCore
from PySide6 import QtGui, QtWidgets
from matplotlib import pyplot as plt
from pandas.plotting import register_matplotlib_converters

Expand All @@ -30,7 +29,7 @@
import GridCal.Gui.GuiFunctions as gf
import GridCal.Gui.Visualization.palettes as palettes
from GridCalEngine.IO.file_system import get_create_gridcal_folder
from GridCal.Gui.GeneralDialogues import LogsDialogue, CheckListDialogue, StartEndSelectionDialogue
from GridCal.Gui.GeneralDialogues import CheckListDialogue, StartEndSelectionDialogue
from GridCal.Gui.BusViewer.bus_viewer_dialogue import BusViewerWidget
from GridCal.Gui.GridEditorWidget import BusBranchEditorWidget, generate_bus_branch_diagram
from GridCal.Gui.MapWidget.grid_map_widget import GridMapWidget
Expand Down Expand Up @@ -155,9 +154,6 @@ def __init__(self, parent=None):
self.ui.explosion_factor_doubleSpinBox.valueChanged.connect(self.explosion_factor_change)
self.ui.defaultBusVoltageSpinBox.valueChanged.connect(self.default_voltage_change)

# check boxes
self.ui.dark_mode_checkBox.clicked.connect(self.change_theme_mode)

def auto_layout(self):
"""
Automatic layout of the nodes
Expand Down Expand Up @@ -1049,38 +1045,6 @@ def set_diagram_widget(self, diagram: Union[BusBranchEditorWidget, GridMapWidget
index = self.ui.diagramsListView.model().index(row, 0)
self.ui.diagramsListView.setCurrentIndex(index)

def change_theme_mode(self) -> None:
"""
Change the GUI theme
:return:
"""
custom_colors = {"primary": "#00aa88ff",
"primary>list.selectionBackground": "#00aa88be"}

if self.ui.dark_mode_checkBox.isChecked():
qdarktheme.setup_theme(theme='dark', custom_colors=custom_colors)

diagram = self.get_selected_diagram_widget()
if diagram is not None:
if isinstance(diagram, BusBranchEditorWidget):
diagram.set_dark_mode()

self.colour_diagrams()

if self.console is not None:
self.console.set_dark_theme()
else:
qdarktheme.setup_theme(theme='light', custom_colors=custom_colors)

diagram = self.get_selected_diagram_widget()
if diagram is not None:
if isinstance(diagram, BusBranchEditorWidget):
diagram.set_light_mode()

self.colour_diagrams()

if self.console is not None:
self.console.set_light_theme()

def plot_style_change(self):
"""
Expand Down Expand Up @@ -1317,28 +1281,11 @@ def update_available_steps_to_color(self):
self.ui.simulation_results_step_slider.setSliderPosition(0)
self.ui.schematic_step_label.setText("No steps")

def get_selected_contingency_devices(self) -> List[dev.EditableDevice]:
"""
Get the selected buses
:return:
"""
lst: List[dev.EditableDevice] = list()
for k, elm in enumerate(self.circuit.get_contingency_devices()):
if elm.graphic_obj is not None:
if elm.graphic_obj.isSelected():
lst.append(elm)
return lst

def get_selected_investment_devices(self) -> List[dev.EditableDevice]:
def get_selected_devices(self) -> List[dev.EditableDevice]:
"""
Get the selected investment devices
:return:
:return: list of selected devices
"""
# lst: List[dev.EditableDevice] = list()
# for k, elm in enumerate(self.circuit.get_investment_devices()):
# if elm.graphic_obj is not None:
# if elm.graphic_obj.isSelected():
# lst.append(elm)

diagram = self.get_selected_diagram_widget()

Expand All @@ -1358,7 +1305,7 @@ def add_selected_to_contingency(self):
if len(self.circuit.buses) > 0:

# get the selected buses
selected = self.get_selected_contingency_devices()
selected = self.get_selected_devices()

if len(selected) > 0:
names = [elm.type_name + ": " + elm.name for elm in selected]
Expand Down Expand Up @@ -1392,7 +1339,7 @@ def add_selected_to_investment(self) -> None:
if len(self.circuit.buses) > 0:

# get the selected investment devices
selected = self.get_selected_investment_devices()
selected = self.get_selected_devices()

if len(selected) > 0:

Expand Down
136 changes: 2 additions & 134 deletions src/GridCal/Gui/Main/SubClasses/Scripting/scripting.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,14 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import os
import numpy as np
import pandas as pd
from typing import Union
from matplotlib import pyplot as plt
import datetime as dtelib
from PySide6.QtGui import QFont, QFontMetrics
from GridCal.Gui.Main.SubClasses.io import IoMain
from GridCal.Gui.Main.SubClasses.Scripting.python_highlighter import PythonHighlighter
from GridCal.Gui.GeneralDialogues import clear_qt_layout

from GridCal.Gui.GuiFunctions import CustomFileSystemModel
from GridCal.Gui.messages import error_msg, yes_no_question

try:
from GridCal.Gui.ConsoleWidget import ConsoleWidget

qt_console_available = True
except ModuleNotFoundError:
print('No qtconsole available')
qt_console_available = False


class ScriptingMain(IoMain):
"""
Expand All @@ -50,12 +38,7 @@ def __init__(self, parent=None):
# create main window
IoMain.__init__(self, parent)

# Console
self.console: Union[ConsoleWidget, None] = None
try:
self.create_console()
except TypeError:
error_msg('The console has failed because the QtConsole guys have a bug in their package :(')


# Source code text ---------------------------------------------------------------------------------------------
# Set the font for your widget
Expand Down Expand Up @@ -86,121 +69,6 @@ def __init__(self, parent=None):
# double clicked -----------------------------------------------------------------------------------------------
self.ui.sourceCodeTreeView.doubleClicked.connect(self.source_code_tree_clicked)

def create_console(self) -> None:
"""
Create console
"""
if qt_console_available:
if self.console is not None:
clear_qt_layout(self.ui.pythonConsoleTab.layout())

self.console = ConsoleWidget(customBanner="GridCal console.\n\n"
"type hlp() to see the available specific commands.\n\n"
"the following libraries are already loaded:\n"
"np: numpy\n"
"pd: pandas\n"
"plt: matplotlib\n"
"app: This instance of GridCal\n"
"circuit: The current grid\n\n")

self.console.buffer_size = 10000

# add the console widget to the user interface
self.ui.pythonConsoleTab.layout().addWidget(self.console)

# push some variables to the console
self.console.push_vars({"hlp": self.print_console_help,
"np": np,
"pd": pd,
"plt": plt,
"clc": self.clc,
'app': self,
'circuit': self.circuit})

@staticmethod
def print_console_help():
"""
Print the console help in the console
@return:
"""
print('GridCal internal commands.\n')
print('If a command is unavailable is because the study has not been executed yet.')

print('\n\nclc():\tclear the console.')

print('\n\nApp functions:')
print('\tapp.new_project(): Clear all.')
print('\tapp.open_file(): Prompt to load GridCal compatible file')
print('\tapp.save_file(): Prompt to save GridCal file')
print('\tapp.export_diagram(): Prompt to export the diagram in png.')
print('\tapp.create_schematic_from_api(): Create the schematic from the circuit information.')
print('\tapp.adjust_all_node_width(): Adjust the width of all the nodes according to their name.')
print('\tapp.numerical_circuit: get compilation of the assets.')
print('\tapp.islands: get compilation of the assets split into the topological islands.')

print('\n\nCircuit functions:')
print('\tapp.circuit.plot_graph(): Plot a graph in a Matplotlib window. Call plt.show() after.')

print('\n\nPower flow results:')
print('\tapp.session.power_flow.voltage:\t the nodal voltages in per unit')
print('\tapp.session.power_flow.current:\t the branch currents in per unit')
print('\tapp.session.power_flow.loading:\t the branch loading in %')
print('\tapp.session.power_flow.losses:\t the branch losses in per unit')
print('\tapp.session.power_flow.power:\t the nodal power Injections in per unit')
print('\tapp.session.power_flow.Sf:\t the branch power Injections in per unit at the "from" side')
print('\tapp.session.power_flow.St:\t the branch power Injections in per unit at the "to" side')

print('\n\nShort circuit results:')
print('\tapp.session.short_circuit.voltage:\t the nodal voltages in per unit')
print('\tapp.session.short_circuit.current:\t the branch currents in per unit')
print('\tapp.session.short_circuit.loading:\t the branch loading in %')
print('\tapp.session.short_circuit.losses:\t the branch losses in per unit')
print('\tapp.session.short_circuit.power:\t the nodal power Injections in per unit')
print('\tapp.session.short_circuit.power_from:\t the branch power Injections in per unit at the "from" side')
print('\tapp.session.short_circuit.power_to:\t the branch power Injections in per unit at the "to" side')
print('\tapp.session.short_circuit.short_circuit_power:\t Short circuit power in MVA of the grid nodes')

print('\n\nOptimal power flow results:')
print('\tapp.session.optimal_power_flow.voltage:\t the nodal voltages angles in rad')
print('\tapp.session.optimal_power_flow.load_shedding:\t the branch loading in %')
print('\tapp.session.optimal_power_flow.losses:\t the branch losses in per unit')
print('\tapp.session.optimal_power_flow.Sbus:\t the nodal power Injections in MW')
print('\tapp.session.optimal_power_flow.Sf:\t the branch power Sf')

print('\n\nTime series power flow results:')
print('\tapp.session.power_flow_ts.time:\t Profiles time index (pandas DateTimeIndex object)')
print('\tapp.session.power_flow_ts.load_profiles:\t Load profiles matrix (row: time, col: node)')
print('\tapp.session.power_flow_ts.gen_profiles:\t Generation profiles matrix (row: time, col: node)')
print('\tapp.session.power_flow_ts.voltages:\t nodal voltages results matrix (row: time, col: node)')
print('\tapp.session.power_flow_ts.currents:\t Branches currents results matrix (row: time, col: branch)')
print('\tapp.session.power_flow_ts.loadings:\t Branches loadings results matrix (row: time, col: branch)')
print('\tapp.session.power_flow_ts.losses:\t Branches losses results matrix (row: time, col: branch)')

print('\n\nVoltage stability power flow results:')
print('\tapp.session.continuation_power_flow.voltage:\t Voltage values for every power multiplication factor.')
print('\tapp.session.continuation_power_flow.lambda:\t Value of power multiplication factor applied')
print('\tapp.session.continuation_power_flow.Sf:\t Power values for every power multiplication factor.')

print('\n\nMonte Carlo power flow results:')
print('\tapp.session.stochastic_power_flow.V_avg:\t nodal voltage average result.')
print('\tapp.session.stochastic_power_flow.I_avg:\t branch current average result.')
print('\tapp.session.stochastic_power_flow.Loading_avg:\t branch loading average result.')
print('\tapp.session.stochastic_power_flow.Losses_avg:\t branch losses average result.')
print('\tapp.session.stochastic_power_flow.V_std:\t nodal voltage standard deviation result.')
print('\tapp.session.stochastic_power_flow.I_std:\t branch current standard deviation result.')
print('\tapp.session.stochastic_power_flow.Loading_std:\t branch loading standard deviation result.')
print('\tapp.session.stochastic_power_flow.Losses_std:\t branch losses standard deviation result.')
print('\tapp.session.stochastic_power_flow.V_avg_series:\t nodal voltage average series.')
print('\tapp.session.stochastic_power_flow.V_std_series:\t branch current standard deviation series.')
print('\tapp.session.stochastic_power_flow.error_series:\t Monte Carlo error series (the convergence value).')
print('The same for app.latin_hypercube_sampling')

def clc(self):
"""
Clear the console
"""
self.console.clear()

def console_msg(self, *msg_):
"""
Print some message in the console.
Expand Down
39 changes: 38 additions & 1 deletion src/GridCal/Gui/Main/SubClasses/Settings/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import json
import os
import qdarktheme
from typing import Dict, Union

from PySide6 import QtWidgets

from GridCalEngine.IO.file_system import get_create_gridcal_folder
from GridCal.Gui.Main.SubClasses.Results.results import ResultsMain
from GridCal.Gui.GridEditorWidget import BusBranchEditorWidget


class ConfigurationMain(ResultsMain):
Expand All @@ -38,6 +39,42 @@ def __init__(self, parent=None):
# create main window
ResultsMain.__init__(self, parent)

# check boxes
self.ui.dark_mode_checkBox.clicked.connect(self.change_theme_mode)

def change_theme_mode(self) -> None:
"""
Change the GUI theme
:return:
"""
custom_colors = {"primary": "#00aa88ff",
"primary>list.selectionBackground": "#00aa88be"}

if self.ui.dark_mode_checkBox.isChecked():
qdarktheme.setup_theme(theme='dark', custom_colors=custom_colors)

diagram = self.get_selected_diagram_widget()
if diagram is not None:
if isinstance(diagram, BusBranchEditorWidget):
diagram.set_dark_mode()

self.colour_diagrams()

if self.console is not None:
self.console.set_dark_theme()
else:
qdarktheme.setup_theme(theme='light', custom_colors=custom_colors)

diagram = self.get_selected_diagram_widget()
if diagram is not None:
if isinstance(diagram, BusBranchEditorWidget):
diagram.set_light_mode()

self.colour_diagrams()

if self.console is not None:
self.console.set_light_theme()

@staticmethod
def config_file_path() -> str:
"""
Expand Down
Loading

0 comments on commit e7b31d4

Please sign in to comment.