def response(self, widget, response_id): """ The buttons that could trigger a response have been disabled, but we receive a response, when the user closes the window Positional arguments: widget -- The widget, which triggered the response. response_id -- A Gtk.ResponseType indicating, which button the user pressed. """ if response_id == Gtk.ResponseType.ACCEPT: print("This should never be called") return if self.deferred and not self.deferred.called: self.deferred.cancel() network.disconnect()
def response(self, widget, response_id): """ Called, when the user clicked on a button ('Connect' or 'Abort') or when the dialog is closed. If the user clicked on connect, we join a document session. Positional arguments: widget -- The widget, which triggered the response. response_id -- A Gtk.ResponseType indicating, which button the user pressed. """ if response_id == Gtk.ResponseType.ACCEPT: documentname = self.doc_name.get_text() self.deferred = network.join_document_session(documentname) self.deferred.addCallback(self.joined_document) self.emit("joining_document", documentname) else: network.disconnect() self.dialog.destroy()
def run_open_pdf_dialog(self, menuitem): """ Run an "Open PDF" dialog and create a new document with that PDF. """ dialog = Gtk.FileChooserDialog( _("Open File"), self, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)) dialog.set_filter(pdf_filter) if dialog.run() == Gtk.ResponseType.ACCEPT: network.disconnect() filename = dialog.get_filename() try: document = Document(filename) except GError as ex: self.run_error_dialog(_("Unable to open PDF"), ex) dialog.destroy() return self._set_document(document) dialog.destroy()
def run_open_xoj_dialog(self, menuitem): """ Run an "Open .xoj" dialog and create a new document from a .xoj file. """ dialog = Gtk.FileChooserDialog( _("Open File"), self, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)) dialog.set_filter(xoj_filter) if dialog.run() == Gtk.ResponseType.ACCEPT: network.disconnect() filename = dialog.get_filename() try: document = xojparser.new_document(filename, self) except Exception as ex: import traceback traceback.print_tb(ex.__traceback__) print(ex) dialog.destroy() return self._set_document(document) self.last_filename = filename dialog.destroy()
def disconnect_clicked(self, widget): """Disconnect from the server and close the OverlayDialog.""" network.disconnect() # Call this via a timeout to let the disconnect_event in network.py fire GObject.timeout_add(0, self.destroy)