Python gi.repository.Gtk 模块,STOCK_CANCEL 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用gi.repository.Gtk.STOCK_CANCEL

项目:susi_linux    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, parent):
        Gtk.Dialog.__init__(self, "Enter API Key", parent, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))

        self.set_default_size(150, 100)

        api_key_field = Gtk.Entry()
        api_key_field.set_placeholder_text("API Key")

        self.api_key_field = api_key_field

        box = self.get_content_area()

        box.set_margin_top(10)
        box.set_margin_bottom(10)
        box.set_margin_left(10)
        box.set_margin_right(10)

        box.set_spacing(10)

        box.add(api_key_field)
        self.show_all()
项目:PyIDE    作者:raggesilver    | 项目源码 | 文件源码
def createProject(self, *args):
        self.getLang()
        dialog = Gtk.FileChooserDialog("Please choose a folder", self, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, "Select", Gtk.ResponseType.OK))
        response = dialog.run()


        if response == Gtk.ResponseType.OK:

            projectPath = dialog.get_filename()
            self.projectPath = projectPath
            with open(os.path.join(projectPath, '.pyide-project.json'), 'w+') as f:
                defaultSettings = {
                    'path': projectPath,
                    'name': projectPath.split('/')[len(projectPath.split('/')) - 1],
                    'language': self.language
                }
                json.dump(defaultSettings, f, indent=4, sort_keys=True, separators=(',', ':'))

            self.createMainFile()

            os.execl(sys.executable, *([sys.executable]+sys.argv+[projectPath]))

        dialog.destroy()
