def _on_filechooser_response(self, save_dialog: Gtk.Dialog,
                                 response: Gtk.ResponseType,
                                 _dialog: Gtk.Dialog) -> None:
        save_dialog.destroy()
        if response == Gtk.ResponseType.ACCEPT:
            spinner = Gtk.Spinner()
            spinner.start()
            self.generate_keyfile_button.set_child(spinner)

            keyfile = save_dialog.get_file()

            def callback(gfile, result):
                try:
                    _res, keyfile_hash = generate_keyfile_finish(result)
                except GLib.Error as err:
                    self.generate_keyfile_button.set_icon_name(
                        "security-high-symbolic")
                    logging.debug("Could not create keyfile: %s", err.message)
                    self.keyfile_error_revealer.reveal(True)
                else:
                    self.generate_keyfile_button.set_icon_name(
                        "object-select-symbolic")
                    self.new_keyfile_hash = keyfile_hash
                    self.new_keyfile_path = gfile.get_path()

            generate_keyfile_async(keyfile, callback)
Пример #2
0
            def hdl_response(dialog: Gtk.Dialog,
                             response: Gtk.ResponseType) -> None:
                del self.confirm_discard_dialog
                dialog.destroy()

                if response == Gtk.ResponseType.YES:
                    self.close(True)
Пример #3
0
    def _on_filechooser_response(self, dialog: Gtk.Dialog,
                                 response: Gtk.ResponseType,
                                 _dialog: Gtk.Dialog) -> None:
        dialog.destroy()
        if response == Gtk.ResponseType.ACCEPT:
            self.generate_keyfile_button.set_sensitive(False)
            self.generate_keyfile_button.set_label(_("Generating…"))
            keyfile = dialog.get_file()
            keyfile_path = keyfile.get_path()
            logging.debug("New keyfile location: %s", keyfile_path)

            def callback(gfile, result):
                password = self.new_password
                keyfile_path = gfile.get_path()
                try:
                    _res, keyfile_hash = generate_keyfile_finish(result)
                except GLib.Error as err:
                    logging.debug("Could not create keyfile: %s", err.message)
                    self.window.send_notification(
                        _("Could not create keyfile"))
                    self.generate_keyfile_button.set_sensitive(True)
                    self.generate_keyfile_button.set_label(_("Generate"))
                else:
                    if not self.composite:
                        password = ""

                    self.database_manager.set_credentials_async(
                        password,
                        keyfile_path,
                        keyfile_hash,
                        self._on_set_credentials,
                    )

            generate_keyfile_async(keyfile, callback)
Пример #4
0
            def on_response(dialog: Gtk.Dialog, resp: int) -> None:
                dialog.destroy()
                self.error_dialog = None

                if resp == Gtk.ResponseType.CANCEL:
                    self.on_cancel(None)
                elif resp == Gtk.ResponseType.NO:
                    finfo = self.files[-1].query_info(
                        'standard::*', Gio.FileQueryInfoFlags.NONE)
                    self.total_bytes -= finfo.get_size()
                    self.total_transferred -= self.transferred
                    self.transferred = 0
                    del self.files[-1]
                    if not self.object_push:
                        self.create_session()
                    self.process_queue()
                elif resp == Gtk.ResponseType.YES:
                    self.total_transferred -= self.transferred
                    self.transferred = 0
                    if not self.object_push:
                        self.create_session()

                    self.process_queue()
                else:
                    self.on_cancel(None)
Пример #5
0
 def on_response(dialog: Gtk.Dialog, response_id: int) -> None:
     if response_id == Gtk.ResponseType.ACCEPT:
         assert isinstance(alias_entry, Gtk.Entry)  # https://github.com/python/mypy/issues/2608
         device.set('Alias', alias_entry.get_text())
     elif response_id == 1:
         device.set('Alias', '')
     dialog.destroy()
Пример #6
0
 def on_dialog_response(self, dialog: Gtk.Dialog,
                        response: Gtk.ResponseType,
                        _dialog: Gtk.Dialog) -> None:
     dialog.destroy()
     if response == Gtk.ResponseType.ACCEPT:
         keyfile = dialog.get_file()
         self.set_keyfile(keyfile)
Пример #7
0
 def passkey_dialog_cb(dialog: Gtk.Dialog, response_id: int) -> None:
     if response_id == Gtk.ResponseType.ACCEPT:
         ret = pin_entry.get_text()
         ok(int(ret) if is_numeric else ret)
     else:
         err(BluezErrorRejected("Rejected"))
     dialog.destroy()
     self.dialog = None
 def _on_select_filechooser_response(
     self,
     select_dialog: Gtk.Dialog,
     response: Gtk.ResponseType,
     _dialog: Gtk.Dialog,
 ) -> None:
     select_dialog.destroy()
     if response == Gtk.ResponseType.ACCEPT:
         keyfile = select_dialog.get_file()
         keyfile.load_bytes_async(None, self.load_bytes_callback)
