def withWorksheetFile(webViewController, filename, server=None):
     if not server:
         server = ServerConfigurations.getDefault()
     wsc = WorksheetController(webViewController)
     wsc.server_configuration = server
     ws = wsc.notebook.import_worksheet(filename, wsc.notebook_username)
     SageProcessManager.setWorksheetProcessServer(ws, server)
     wsc.setWorksheet(ws)
     return wsc
 def withNewWorksheet(webViewController, server=None):
     # server is a Sage server configuration that will determine the Sage process this
     # worksheet will use.
     if not server:
         server = ServerConfigurations.getDefault()
     wsc = WorksheetController(webViewController)
     wsc.server_configuration = server
     ws = guru_notebook.create_new_worksheet('Untitled', wsc.notebook_username)
     SageProcessManager.setWorksheetProcessServer(ws, server)
     wsc.setWorksheet(ws)
     return wsc
    def useServerConfiguration(self, server_config):
        self.server_configuration = server_config
        new_worksheet = SageProcessManager.setWorksheetProcessServer(self._worksheet, server_config)

        #If we are switching TO a Notebook Server, we want to be able to access resources on the
        #server from the browser page.
        self.setSessionCookie()

        #There are some instances when we have to swap out worksheets, i.e., when switching FROM a
        #notebook server.
        if self._worksheet is not new_worksheet:
            self._worksheet._notebook.delete_worksheet(self._worksheet.filename())
            self._worksheet = new_worksheet
            #Open the worksheet in the webView
            self.webFrame.setUrl(self.worksheetUrl())