Skip to content

Commit

Permalink
Simplifications and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulocracy committed Jun 21, 2024
1 parent e661e81 commit 21f7d41
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
1 change: 0 additions & 1 deletion cnapy/appdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def __init__(self):
self.scenario_future = []
self.recent_cna_files = []
self.auto_fba = False
self.scenario_in_clipboard = False

def scen_values_set(self, reaction: str, values: Tuple[float, float]):
if self.project.scen_values.get(reaction, None) != values: # record only real changes
Expand Down
15 changes: 10 additions & 5 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 @@ -81,9 +81,8 @@ def compute(self):
if self.l1.isChecked():
l_comp = self.appdata.project.comp_values

if appdata.scenario_in_clipboard:
for (key, value) in appdata.project.scen_values.items():
l_comp[key] = value
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 @@ -97,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 @@ -113,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 @@ -127,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)
22 changes: 7 additions & 15 deletions cnapy/gui_elements/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,6 @@ def __init__(self, appdata: AppData):
self.clipboard_menu.addAction(save_fluxes_as_xlsx_action)
save_fluxes_as_xlsx_action.triggered.connect(self.save_fluxes_as_xlsx)

self.scenario_in_clipboard_action = QAction("Include scenario in clipboard", self)
self.scenario_in_clipboard_action.triggered.connect(self.scenario_in_clipboard)
self.scenario_in_clipboard_action.setCheckable(True)
self.clipboard_menu.addAction(self.scenario_in_clipboard_action)

self.map_menu = self.menu.addMenu("Map")
self.cnapy_map_actions = QActionGroup(self)
separator = QAction(" CNApy map", self)
Expand Down Expand Up @@ -1571,13 +1566,17 @@ def on_tab_change(self, idx):
def copy_to_clipboard(self):
self.appdata.clipboard_comp_values = self.appdata.project.comp_values.copy()

if self.appdata.scenario_in_clipboard:
for (key, value) in self.appdata.project.scen_values.items():
self.appdata.clipboard_comp_values[key] = value
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():
if key not in self.appdata.clipboard_comp_values.keys():
continue
self.appdata.project.scen_values[key] = self.appdata.clipboard_comp_values[key]
except AttributeError:
QMessageBox.warning(
self,
Expand All @@ -1587,13 +1586,6 @@ def paste_clipboard(self):
return
self.centralWidget().update()


def scenario_in_clipboard(self):
if self.scenario_in_clipboard_action.isChecked():
self.appdata.scenario_in_clipboard = True
else:
self.appdata.scenario_in_clipboard = False

@Slot()
def clipboard_arithmetics(self):
dialog = ClipboardCalculator(self.appdata)
Expand Down

0 comments on commit 21f7d41

Please sign in to comment.