Skip to content

Commit

Permalink
Scenario in clipboard (#512)
Browse files Browse the repository at this point in the history
* Add scenario values to clipboard

* Simplifications and fixes

* minor simplification

---------

Co-authored-by: axelvonkamp <axelk1@gmx.de>
  • Loading branch information
Paulocracy and axelvonkamp committed Jun 25, 2024
1 parent 06e2778 commit 3a57ab9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cnapy/gui_elements/clipboard_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, appdata: AppData):
self.op.insertItem(1, "+")
self.op.insertItem(2, "-")
self.op.insertItem(3, "*")
self.op.insertItem(4, "\\")
self.op.insertItem(4, "/")
op.addWidget(self.op)
self.right = QVBoxLayout()
self.r1 = QRadioButton("Current values")
Expand Down Expand Up @@ -80,6 +80,9 @@ def compute(self):
r_comp = {}
if self.l1.isChecked():
l_comp = self.appdata.project.comp_values

for (key, value) in self.appdata.project.scen_values.items():
l_comp[key] = value
elif self.l2.isChecked():
try:
l_comp = self.appdata.clipboard_comp_values
Expand All @@ -93,6 +96,9 @@ def compute(self):

if self.r1.isChecked():
r_comp = self.appdata.project.comp_values

for (key, value) in self.appdata.project.scen_values.items():
r_comp[key] = value
elif self.r2.isChecked():
r_comp = self.appdata.clipboard_comp_values

Expand All @@ -109,6 +115,9 @@ def compute(self):
rv_comp = r_comp[key]

res = self.combine(lv_comp, rv_comp)

if key in self.appdata.project.scen_values.keys():
self.appdata.project.scen_values[key] = res
self.appdata.project.comp_values[key] = res

self.appdata.project.comp_values_type = 0
Expand All @@ -123,5 +132,5 @@ def combine(self, lv, rv):
return (llb-rlb, lub-rub)
if self.op.currentText() == "*":
return (llb*rlb, lub*rub)
if self.op.currentText() == "\\":
if self.op.currentText() == "/":
return (llb/rlb, lub/rub)
6 changes: 6 additions & 0 deletions cnapy/gui_elements/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,9 +1576,15 @@ def on_tab_change(self, idx):
def copy_to_clipboard(self):
self.appdata.clipboard_comp_values = self.appdata.project.comp_values.copy()

for (key, value) in self.appdata.project.scen_values.items():
self.appdata.clipboard_comp_values[key] = value

def paste_clipboard(self):
try:
self.appdata.project.comp_values = self.appdata.clipboard_comp_values.copy()

for key in (self.appdata.project.scen_values.keys() & self.appdata.clipboard_comp_values.keys()):
self.appdata.project.scen_values[key] = self.appdata.clipboard_comp_values[key]
except AttributeError:
QMessageBox.warning(
self,
Expand Down

0 comments on commit 3a57ab9

Please sign in to comment.