ripple-down-rules 0.5.87__py3-none-any.whl → 0.5.89__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- __version__ = "0.5.87"
1
+ __version__ = "0.5.89"
2
2
 
3
3
  import logging
4
4
  logger = logging.Logger("rdr")
@@ -20,12 +20,15 @@ from ..datastructures.dataclasses import CaseQuery
20
20
  from ..datastructures.enums import PromptFor
21
21
  from .ipython_custom_shell import IPythonShell
22
22
  from ..utils import make_list
23
+ from threading import Lock
23
24
 
24
25
 
25
26
  class UserPrompt:
26
27
  """
27
28
  A class to handle user prompts for the RDR.
28
29
  """
30
+ shell_lock: Lock = Lock() # To ensure that only one thread can access the shell at a time
31
+
29
32
  def __init__(self, viewer: Optional[RDRCaseViewer] = None):
30
33
  """
31
34
  Initialize the UserPrompt class.
@@ -99,15 +102,16 @@ class UserPrompt:
99
102
  prompt_str = f"Give conditions on when can the rule be evaluated for:"
100
103
  case_query.scope.update({'case': case_query.case})
101
104
  shell = None
102
- if self.viewer is None:
103
- prompt_str = self.construct_prompt_str_for_shell(case_query, prompt_for, prompt_str)
104
- shell = IPythonShell(header=prompt_str, prompt_for=prompt_for, case_query=case_query,
105
- code_to_modify=code_to_modify)
106
- else:
105
+ with self.shell_lock:
106
+ if self.viewer is None:
107
+ prompt_str = self.construct_prompt_str_for_shell(case_query, prompt_for, prompt_str)
108
+ shell = IPythonShell(header=prompt_str, prompt_for=prompt_for, case_query=case_query,
109
+ code_to_modify=code_to_modify)
110
+ else:
107
111
 
108
- self.viewer.update_for_case_query(case_query, prompt_str,
109
- prompt_for=prompt_for, code_to_modify=code_to_modify)
110
- return self.prompt_user_input_and_parse_to_expression(shell=shell)
112
+ self.viewer.update_for_case_query(case_query, prompt_str,
113
+ prompt_for=prompt_for, code_to_modify=code_to_modify)
114
+ return self.prompt_user_input_and_parse_to_expression(shell=shell)
111
115
 
112
116
 
113
117
  def construct_prompt_str_for_shell(self, case_query: CaseQuery, prompt_for: PromptFor,
@@ -143,17 +147,7 @@ class UserPrompt:
143
147
  """
144
148
  while True:
145
149
  if user_input is None:
146
- if self.viewer is None:
147
- shell = IPythonShell() if shell is None else shell
148
- shell.run()
149
- user_input = shell.user_input
150
- else:
151
- app = QApplication.instance()
152
- if app is None:
153
- raise RuntimeError("QApplication instance is None. Please run the application first.")
154
- self.viewer.show()
155
- app.exec()
156
- user_input = self.viewer.user_input
150
+ user_input = self.start_shell_and_get_user_input(shell=shell)
157
151
  if user_input is None or user_input == 'exit':
158
152
  return user_input, None
159
153
  self.print_func(f"{Fore.GREEN}Captured User input: {Style.RESET_ALL}")
@@ -166,3 +160,23 @@ class UserPrompt:
166
160
  logging.error(msg)
167
161
  self.print_func(f"{Fore.RED}{msg}{Style.RESET_ALL}")
168
162
  user_input = None
163
+
164
+ def start_shell_and_get_user_input(self, shell: Optional[IPythonShell] = None) -> Optional[str]:
165
+ """
166
+ Start the shell and get user input.
167
+
168
+ :param shell: The Ipython shell to use for prompting the user.
169
+ :return: The user input.
170
+ """
171
+ if self.viewer is None:
172
+ shell = IPythonShell() if shell is None else shell
173
+ shell.run()
174
+ user_input = shell.user_input
175
+ else:
176
+ app = QApplication.instance()
177
+ if app is None:
178
+ raise RuntimeError("QApplication instance is None. Please run the application first.")
179
+ self.viewer.show()
180
+ app.exec()
181
+ user_input = self.viewer.user_input
182
+ return user_input
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ripple_down_rules
3
- Version: 0.5.87
3
+ Version: 0.5.89
4
4
  Summary: Implements the various versions of Ripple Down Rules (RDR) for knowledge representation and reasoning.
5
5
  Author-email: Abdelrhman Bassiouny <abassiou@uni-bremen.de>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,4 +1,4 @@
1
- ripple_down_rules/__init__.py,sha256=GkugTXRcQu2cnGcyrT7Ra2SGmRhDvnkbdHlrvXqCmfw,100
1
+ ripple_down_rules/__init__.py,sha256=oOJbyOSBUiEhjmjcUnRZFxEukTio6qEyFU0r-oVaMgg,100
2
2
  ripple_down_rules/experts.py,sha256=J4VaYPKrAMNcoP0JRenZpx9IHLLoeFdl0QZKZzjFFkM,12768
3
3
  ripple_down_rules/helpers.py,sha256=v4oE7C5PfQUVJfSUs1FfLHEwrJXEHJLn4vJhJMvyCR8,4453
4
4
  ripple_down_rules/rdr.py,sha256=C6bvlq6MsKa2Mym1wW6JUMj705aCaoihTP279TM6eT0,55218
@@ -15,10 +15,10 @@ ripple_down_rules/user_interface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRk
15
15
  ripple_down_rules/user_interface/gui.py,sha256=_lgZAUXxxaBUFQJAHjA5TBPp6XEvJ62t-kSN8sPsocE,27379
16
16
  ripple_down_rules/user_interface/ipython_custom_shell.py,sha256=6v99tlNcfRyZpnPxq3FfqgFgxbJ5zkA2jVAXamTH1C0,6575
17
17
  ripple_down_rules/user_interface/object_diagram.py,sha256=FEa2HaYR9QmTE6NsOwBvZ0jqmu3DKyg6mig2VE5ZP4Y,4956
18
- ripple_down_rules/user_interface/prompt.py,sha256=Liu24-wuL12mg2xI7FBvnL6T1eyykCcMZ3AeKkkYwpA,8283
18
+ ripple_down_rules/user_interface/prompt.py,sha256=udD4SUe4Agm7mWqB9X-b4g2AGQg-Ow3OtZdw9nY-TsY,8759
19
19
  ripple_down_rules/user_interface/template_file_creator.py,sha256=ELHYhZEjHsMdG5ebbOghfZtPBpPtuJDWQRAkLpfcSFM,13553
20
- ripple_down_rules-0.5.87.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
21
- ripple_down_rules-0.5.87.dist-info/METADATA,sha256=L_EDvPOt6ibGEoNS6qgGXSFQ5zJkJdpPCKlB937_vzc,48214
22
- ripple_down_rules-0.5.87.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- ripple_down_rules-0.5.87.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
24
- ripple_down_rules-0.5.87.dist-info/RECORD,,
20
+ ripple_down_rules-0.5.89.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
21
+ ripple_down_rules-0.5.89.dist-info/METADATA,sha256=z3Ed4CzU7Dt3SlwuWoMc7wKHqr66NuN1K3Xwpe0Z2po,48214
22
+ ripple_down_rules-0.5.89.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ ripple_down_rules-0.5.89.dist-info/top_level.txt,sha256=VeoLhEhyK46M1OHwoPbCQLI1EifLjChqGzhQ6WEUqeM,18
24
+ ripple_down_rules-0.5.89.dist-info/RECORD,,