项目:jcchess    作者:johncheetham    | 项目源码 | 文件源码
def show_pieces_dialog(self, gtkaction):
        dialog = Gtk.Dialog(
            _("Select Pieces"), gv.gui.get_window(), 0,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        rb1 = Gtk.RadioButton.new_with_label(None, "Pieceset 1")
        dialog.vbox.pack_start(rb1, False, True, 5)
        rb2 = Gtk.RadioButton.new_with_label_from_widget(rb1, "Pieceset 2")
        dialog.vbox.pack_start(rb2, False, True, 5)
        dialog.show_all()
        dialog.set_default_response(Gtk.ResponseType.OK)
        if self.pieceset == 0:
            rb1.set_active(True)
        elif self.pieceset == 1:
            rb2.set_active(True)
        else:
            rb1.set_active()
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            if rb1.get_active():
                self.pieceset = 0
            elif rb2.get_active():
                self.pieceset = 1
        dialog.destroy()
        return
项目:sbrick-controller    作者:wintersandroid    | 项目源码 | 文件源码
def on_save_as_configuration(self, action, param):
        dialog = Gtk.FileChooserDialog("Save Configuration As...", self.window,
                                       Gtk.FileChooserAction.SAVE,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
        dialog.set_filename(self.configFile)

        self.add_filters(dialog)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.configFile = dialog.get_filename()
            self.save_configuration(self.configFile)

        dialog.destroy()

    # noinspection PyUnusedLocal
项目:sbrick-controller    作者:wintersandroid    | 项目源码 | 文件源码
def on_open_configuration(self, action, param):
        dialog = Gtk.FileChooserDialog("Open Configuration...", self.window,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        dialog.set_filename(self.configFile)

        self.add_filters(dialog)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.configFile = dialog.get_filename()
            self.read_config()
            if self.window:
                self.window.close()
            self.window = MainWindow(application=self, title="SBrick Controller", config=self.config)
            self.window.present()
            # self.save_configuration(self.configFile)
        dialog.destroy()
项目:pyspc    作者:carlosqsilva    | 项目源码 | 文件源码
def on_file(self, button):

        dialog = Gtk.FileChooserDialog("Please choose a file", self,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        filter_csv = Gtk.FileFilter()
        filter_csv.set_name("CSV Files")
        filter_csv.add_pattern("*.csv")
        dialog.add_filter(filter_csv)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            path = dialog.get_filename()
            self.data = pd.read_csv(path)
            self.verticalbox.remove(self.scrollable_treelist)
            self.add_treeview()

        dialog.destroy()
项目:pyspc    作者:carlosqsilva    | 项目源码 | 文件源码
def on_file_clicked(self, widget):
        # dialog = Gtk.FileChooserDialog("Please choose a file", self,
        #                                Gtk.FileChooserAction.OPEN,
        #                                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
        #                                 Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        # response = dialog.run()
        # if response == Gtk.ResponseType.OK:
        #     path = dialog.get_filename()
        #     # self.open_file.set_label("File Selected: %s" % os.path.basename(path))
        #     self.data = pd.read_csv(path)

        # elif response == Gtk.ResponseType.CANCEL:
        #     print("Cancel clicked")

        # dialog.destroy()
        dialog = FileDialog(self)
        # dialog.show_all()
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.data = dialog.data
        dialog.destroy()
项目:Ebook-Viewer    作者:michaldaniel    | 项目源码 | 文件源码
def show_dialog(self, importing=False):
        """
        Displays FileChooserDialog with ePub file filters and returns Gtk.ResponseType and filename string
        :return (response, filename):
        """
        dialog = Gtk.FileChooserDialog(_("Please choose a file"), self, Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        # Always start in user dir
        dialog.set_current_folder(path.expanduser("~"))

        # Add filters so only .epub files show
        # TODO: Filter list for all conversion supported ebooks
        self.__add_filters(dialog, importing)

        response = dialog.run()
        filename = dialog.get_filename()
        dialog.destroy()

        return response, filename
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def __init__(self, oldname):
        Gtk.Dialog.__init__(self, _(u"_Rename profile\u2026").replace("_", "").replace(u"\u2026", ""))
        self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                        Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
        vbox = gu.hig_dlg_vbox()
        self.vbox.pack_start(vbox, True, True, 0)

        label = Gtk.Label(label=_(u"Rename the profile «%s» to:") % oldname)
        label.set_alignment(0.0, 0.5)
        vbox.pack_start(label, False, False, 0)

        self.g_entry = Gtk.Entry()
        self.g_entry.set_text(oldname)
        self.g_entry.set_activates_default(True)
        self.g_entry.connect('changed', self.on_entry_changed)
        vbox.pack_start(self.g_entry, False, False, 0)

        self.g_info = Gtk.Label()
        self.g_info.set_no_show_all(True)
        vbox.pack_start(self.g_info, False, False, 0)
        self.set_default_response(Gtk.ResponseType.ACCEPT)
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def file_open_cb(self, *v):
        dialog = Gtk.FileChooserDialog(_("Open..."), self,
                                   Gtk.FileChooserAction.OPEN,
                                   (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                    Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        dialog.set_default_response(Gtk.ResponseType.OK)
        if dialog.run() == Gtk.ResponseType.OK:
            filename = gu.decode_filename(dialog.get_filename())
            try:
                self.load_file(filename)
            except Exception, e:
                dialog.destroy()
                m = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR,
                        Gtk.ButtonsType.CLOSE,
                        _("Loading file '%(filename)s' failed: %(msg)s") %
                            {'filename': filename, 'msg': e})
                m.run()
                m.destroy()

            else:
                dialog.destroy()

        else:
            dialog.destroy()
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def file_save_cb(self, *v):
        self.store_data_from_ui()
        if self.m_P.m_filename is None:
            dialog = Gtk.FileChooserDialog(_("Save..."), self,
                                   Gtk.FileChooserAction.SAVE,
                                   (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                    Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
            dialog.set_default_response(Gtk.ResponseType.OK)

            if dialog.run() == Gtk.ResponseType.OK:
                self.m_P.m_filename = gu.decode_filename(dialog.get_filename())
            dialog.destroy()

        if self.m_P.m_filename:
            self.update_appwin()
            self.save_file()
项目:bcloud    作者:wangYanJava    | 项目源码 | 文件源码
def add_file_task(self, dir_name=None):
        '''??????, ?????????????'''
        file_dialog = Gtk.FileChooserDialog(_('Choose Files..'),
                self.app.window, Gtk.FileChooserAction.OPEN,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 Gtk.STOCK_OK, Gtk.ResponseType.OK))
        file_dialog.set_modal(True)
        file_dialog.set_select_multiple(True)
        file_dialog.set_default_response(Gtk.ResponseType.OK)
        response = file_dialog.run()
        if response != Gtk.ResponseType.OK:
            file_dialog.destroy()
            return
        source_paths = file_dialog.get_filenames()
        file_dialog.destroy()
        if source_paths:
            self.upload_files(source_paths, dir_name)
项目:bcloud    作者:wangYanJava    | 项目源码 | 文件源码
def add_folder_task(self, dir_name=None):
        '''??????, ??????????????'''
        folder_dialog = Gtk.FileChooserDialog(_('Choose Folders..'),
                self.app.window, Gtk.FileChooserAction.SELECT_FOLDER,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 Gtk.STOCK_OK, Gtk.ResponseType.OK))
        folder_dialog.set_modal(True)
        folder_dialog.set_select_multiple(True)
        folder_dialog.set_default_response(Gtk.ResponseType.OK)
        folder_dialog.set_current_folder(Config.HOME_DIR)
        response = folder_dialog.run()
        if response != Gtk.ResponseType.OK:
            folder_dialog.destroy()
            return
        source_paths = folder_dialog.get_filenames()
        folder_dialog.destroy()
        if source_paths:
            self.upload_files(source_paths, dir_name)
项目:bcloud    作者:wangYanJava    | 项目源码 | 文件源码
def on_download_to_activated(self, menu_item):
        '''????/??????????.'''
        tree_paths = self.iconview.get_selected_items()
        if not tree_paths:
            return

        dialog = Gtk.FileChooserDialog(_('Save to...'), self.app.window,
                Gtk.FileChooserAction.SELECT_FOLDER,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                 Gtk.STOCK_OK, Gtk.ResponseType.OK))
        response = dialog.run()
        if response != Gtk.ResponseType.OK:
            dialog.destroy()
            return
        dirname = dialog.get_filename()
        dialog.destroy()

        pcs_files = [self.get_pcs_file(p) for p in tree_paths]
        self.app.blink_page(self.app.download_page)
        self.app.download_page.add_tasks(pcs_files, dirname)
项目:ez_gpg    作者:sgnn7    | 项目源码 | 文件源码
def get_filename(window, title="Open..."):
        dialog = Gtk.FileChooserDialog(title,
                                       window,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN,
                                        Gtk.ResponseType.OK))

        dialog.set_default_response(Gtk.ResponseType.OK)
        UiUtils._set_keyfile_filter(dialog)

        response = dialog.run()

        filename = None
        if response == Gtk.ResponseType.OK:
            filename = dialog.get_filename()

        dialog.destroy()
        return filename
项目:MokaPlayer    作者:vedard    | 项目源码 | 文件源码
def __init__(self, parent, title, text):
        Gtk.Dialog.__init__(self, title, parent, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))

        self.set_default_size(350, 0)
        self.set_default_response(Gtk.ResponseType.OK)

        self.label = Gtk.Label(text)
        self.label.set_margin_start(5)
        self.label.set_margin_top(5)
        self.label.set_margin_bottom(5)
        self.label.set_margin_end(5)

        self.entry = Gtk.Entry()
        self.entry.set_margin_start(5)
        self.entry.set_margin_top(5)
        self.entry.set_margin_bottom(5)
        self.entry.set_margin_end(5)
        self.entry.connect('activate', lambda widget: self.response(Gtk.ResponseType.OK))

        self.get_content_area().add(self.label)
        self.get_content_area().add(self.entry)
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def _save(self, widget, data):
        chooser = Gtk.FileChooserDialog(title=None,action=Gtk.FileChooserAction.SAVE, buttons=(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL,Gtk.STOCK_OPEN,Gtk.ResponseType.OK))
        response = chooser.run()

        if response == Gtk.ResponseType.OK:
            all = ['asm', 'hex', 'str']
            filename = chooser.get_filename()
            if data != 'all':
                output = open(filename + '.' + data, 'wb')
                content = self._get_content(data)
                output.write(content)
                output.close()
            else:
                for fmt in all:
                    output = open(filename + '.' + fmt, 'wb')
                    content = self._get_content(fmt)
                    output.write(content)
                    output.close()
        chooser.destroy()
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def on_open(self, action):
        chooser = Gtk.FileChooserDialog(title="Open dot File",
                                        action=Gtk.FileChooserAction.OPEN,
                                        buttons=(Gtk.STOCK_CANCEL,
                                                 Gtk.ResponseType.CANCEL,
                                                 Gtk.STOCK_OPEN,
                                                 Gtk.ResponseType.OK))
        chooser.set_default_response(Gtk.ResponseType.OK)
        chooser.set_current_folder(self.last_open_dir)
        filter = Gtk.FileFilter()
        filter.set_name("Graphviz dot files")
        filter.add_pattern("*.dot")
        chooser.add_filter(filter)
        filter = Gtk.FileFilter()
        filter.set_name("All files")
        filter.add_pattern("*")
        chooser.add_filter(filter)
        if chooser.run() == Gtk.ResponseType.OK:
            filename = chooser.get_filename()
            self.last_open_dir = chooser.get_current_folder()
            chooser.destroy()
            self.open_file(filename)
        else:
            chooser.destroy()
项目:ibus-typing-booster    作者:mike-fabian    | 项目源码 | 文件源码
def on_delete_learned_data_clicked(self, dummy_widget):
        '''
        The button requesting to delete all data learned from
        user input or text files has been clicked.
        '''
        SETUP_UI.delete_learned_data_button.set_sensitive(False)
        confirm_question = Gtk.Dialog(
            title=_('Are you sure?'),
            parent=SETUP_UI.builder.get_object('main_dialog'),
            buttons=(
                Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                Gtk.STOCK_OK, Gtk.ResponseType.OK))
        box = confirm_question.get_content_area()
        box.add(Gtk.Label(
            _('Do you really want to delete all language \n'
              + 'data learned from typing or reading files?')))
        confirm_question.show_all()
        response = confirm_question.run()
        confirm_question.destroy()
        while Gtk.events_pending():
            Gtk.main_iteration()
        if response == Gtk.ResponseType.OK:
            SETUP_UI.tabsqlitedb.remove_all_phrases()
        SETUP_UI.delete_learned_data_button.set_sensitive(True)
项目:chromecast-player    作者:wa4557    | 项目源码 | 文件源码
def main(self):
        dialog = Gtk.FileChooserDialog("Please choose a file", self.win,
            Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
        self.button1 = dialog.add_button('Add to playlist', Gtk.ResponseType.OK)
        self.button2 = dialog.add_button('Play now', Gtk.ResponseType.OK)
        self.button1.connect("clicked", self._button_clicked)
        self.button2.connect("clicked", self._button_clicked)
        dialog.set_select_multiple(True)
        self.add_filters(dialog)
        ret = None
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            ret = (dialog.get_uris(), self.but)
        dialog.destroy()
        return ret
项目:SolStudio    作者:alianse777    | 项目源码 | 文件源码
def confirm(parent=None, title="", text=""):
    dialog = Gtk.Dialog(title, parent, 0)

    dialog.set_default_size(150, 100)
    dialog.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("white"))
    label = Gtk.Label()
    label.set_markup('<span foreground="#494941" face="sans">' + text + '</span>')
    box = dialog.get_content_area()
    box.add(label)
    box.show_all()
    btn1 = dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
    btn1.set_relief(2)
    btn2 = dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
    btn2.set_relief(2)
    result = False
    response = dialog.run()
    dialog.destroy()
    if response == Gtk.ResponseType.OK:
        result = True
    elif response == Gtk.ResponseType.CANCEL:
        result = False
    return result
项目:apart-gtk    作者:alexheretic    | 项目源码 | 文件源码
def __init__(self, root: Gtk.Window, text: str,
                 ok_button_text: str = Gtk.STOCK_OK,
                 cancel_button_text: str = Gtk.STOCK_CANCEL,
                 header: str = '',
                 message_type: Gtk.MessageType = Gtk.MessageType.WARNING):
        Gtk.MessageDialog.__init__(self, root, 0, message_type=message_type)
        self.set_title(header)
        self.icon = Gtk.Image()
        self.icon.set_from_icon_name(appropriate_icon(message_type), Gtk.IconSize.LARGE_TOOLBAR)
        self.text = Gtk.Label(text)
        heading = Gtk.Box()
        heading.add(self.icon)
        heading.add(self.text)

        self.get_message_area().add(heading)
        self.get_message_area().set_spacing(0)
        self.add_button(cancel_button_text, Gtk.ResponseType.CANCEL)
        self.add_button(ok_button_text, Gtk.ResponseType.OK)
        self.show_all()
项目:Remarkable    作者:jamiemcg    | 项目源码 | 文件源码
def save_as(self, widget):
        self.window.set_sensitive(False)
        chooser = Gtk.FileChooserDialog(title=None, action=Gtk.FileChooserAction.SAVE, buttons=(
            Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
        chooser.set_do_overwrite_confirmation(True)
        title = self.name.split("/")[-1]
        chooser.set_title("Save As: " + title)
        response = chooser.run()
        if response == Gtk.ResponseType.OK:
            file = open(chooser.get_filename(), 'w')
            self.name = chooser.get_filename()
            text = self.text_buffer.get_text(self.text_buffer.get_start_iter(), self.text_buffer.get_end_iter(), False)
            file.write(text)
            file.close()
            self.text_buffer.set_modified(False)
            title = self.name.split("/")[-1]
            self.window.set_title("Remarkable: " + title)
        elif response == Gtk.ResponseType.CANCEL:
            pass
        chooser.destroy()
        self.window.set_sensitive(True)
项目:Remarkable    作者:jamiemcg    | 项目源码 | 文件源码
def save_html(self, data):
        html = data
        chooser = Gtk.FileChooserDialog("Export HTML", None, Gtk.FileChooserAction.SAVE,
                                        (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                         Gtk.STOCK_OK, Gtk.ResponseType.OK))
        html_filter = Gtk.FileFilter()
        html_filter.set_name("HTML Files")
        html_filter.add_pattern("*.html")
        html_filter.add_pattern("*.htm")
        chooser.set_do_overwrite_confirmation(True)
        chooser.add_filter(html_filter)
        response = chooser.run()
        if response == Gtk.ResponseType.OK:
            file_name = chooser.get_filename()
            if not file_name.endswith(".html"):
                file_name += ".html"
            file = open(file_name, 'w')
            soup = BeautifulSoup(html, "lxml")

            file.write(soup.prettify())
            file.close()
        elif response == Gtk.ResponseType.CANCEL:
            pass
        chooser.destroy()
        self.window.set_sensitive(True)
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def on_file_clicked(self, widget):
        dialog = Gtk.FileChooserDialog("Please choose a file", self.get_toplevel(),
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        self.add_filters(dialog)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print("Open clicked")
            print("File selected: " + dialog.get_filename())
            self.text_file.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")

        dialog.destroy()
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def on_folder_clicked(self, widget):
        dialog = Gtk.FileChooserDialog("Please choose a folder", self.get_toplevel(),
                                       Gtk.FileChooserAction.SELECT_FOLDER,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        "Select", Gtk.ResponseType.OK))
        dialog.set_default_size(800, 400)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print("Select clicked")
            str1 = "Folder selected: " + dialog.get_filename()
            print(str1)
            self.fold_str = str1
            self.text_folder.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")

        dialog.destroy()
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def on_file_clicked(self, widget):
        dialog = Gtk.FileChooserDialog("Please choose a file", self,
            Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        self.add_filters(dialog)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print("Open clicked")
            print("File selected: " + dialog.get_filename())
            self.text_file.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")

        dialog.destroy()
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def on_folder_clicked(self, widget):
        dialog = Gtk.FileChooserDialog("Please choose a folder", self,
            Gtk.FileChooserAction.SELECT_FOLDER,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             "Select", Gtk.ResponseType.OK))
        dialog.set_default_size(800, 400)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print("Select clicked")
            str1 = "Folder selected: " + dialog.get_filename()
            print(str1)
            self.fold_str = str1
            self.text_folder.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")

        dialog.destroy()
项目:Vulnerabilities-spider    作者:muhammad-bouabid    | 项目源码 | 文件源码
def __init__(self, parent):
      Gtk.Dialog.__init__(self, "Something", parent,
          Gtk.DialogFlags.MODAL, buttons=(
          Gtk.STOCK_NEW, Gtk.ResponseType.OK,
          Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))

      self.set_default_size(400, 600)

      box = self.get_content_area()

      label = Gtk.Label("Insert text you want to search for:")
      box.add(label)

#        self.entry = Gtk.Entry()
#        box.add(self.entry)

      self.main_area = Gtk.Stack()
      self.main_area.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)

      self.main_area.set_transition_duration(1000)

      self.entry = Gtk.Entry()
      self.main_area.add_titled(self.entry, "entry_name", "Entry Url")

      self.labelS = Gtk.Label()
      self.label_txt = """<big><i>you have choice to runn the scan directly or after setup the scanning process you want to follow on your target</i></big>"""
      self.labelS.set_markup(self.label_txt)
      self.labelS.set_line_wrap(True)
      self.main_area.add_titled(self.labelS, "label_name", "How Scan will Start")

      self.our_stackSwitcher = Gtk.StackSwitcher()
      self.our_stackSwitcher.set_stack(self.main_area)

      box.add(self.our_stackSwitcher)
      box.add(self.main_area)

      self.show_all()


#~~~~~~~~~~~~ History Dialog ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
项目:poseidon    作者:sidus-dev    | 项目源码 | 文件源码
def force_save(self, content, name):

        d = Gtk.FileChooserDialog("{}: {}".format(_("Save as"), name), self,
            Gtk.FileChooserAction.SAVE,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        d.set_current_name(name)
        d.set_default_size(int(width), int(height))
        response = d.run()

        if response == Gtk.ResponseType.OK:

            if os.path.exists(d.get_filename()):
                if self.do_decision(name): pass
                else:
                    d.destroy()
                    return True

            with open(d.get_filename(), 'w') as f:
                f.write(content)
                f.close()

        d.destroy()
项目:poseidon    作者:sidus-dev    | 项目源码 | 文件源码
def import_bookmarks(self):

        d = Gtk.FileChooserDialog(_("Import a HTML bookmark file"), self,
            Gtk.FileChooserAction.OPEN,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
            Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT))

        d.set_default_size(int(width), int(height))

        filter_html = Gtk.FileFilter()
        filter_html.set_name("HTML files")
        filter_html.add_mime_type("text/html")
        d.add_filter(filter_html)

        response = d.run()

        if response == Gtk.ResponseType.ACCEPT:

            filename = d.get_filename()
            d.destroy()
            return filename

        d.destroy()
项目:cavalcade    作者:worron    | 项目源码 | 文件源码
def gtk_open_file(parent, filter_=None):
    """Gtk open file dialog"""
    dialog = Gtk.FileChooserDialog(
        "Select image file", parent, Gtk.FileChooserAction.OPEN,
        (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
    )

    if filter_ is not None:
        dialog.add_filter(filter_)

    response = dialog.run()
    if response != Gtk.ResponseType.OK:
        is_ok, file_ = False, None
    else:
        is_ok = True
        file_ = dialog.get_filename()

    dialog.destroy()
    return is_ok, file_
项目:gpt    作者:encarsia    | 项目源码 | 文件源码
def on_folder_clicked(self):
        Gtk.Window.__init__(self, title=_("Change working directory"))
        dialog = Gtk.FileChooserDialog(_("Choose directory"), self,
            Gtk.FileChooserAction.SELECT_FOLDER,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             _("Apply"), Gtk.ResponseType.OK))
        dialog.set_default_size(800, 400)
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            print(_("Select clicked"))
            print(_("Folder selected: ") + dialog.get_filename())
            self.selectedfolder = dialog.get_filename()
        elif response == Gtk.ResponseType.CANCEL:
            print(_("Cancel clicked"))
            self.selectedfolder = cli.stdir

        dialog.destroy()
项目:MTTT    作者:roxana-lafuente    | 项目源码 | 文件源码
def _on_file_clicked(self, widget, labelToUpdate, tab_name = "undefined"):
        """@brief     Get file path from dialog."""
        dialog = Gtk.FileChooserDialog("Please choose a file", None,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        self._add_file_filters(dialog)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            labelToUpdate.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            labelToUpdate.set_text("")

        if tab_name == "Machine translation":
            self.mt_out_text = os.path.dirname(dialog.get_filename())
        dialog.destroy()
项目:MTTT    作者:roxana-lafuente    | 项目源码 | 文件源码
def _on_dir_clicked(self, widget, labelToUpdate, command = ""):
        """@brief     Get folder path from dialog."""
        dialog = Gtk.FileChooserDialog("Please choose a directory", None,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL,
                                        Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        self._add_dir_filters(dialog)
        dialog.set_action(Gtk.FileChooserAction.SELECT_FOLDER)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            labelToUpdate.set_text(dialog.get_filename())
        elif response == Gtk.ResponseType.CANCEL:
            labelToUpdate.set_text("")

        if "change output directory" in command:
            self.output_directory = dialog.get_filename()
            self.post_editing_output.set_text(self.output_directory)
            self.evaluation_output.set_text(self.output_directory)

        dialog.destroy()
        if command == "change output directory and maybe create post edition table":
            self._check_if_both_files_are_choosen_post_edition(None, "")
项目:hubangl    作者:soonum    | 项目源码 | 文件源码
def build_confirm_dialog(self, message_type, message_label,
                             on_signal=None, callback=None):
        """
        Create a :class:`Gtk.MessageDialog` asking user for confirmation.

        :param message_type: :class:`Gtk.MessageType`
        :param message_label: text displayed to user as :class`str`
        :param on_signal: Gtk signal as :class:`str`
        :param callback: callback to connect to ``signal``
        """
        confirm_dialog = Gtk.MessageDialog(
            message_type=message_type, message_format=message_label)
        confirm_dialog.set_icon_from_file(self.images.logo_favicon_path)
        confirm_dialog.set_title("Confirmation")
        confirm_dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        confirm_dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
        confirm_dialog.set_modal(True)
        if on_signal and callback:
            confirm_dialog.connect(on_signal, callback)

        confirm_dialog.run()
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, icons):
        Gtk.MessageDialog.__init__(self, flags=Gtk.DialogFlags.MODAL,
                                   type=Gtk.MessageType.INFO)
        self.set_title("")
        icon_name = "softwarecenter"
        if icons.has_icon(icon_name):
            icon = Gtk.Image.new_from_icon_name(icon_name,
                                                Gtk.IconSize.DIALOG)
            self.set_image(icon)
            icon.show()
        self.format_secondary_text(
            _(RecommendationsPanelLobby.RECOMMENDATIONS_OPT_IN_TEXT))
        self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        self.add_button(
            _(RecommendationsPanelLobby.TURN_ON_RECOMMENDATIONS_TEXT),
            Gtk.ResponseType.YES)
        self.set_default_response(Gtk.ResponseType.YES)


# test helpers
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, icons):
        Gtk.MessageDialog.__init__(self, flags=Gtk.DialogFlags.MODAL,
                                   type=Gtk.MessageType.INFO)
        self.set_title("")
        icon_name = "softwarecenter"
        if icons.has_icon(icon_name):
            icon = Gtk.Image.new_from_icon_name(icon_name,
                                                Gtk.IconSize.DIALOG)
            self.set_image(icon)
            icon.show()
        self.format_secondary_text(
            _(RecommendationsPanelLobby.RECOMMENDATIONS_OPT_IN_TEXT))
        self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        self.add_button(
            _(RecommendationsPanelLobby.TURN_ON_RECOMMENDATIONS_TEXT),
            Gtk.ResponseType.YES)
        self.set_default_response(Gtk.ResponseType.YES)


# test helpers
项目:SafeEyes    作者:slgobinath    | 项目源码 | 文件源码
def select_image(self, button):
        """
        Show a file chooser dialog and let the user to select an image.
        """
        dialog = Gtk.FileChooserDialog(_('Please select an image'), self.window, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                       Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        png_filter = Gtk.FileFilter()
        png_filter.set_name("PNG files")
        png_filter.add_mime_type("image/png")
        png_filter.add_pattern("*.png")
        dialog.add_filter(png_filter)

        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self.break_config['image'] = dialog.get_filename()
            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(self.break_config['image'], 16, 16, True)
            self.img_break.set_from_pixbuf(pixbuf)
        elif response == Gtk.ResponseType.CANCEL:
            self.break_config.pop('image', None)
            self.img_break.set_from_stock('gtk-missing-image', Gtk.IconSize.BUTTON)

        dialog.destroy()
项目:sound-organiser-offline-app    作者:nils-van-zuijlen    | 项目源码 | 文件源码
def on_open_file_activate(self, image_menu_item):
        """Opening of a file"""
        dialog = Gtk.FileChooserDialog(action=Gtk.FileChooserAction.OPEN)
        dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
            Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
        dialog.set_transient_for(self.main_widget)
        file_filter = Gtk.FileFilter()
        file_filter.add_pattern("*.theatre")
        dialog.add_filter(file_filter)
        dialog.modal = True
        answer = dialog.run()
        try:
            if answer == Gtk.ResponseType.OK:
                self._open_file_callback(dialog.get_filename())
        finally:
            dialog.destroy()
项目:yt-browser    作者:juanfgs    | 项目源码 | 文件源码
def on_download_clicked(self,button,video_data):
        """ Show the file dialog """
        file_chooser_dialog = Gtk.FileChooserDialog("Elegir donde guardar el video", self.window, Gtk.FileChooserAction.SAVE,
                                                    (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                                     Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        file_chooser_dialog.set_current_name(video_data["title"])



        if file_chooser_dialog.run() == Gtk.ResponseType.OK:
            filename = file_chooser_dialog.get_filename()

            row  = button.get_parent().get_parent()

            # for widget in button.get_parent().get_children():
            #     if widget.__class__.__name__ == 'Button':
            #         widget.destroy()
            video_iter = self.add_video_to_queue(video_data)
            self.video_list.show_all()
            file_chooser_dialog.destroy()

            if video_data["action"] == "convert": #add postprocessing if convert was pressed
                self.backend.convert(True)

            self.download_video_thread(video_data["video_id"], filename,video_iter)
        else:
            file_chooser_dialog.destroy()
项目:aniwall    作者:worron    | 项目源码 | 文件源码
def run(self, path_suggest=None, name_suggest=None):
        """Activate dialog"""
        dialog = Gtk.FileChooserDialog(
            self.title, self.parent, self.action,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, self.action_button, Gtk.ResponseType.OK)
        )

        # set initial location and file name
        if path_suggest is not None:
            dialog.set_current_folder(path_suggest)
        else:
            dialog.set_current_folder(self.homedir)
        if name_suggest is not None:
            dialog.set_current_name(name_suggest)

        # listen response
        is_ok, path, filename = False, None, None
        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            # get data
            is_ok = True
            path = dialog.get_current_folder()
            if self.action != Gtk.FileChooserAction.SELECT_FOLDER:
                filename = dialog.get_filename()

        # clean up
        dialog.destroy()
        return is_ok, path, filename
项目:susi_linux    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, parent):
        Gtk.Dialog.__init__(self, "Enter Credentials", parent, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))

        self.set_default_size(150, 100)

        username_field = Gtk.Entry()
        username_field.set_placeholder_text("Username")
        password_field = Gtk.Entry()
        password_field.set_placeholder_text("Password")
        password_field.set_visibility(False)
        password_field.set_invisible_char('*')

        self.username_field = username_field
        self.password_field = password_field

        box = self.get_content_area()

        box.set_margin_top(10)
        box.set_margin_bottom(10)
        box.set_margin_left(10)
        box.set_margin_right(10)

        box.set_spacing(10)

        box.add(username_field)
        box.add(password_field)
        self.show_all()
项目:mama    作者:maateen    | 项目源码 | 文件源码
def __init__(self):
        w=Gtk.Window()
        dialog = Gtk.FileChooserDialog(_("Choose a file"), w,Gtk.FileChooserAction.OPEN,(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        dialog.set_default_size(800, 400)

        response = dialog.run()
        self.module = '-1'
        if response == Gtk.ResponseType.OK:
            self.module=dialog.get_filename()
        elif response == Gtk.ResponseType.CANCEL:
            print("Cancel clicked")

        dialog.destroy()
项目:mama    作者:maateen    | 项目源码 | 文件源码
def __init__(self, app):
        Gtk.Window.__init__(self, title="Mama Manager", application=app)
        self.set_default_size(800, 400)
        self.set_resizable(True)
        self.set_border_width(0)
        self.get_focus()
        self.set_position(Gtk.WindowPosition.CENTER)
        path = os.path.dirname(os.path.abspath(__file__)).strip('librairy')
        self.icon_path = path + 'resources/icons/'
        self.set_default_icon_from_file(path + '/resources/icons.png')

        # get two button to switch between view
        setup_icon = Gtk.Image()
        setup_icon.set_from_file(self.icon_path + 'setup.png')
        button_config = Gtk.ToolButton(icon_widget=setup_icon)
        button_config.set_label("Setup")
        button_config.set_is_important(True)
        button_config.set_tooltip_text('Open setup window')
        button_config.show()
        button_config.connect("clicked", self.change_page, 1)

        button_back = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
        button_back.connect("clicked", self.change_page, 0)
        button_cancel = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
        button_cancel.connect("clicked", self.change_page, 0)

        # get the main view
        content = AddWindow(button_config)
        label_main = Gtk.Label("main")
        config = SetupWindow(button_back, button_cancel)
        label_config = Gtk.Label("config")

        # create a Gtk.Notebook to store both page
        self.notebook = Gtk.Notebook.new()
        self.notebook.set_show_tabs(False)
        self.notebook.append_page(content.get_grid(), label_main)
        self.notebook.append_page(config.getGrid(), label_config)

        # show
        self.add(self.notebook)
        self.show_all()
项目:mama    作者:maateen    | 项目源码 | 文件源码
def __init__(self, store, iter=None):
        self.grid = Gtk.Grid()
        self.grid.set_border_width(5)
        self.grid.set_row_spacing(5)
        self.grid.set_vexpand(True)
        self.grid.set_hexpand(True)
        self.grid.set_column_spacing(2)
        self.grid.set_column_homogeneous(False)
        self.grid.set_row_homogeneous(False)

        label1 = Gtk.Label('key sentence')
        label1.set_justify(Gtk.Justification.LEFT)
        label1.set_halign(Gtk.Align.START)
        label1.set_hexpand(True)
        label2 = Gtk.Label('your command')
        label2.set_justify(Gtk.Justification.LEFT)
        label2.set_halign(Gtk.Align.START)
        ll = Gtk.Label()
        ll.set_vexpand(True)
        self.entry1 = Gtk.Entry()
        if iter is not None:
            self.entry1.set_text(store[iter][0])

        self.combo = self.__get_combobox(store, iter)
        button = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
        button.connect("clicked", self.button_clicked, store, iter)
        button_cancel = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
        button_cancel.connect("clicked", self.do_destroy)

        self.grid.attach(label1, 0, 0, 11, 1)
        self.grid.attach(self.entry1, 11, 0, 4, 1)
        self.grid.attach(label2, 0, 1, 11, 1)
        self.grid.attach(self.combo, 11, 1, 4, 1)
        self.grid.attach(ll, 0, 2, 15, 1)
        self.grid.attach(button_cancel, 13, 3, 1, 1)
        self.grid.attach(button, 14, 3, 1, 1)
        self.grid.show_all()
项目:mama    作者:maateen    | 项目源码 | 文件源码
def __init__(self, store, iter=None):
        self.grid = Gtk.Grid()
        self.grid.set_border_width(5)
        self.grid.set_row_spacing(5)
        self.grid.set_vexpand(True)
        self.grid.set_hexpand(True)
        self.grid.set_column_spacing(2)
        self.grid.set_column_homogeneous(False)
        label1 = Gtk.Label('key sentence')
        label1.set_hexpand(True)
        label1.set_justify(Gtk.Justification.LEFT)
        label1.set_halign(Gtk.Align.START)
        label2 = Gtk.Label('your command')
        label2.set_justify(Gtk.Justification.LEFT)
        label2.set_halign(Gtk.Align.START)
        ll = Gtk.Label()
        ll.set_vexpand(True)
        self.entry1 = Gtk.Entry()
        self.entry2 = Gtk.Entry()

        if iter is not None:
            self.entry1.set_text(store[iter][0])
            self.entry2.set_text(store[iter][1])

        button = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
        button.connect("clicked", self.button_clicked, store, iter)
        button_cancel = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
        button_cancel.connect("clicked", self.do_destroy)

        self.grid.attach(label1, 0, 0, 11, 1)
        self.grid.attach(self.entry1, 11, 0, 4, 1)
        self.grid.attach(label2, 0, 1, 11, 1)
        self.grid.attach(self.entry2, 11, 1, 4, 1)
        self.grid.attach(ll, 0, 2, 15, 1)
        self.grid.attach(button_cancel, 13, 3, 1, 1)
        self.grid.attach(button, 14, 3, 1, 1)
        self.grid.show_all()
项目:Dict-O-nator    作者:theawless    | 项目源码 | 文件源码
def __init__(self, window: Gtk.Window):

        """Constructor.

        :param window: current window to set as parent.
        """
        self.owner = window
        self.file_chooser = Gtk.FileChooserDialog("Save file", window, Gtk.FileChooserAction.SAVE, (
            Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
        # Sets whether we get the overwrite confirmation
        self.file_chooser.set_do_overwrite_confirmation(True)
        self.save_possible = False
项目:stickies    作者:aboudzakaria    | 项目源码 | 文件源码
def __init__(self, parent, message=""):
        Gtk.Dialog.__init__(self, "Confirmation", parent, 0,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        self.set_resizable(False)
        self.get_content_area().add(Gtk.Label(message))
        self.show_all()
项目:ubi-virtual-assistant    作者:Alzemand    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Dialog.__init__(self, 'File Downloader',None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.set_size_request(400, 100)
        self.set_title('? ubi site file downloader')
        self.connect('destroy', self.close_application)
        #
        vbox0 = Gtk.VBox(spacing = 10)
        vbox0.set_border_width(5)
        self.get_content_area().add(vbox0)
        #
        table1 = Gtk.Table(3,2,False)
        vbox0.add(table1)
        label10 = Gtk.Label('Extension:')
        label10.set_alignment(0, 0.5)
        table1.attach(label10,0,1,0,1)
        #
        self.entry10 = Gtk.Entry()
        table1.attach(self.entry10,1,2,0,1)     
        #
        label11 = Gtk.Label('Url:')
        label11.set_alignment(0, 0.5)
        table1.attach(label11,0,1,1,2)
        #
        self.entry11 = Gtk.Entry()
        table1.attach(self.entry11,1,2,1,2)
        #
        #self.button = Gtk.Button('Select folder')
        #self.button.connect('clicked',self.on_button_clicked)
        #table1.attach(self.button,0,2,2,3)
        #
        self.show_all()