Пример #9
0
def reset_dialog(dialog: Gtk.Dialog, *args, **kwargs) -> None:
    content_area = dialog.get_content_area()
    header_bar = dialog.get_header_bar()

    for widget in content_area.get_children():
        widget.destroy()

    for widget in header_bar.get_children():
        widget.destroy()

    dialog.__init__(*args, **kwargs)
Пример #10
0
    def _on_dialog_response(self, dialog: Gtk.Dialog,
                            response: Gtk.ResponseType) -> None:
        database = self.window.unlocked_db
        dialog.close()

        if response == Gtk.ResponseType.YES:  # Save
            if database:
                database.database_manager.save_async(self._on_save)

        elif response == Gtk.ResponseType.NO:  # Discard
            self.window.save_window_size()
            self.window.destroy()
Пример #11
0
    def _on_select_filechooser_response(self, dialog: Gtk.Dialog,
                                        response: Gtk.ResponseType,
                                        _dialog: Gtk.Dialog) -> None:
        dialog.destroy()
        if response == Gtk.ResponseType.ACCEPT:
            safe_entry: SafeEntry = self.unlocked_database.current_element

            def callback(gfile, result):
                try:
                    gbytes, _stream = gfile.load_bytes_finish(result)
                except GLib.Error as err:
                    logging.debug("Could not read attachment: %s", err.message)
                else:
                    filename = gfile.get_basename()
                    data = gbytes.get_data()
                    new_attachment = safe_entry.add_attachment(data, filename)
                    self.add_attachment_row(new_attachment)

            for attachment in dialog.get_files():
                attachment.load_bytes_async(None, callback)
    def _on_save_filechooser_response(
        self,
        dialog: Gtk.Dialog,
        response: Gtk.ResponseType,
        _dialog: Gtk.Dialog,
    ) -> None:
        dialog.destroy()
        if response == Gtk.ResponseType.ACCEPT:
            gfile = dialog.get_file()
            bytes_buffer = self.entry.get_attachment_content(self.attachment)
            gbytes = GLib.Bytes.new(bytes_buffer)

            gfile.replace_contents_bytes_async(
                gbytes,
                None,
                False,
                Gio.FileCreateFlags.PRIVATE
                | Gio.FileCreateFlags.REPLACE_DESTINATION,
                None,
                self._replace_contents_callback,
            )
Пример #13
0
def send_note_cb(dialog: Gtk.Dialog, response_id: int, device_address: str,
                 text_view: Gtk.Entry) -> None:
    text = text_view.get_buffer().props.text
    dialog.destroy()
    if response_id == Gtk.ResponseType.CANCEL:
        return

    date = datetime.datetime.now().strftime('%Y%m%dT%H%M00')
    data = ('BEGIN:VNOTE \n'
            'VERSION:1.1 \n'
            'BODY;CHARSET=UTF-8: %s \n'
            'DCREATED:%s \n'
            'LAST-MODIFIED:%s \n'
            'CLASS:PUBLIC \n'
            'X-IRMC-LUID:000001000000 \n'
            'END:VNOTE \n' % (' '.join(text.splitlines()), date, date))

    tempfile = NamedTemporaryFile(suffix='.vnt', prefix='note', delete=False)
    tempfile.write(data.encode('utf-8'))
    tempfile.close()
    launch(f"blueman-sendto --delete --device={device_address}",
           paths=[tempfile.name])
Пример #14
0
 def _file_dialog_handler(self, saver_dialog: Gtk.Dialog, window: Gtk.Window):
     response = saver_dialog.run()
     if response == Gtk.ResponseType.OK:
         doc = window.get_active_document()
         # save the document with Gedit's save as function
         gfile_path = Gio.File.new_for_path(saver_dialog.get_filename())
         doc.save_as(gfile_path, doc.get_encoding(), doc.get_newline_type(), doc.get_compression_type(),
                     Gedit.DocumentSaveFlags(15))
         saver_dialog.destroy()
     elif response == Gtk.ResponseType.CANCEL:
         saver_dialog.destroy()
 def on_sr_dialog_close(self, dialog: Gtk.Dialog, *args):
     self._loaded_search_window = None
     dialog.hide()
     return True
Пример #16
0
 def on_delete_event(self, dialog: Gtk.Dialog, event) -> None:
     """
     Dialog box was manually closed (cancel).
     """
     dialog.destroy()
Пример #17
0
 def _create_menu_item(self, name: str, label: str, dialog: Gtk.Dialog) -> Gtk.MenuItem:
     menu_item = Gtk.MenuItem.new_with_label(label)
     menu_item.props.name = name
     menu_item.connect("activate", lambda *_: dialog.run())
     return menu_item
Пример #18
0
 def on_response(dialog: Gtk.Dialog, response_id: int) -> None:
     if response_id == Gtk.ResponseType.ACCEPT:
         device.set('Alias', alias_entry.get_text())
     elif response_id == 1:
         device.set('Alias', '')
     dialog.destroy()
Пример #19
0
def run_dialog(dialog: Dialog) -> ResponseType:
    try:
        yield dialog.run()
    finally:
        dialog.destroy()