##// END OF EJS Templates
Improve 'save history' menu (%save)...
Matthias BUSSONNIER -
Show More
@@ -324,6 +324,8 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
324
324
325 self._show_interpreter_prompt_for_reply(msg)
325 self._show_interpreter_prompt_for_reply(msg)
326 self.executed.emit(msg)
326 self.executed.emit(msg)
327 else:
328 super(FrontendWidget, self)._handle_execute_reply(msg)
327
329
328 def _handle_input_request(self, msg):
330 def _handle_input_request(self, msg):
329 """ Handle requests for raw_input.
331 """ Handle requests for raw_input.
@@ -219,16 +219,44 b' class HistoryConsoleWidget(ConsoleWidget):'
219 def history_magic(self):
219 def history_magic(self):
220 self.pasteMagic("%history")
220 self.pasteMagic("%history")
221
221
222 def _request_update_session_history_length(self):
223 msg_id = self.kernel_manager.shell_channel.execute('',
224 silent=True,
225 user_expressions={
226 'hlen':'len(get_ipython().history_manager.input_hist_raw)',
227 }
228 )
229 self._request_info['execute'] = self._ExecutionRequest(msg_id, 'save_magic')
230
231 def _handle_execute_reply(self, msg):
232 """ Handles replies for code execution, here only session history length
233 """
234 info = self._request_info.get('execute')
235 if info and info.id == msg['parent_header']['msg_id'] and \
236 info.kind == 'save_magic' and not self._hidden:
237 content = msg['content']
238 status = content['status']
239 if status == 'ok':
240 self._max_session_history=(int(content['user_expressions']['hlen']))
241
222 def save_magic(self):
242 def save_magic(self):
223 file_name, ok = QtGui.QInputDialog.getText(self,
243 # update the session history length
224 'Enter A file Name',
244 self._request_update_session_history_length()
225 'Please enter a filename to wich export the history as python file:',
245
226 text='untilted.py')
246 file_name,extFilter = QtGui.QFileDialog.getSaveFileName(self,
227 if ok:
247 "Enter A filename",
248 filter='Python File (*.py);; All files (*.*)'
249 )
250
251 # let's the user search/type for a file name, while the history length
252 # is fetched
253
254 if file_name:
228 hist_range, ok = QtGui.QInputDialog.getText(self,
255 hist_range, ok = QtGui.QInputDialog.getText(self,
229 'Please enter an interval of command to save',
256 'Please enter an interval of command to save',
230 'Saving commands:',
257 'Saving commands:',
231 text='1-500')
258 text=str('1-'+str(self._max_session_history))
259 )
232 if ok:
260 if ok:
233 self.pasteMagic("%save"+" "+file_name+" "+str(hist_range))
261 self.pasteMagic("%save"+" "+file_name+" "+str(hist_range))
234
262
General Comments 0
You need to be logged in to leave comments. Login now