Python gi.repository.Gtk.STOCK_OK Examples

The following are 30 code examples of gi.repository.Gtk.STOCK_OK(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gtk , or try the search function .
Example #1
Source File: UploadPage.py    From bcloud with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #2
Source File: UploadPage.py    From bcloud with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #3
Source File: IconWindow.py    From bcloud with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #4
Source File: class_bankaccounts.py    From amir with GNU General Public License v3.0 6 votes vote down vote up
def addNewBank(self, model):
        dialog = Gtk.Dialog(None, None,
                            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        label = Gtk.Label(label='Bank Name:')
        entry = Gtk.Entry()
        dialog.vbox.pack_start(label, False, False, 0)
        dialog.vbox.pack_start(entry, False, False, 0)
        dialog.show_all()
        result = dialog.run()
        bank_name = entry.get_text()
        if result == Gtk.ResponseType.OK and len(bank_name) != 0:
            iter = model.append()
            model.set(iter, 0, bank_name)
            self.add_bank(bank_name)

        dialog.destroy() 
Example #5
Source File: preferences_window.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def _config_chooser_dialog(self, title_text, description):
        """Dialog to select which config shall be exported

        :param title_text: Title text
        :param description: Description
        """
        dialog = Gtk.Dialog(title_text, self.view["preferences_window"],
                            flags=0, buttons=
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
                             Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        label = Gtk.Label(label=description)
        label.set_padding(xpad=10, ypad=10)
        dialog.vbox.pack_start(label, True, True, 0)
        label.show()
        self._gui_checkbox = Gtk.CheckButton(label="GUI Config")
        dialog.vbox.pack_start(self._gui_checkbox, True, True, 0)
        self._gui_checkbox.show()
        self._core_checkbox = Gtk.CheckButton(label="Core Config")
        self._core_checkbox.show()
        dialog.vbox.pack_start(self._core_checkbox, True, True, 0)
        response = dialog.run()
        dialog.destroy()
        return response 
Example #6
Source File: results.py    From runsqlrun with MIT License 6 votes vote down vote up
def export_selected(self):
        def to_csv(value):
            if value is None:
                return ''
            elif isinstance(value, memoryview):
                return ''
            return str(value)

        dlg = Gtk.FileChooserDialog(
            'Export Selection', self.win, Gtk.FileChooserAction.SAVE,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        file_filter = Gtk.FileFilter()
        file_filter.set_name('CSV files')
        file_filter.add_mime_type('text/csv')
        dlg.add_filter(file_filter)
        dlg.set_current_name('export.csv')
        if dlg.run() == Gtk.ResponseType.ACCEPT:
            with open(dlg.get_filename(), 'w') as f:
                writer = csv.writer(f)
                for row in self._selection.get_export_data():
                    writer.writerow(list(map(to_csv, row)))
        dlg.destroy() 
Example #7
Source File: configwindow.py    From autokey with GNU General Public License v3.0 6 votes vote down vote up
def on_new_topfolder(self, widget, data=None):
        dlg = Gtk.FileChooserDialog(_("Create New Folder"), self.ui)
        dlg.set_action(Gtk.FileChooserAction.CREATE_FOLDER)
        dlg.set_local_only(True)
        dlg.add_buttons(_("Use Default"), Gtk.ResponseType.NONE, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK)

        response = dlg.run()
        if response == Gtk.ResponseType.OK:
            path = dlg.get_filename()
            self.__createFolder(os.path.basename(path), None, path)
            self.app.monitor.add_watch(path)
            dlg.destroy()
            self.app.config_altered(True)
        elif response == Gtk.ResponseType.NONE:
            dlg.destroy()
            name = self.__getNewItemName("Folder")
            self.__createFolder(name, None)
            self.app.config_altered(True)
        else:
            dlg.destroy() 
Example #8
Source File: comments_dialog.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, title='Add comment'):
        super(CommentsDialog,self).__init__(title, None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))

        # the cancel button
        self.butt_cancel = self.action_area.get_children()[1]
        self.butt_cancel.connect("clicked", lambda x: self.destroy())

        # Positions
        self.resize(400, 200)
        self.set_position(Gtk.WindowPosition.CENTER)
        ui.gtk3.common.set_bokken_icon(self)

        # Log TextView
        #################################################################
        self.input_text = Gtk.TextView(buffer=None)
        self.input_text.set_wrap_mode(Gtk.WrapMode.NONE)
        self.input_text.set_left_margin(10)
        self.input_buffer = self.input_text.get_buffer()

        self.scrolled_window = Gtk.ScrolledWindow()
        self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.scrolled_window.is_visible = True

        # Add Textview to Scrolled Window
        self.scrolled_window.add_with_viewport(self.input_text)

        #self.vbox.pack_start(self.input_text, True, True, 0)
        self.vbox.pack_start(self.scrolled_window, True, True, 0)
        self.show_all() 
Example #9
Source File: pdf_quench.py    From pdf-quench with GNU General Public License v2.0 5 votes vote down vote up
def __open_file(self):
    dialog = Gtk.FileChooserDialog(title='Load pdf file',
                                   parent=self,
                                   action=Gtk.FileChooserAction.OPEN,
                                   buttons=(Gtk.STOCK_CANCEL,
                                            Gtk.ResponseType.CANCEL,
                                            Gtk.STOCK_OK,
                                            Gtk.ResponseType.OK))
    global LAST_OPEN_FOLDER
    if LAST_OPEN_FOLDER:
      dialog.set_current_folder(LAST_OPEN_FOLDER)
    else:
      dialog.set_current_folder(os.getcwd())
    file_filter = Gtk.FileFilter()
    file_filter.add_pattern("*.pdf")
    dialog.set_filter(file_filter)
    pdf_file_name = None

    try:
      response = dialog.run()
      if response == Gtk.ResponseType.OK:
        pdf_file_name = dialog.get_filename()
        LAST_OPEN_FOLDER = os.path.dirname(pdf_file_name)
      dialog.hide()
    finally:
      dialog.destroy()

    if pdf_file_name:
      self.__load_pdf_file(pdf_file_name)
      self.__pages_view.get_selection().select_iter(
          self.__pages_model.get_iter_first())

    return True 
Example #10
Source File: basedialog.py    From lplayer with MIT License 5 votes vote down vote up
def __init__(self, title, window=None, ok_button=True, cancel_button=True):
        Gtk.Dialog.__init__(self, title, window)
        self.set_modal(True)
        self.set_destroy_with_parent(True)
        if ok_button:
            self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
        if cancel_button:
            self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        self.set_default_response(Gtk.ResponseType.ACCEPT)
        self.set_resizable(False)
        self.set_icon_from_file(comun.ICON)
        self.connect('realize', self.on_realize)
        self.init_ui()
        self.show_all() 
Example #11
Source File: setting.py    From amir with GNU General Public License v3.0 5 votes vote down vote up
def repairDbFunc(self):
        share.config.db.rebuild_nested_set(0, 0)

        self.msgbox.set_markup(_("Repair Operation Completed!"))
        self.msgbox.add_button(Gtk.STOCK_OK, -5)
        self.msgbox.run()
        self.msgbox.destroy()
        return False 
Example #12
Source File: pyspc_gui.py    From pyspc with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent):
        Gtk.Dialog.__init__(self, "File Dialog", parent, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        self.set_default_size(500, 550)
        box = self.get_content_area()

        self.verticalbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=3)
        box.add(self.verticalbox)

        self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

        from_file = Gtk.Button("From File")
        from_file.connect("clicked", self.on_file)
        from_clipboard = Gtk.Button("Clipboard")
        from_clipboard.connect("clicked", self.on_clipboard)

        hbox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=True)
        hbox1.pack_start(from_file, True, True, 0)
        hbox1.pack_start(from_clipboard, True, True, 0)
        self.verticalbox.pack_start(hbox1, False, False, 0)

        # Just holding the Place for real treeview widget
        self.scrollable_treelist = Gtk.Label()
        self.verticalbox.pack_start(self.scrollable_treelist, True, True, 0)

        self.show_all() 
Example #13
Source File: results.py    From runsqlrun with MIT License 5 votes vote down vote up
def save_blob_contents(self, value, content_type):
        dlg = Gtk.FileChooserDialog(
            'Save Contents', self.win, Gtk.FileChooserAction.SAVE,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        if dlg.run() == Gtk.ResponseType.ACCEPT:
            with open(dlg.get_filename(), 'wb') as f:
                f.write(value)
        dlg.destroy() 
Example #14
Source File: automaticaccounting.py    From amir with GNU General Public License v3.0 5 votes vote down vote up
def on_discount_clicked(self, button):
        dialog = Gtk.Dialog("Discount percentage",
                            self.builder.get_object('general'),
                            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK)
                            )
        adj = Gtk.Adjustment(0, 0, 100, 1, 1)
        spin = Gtk.SpinButton()
        spin.set_adjustment(adj)

        hbox = Gtk.HBox()
        hbox.pack_start(spin, True, True, 0)
        hbox.pack_start(Gtk.Label(' % ', True, True, 0), False, False, 0)
        hbox.show_all()

        dialog.vbox.pack_start(hbox, False, False, 0)

        result = dialog.run()
        if result == Gtk.ResponseType.OK:
            val = spin.get_value()
            total = self.total_credit_entry.get_float()
            discount = (val*total)/100
            self.discount_entry.set_text(str(discount))

        dialog.destroy() 
Example #15
Source File: search_dialog.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, main, title='Search results'):
        super(SearchDialog,self).__init__(title, main.window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_OK,Gtk.ResponseType.ACCEPT))

        # the cancel button
        self.butt_cancel = self.action_area.get_children()[0]
        self.butt_cancel.connect("clicked", lambda x: self.destroy())

        # Positions
        self.resize(400, 400)
        self.set_position(Gtk.WindowPosition.CENTER)
        ui.gtk3.common.set_bokken_icon(self)

        # Log TextView
        #################################################################
        self.output_text = Gtk.TextView(buffer=None)
        self.output_text.set_wrap_mode(Gtk.WrapMode.NONE)
        self.output_text.set_editable(False)
        self.output_buffer = self.output_text.get_buffer()

        self.scrolled_window = Gtk.ScrolledWindow()
        self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.ALWAYS)
        self.scrolled_window.is_visible = True

        # Add Textview to Scrolled Window
        self.scrolled_window.add_with_viewport(self.output_text)

        #self.vbox.pack_start(self.output_text, True, True, 0)
        self.vbox.pack_start(self.scrolled_window, True, True, 0)
        self.show_all() 
Example #16
Source File: VCodeDialog.py    From bcloud with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent, app, info):
        super().__init__(_('Verification..'), app.window,
                         Gtk.DialogFlags.MODAL,
                         (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                          Gtk.STOCK_OK, Gtk.ResponseType.OK))

        self.set_default_response(Gtk.ResponseType.OK)
        self.set_default_size(320, 200)
        self.set_border_width(10)
        self.app = app

        box = self.get_content_area()
        box.set_spacing(10)

        gutil.async_call(net.urlopen, info['img'],
                         {'Cookie': app.cookie.header_output()},
                         callback=self.update_img)
        self.img = Gtk.Image()
        box.pack_start(self.img, False, False, 0)

        self.entry = Gtk.Entry()
        self.entry.connect('activate',
                lambda *args: self.response(Gtk.ResponseType.OK))
        box.pack_start(self.entry, False, False, 0)

        box.show_all() 
Example #17
Source File: NewFolderDialog.py    From bcloud with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent, app, path):
        super().__init__(_('New Folder'), app.window, Gtk.DialogFlags.MODAL,
                         (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                         Gtk.STOCK_OK, Gtk.ResponseType.OK))
        self.set_default_response(Gtk.ResponseType.OK)
        self.connect('show', self.on_show)
        self.set_default_size(550, 200)

        self.app = app
        self.path = path

        self.set_border_width(10)
        box = self.get_content_area()

        folder_name = _('New Folder')
        abspath = os.path.join(path, folder_name)
        self.entry = Gtk.Entry()
        self.entry.set_text(abspath)
        self.entry.connect('changed', self.on_entry_changed)
        self.entry.connect('activate', self.on_entry_activated)
        box.pack_start(self.entry, True, True, 10)

        self.infobar = Gtk.InfoBar()
        self.infobar.timestamp = 0
        self.infobar.set_message_type(Gtk.MessageType.ERROR)
        box.pack_start(self.infobar, False, False, 0)
        self.info_label= Gtk.Label()
        self.infobar.get_content_area().pack_start(self.info_label, False,
                                                   False, 0)

        box.show_all()
        self.infobar.hide() 
Example #18
Source File: templates.py    From rednotebook with GNU General Public License v2.0 5 votes vote down vote up
def on_new_template(self, action):
        dialog = Gtk.Dialog(_("Choose Template Name"))
        dialog.set_transient_for(self.main_window.main_frame)
        dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
        dialog.set_response_sensitive(Gtk.ResponseType.OK, False)

        # Let user finish by hitting ENTER.
        def respond(widget):
            dialog.response(Gtk.ResponseType.OK)

        def on_text_changed(entry):
            dialog.set_response_sensitive(Gtk.ResponseType.OK, bool(entry.get_text()))

        entry = Gtk.Entry()
        entry.connect("activate", respond)
        # Only allow closing dialog when text is entered.
        entry.connect("changed", on_text_changed)
        entry.set_size_request(300, -1)
        dialog.get_content_area().pack_start(entry, True, True, 0)
        dialog.show_all()
        response = dialog.run()
        dialog.hide()

        if response == Gtk.ResponseType.OK:
            title = entry.get_text()
            selection = self.main_window.day_text_field.get_selection_bounds()
            path = self.get_path(title)
            filesystem.make_file(path, example_text)
            self.enter_template_mode(title, selection) 
Example #19
Source File: FlatCAMApp.py    From FlatCAM with MIT License 5 votes vote down vote up
def question_dialog(self, title, message):
        label = Gtk.Label(message)
        dialog = Gtk.Dialog(title, self.window, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        dialog.set_default_size(150, 100)
        dialog.set_modal(True)
        box = dialog.get_content_area()
        box.set_border_width(10)
        box.add(label)
        dialog.show_all()
        response = dialog.run()
        dialog.destroy()
        return response 
Example #20
Source File: run.py    From twitch-indicator with zlib License 5 votes vote down vote up
def settings_dialog(self, widget):
    """Shows applet settings dialog."""
    self.dialog = gtk.Dialog(
      "Settings",
      None,
      0,
      (gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL,
       gtk.STOCK_OK, gtk.ResponseType.OK)
    )

    self.builder = gtk.Builder()
    self.builder.add_from_file("/usr/lib/twitch-indicator/twitch-indicator.glade")

    self.builder.get_object("twitch_username").set_text(self.settings.get_string("twitch-username"))
    self.builder.get_object("show_notifications").set_active(self.settings.get_boolean("enable-notifications"))
    self.builder.get_object("refresh_interval").set_value(self.settings.get_int("refresh-interval"))

    self.box = self.dialog.get_content_area()
    self.box.add(self.builder.get_object("grid1"))
    self.response = self.dialog.run()

    if self.response == gtk.ResponseType.OK:
      self.settings.set_string("twitch-username", self.builder.get_object("twitch_username").get_text())
      self.settings.set_boolean("enable-notifications", self.builder.get_object("show_notifications").get_active())
      self.settings.set_int("refresh-interval", self.builder.get_object("refresh_interval").get_value_as_int())
    elif self.response == gtk.ResponseType.CANCEL:
      pass

    self.dialog.destroy() 
Example #21
Source File: DownloadMedia.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def display(self):
        """
        Constructs the GUI, consisting of a message, and fields to enter the
        name and password (commented out for now)
        """


        # GUI setup:
        dialog = Gtk.Dialog(_("Download media tool"),
                                self.uistate.window,
                                Gtk.DialogFlags.MODAL|
                                Gtk.DialogFlags.DESTROY_WITH_PARENT,
                                (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
                                 Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        label = Gtk.Label(_("Make sure you are connected to the internet "
                            "before starting this tool."))
        label.set_line_wrap(True)
        vbox = Gtk.VBox()
        vbox.pack_start(label, True, True, 0)

#        hbox1 = Gtk.HBox()
#        label_name = Gtk.Label(_("Name") + ":")
#        self.name_entry = Gtk.Entry()
#        self.name_entry.set_text("%s" % name)
#        hbox1.pack_start(label_name, False, False, 0)
#        hbox1.pack_start(self.name_entry, True, True, 0)
#        vbox.pack_start(hbox1, False)
#
#        hbox2 = Gtk.HBox()
#        label_password = Gtk.Label(_("Password") + ":")
#        self.password_entry = Gtk.Entry()
#        self.password_entry.set_text("%s" % password)
#        hbox2.pack_start(label_password, False, False, 0)
#        hbox2.pack_start(self.password_entry, True, True, 0)
#        vbox.pack_start(hbox2, False)

        dialog.vbox.set_spacing(10)
        dialog.vbox.pack_start(vbox, True, True, 0)
        dialog.show_all()
        return dialog 
Example #22
Source File: foldereditor.py    From syncthing-gtk with GNU General Public License v2.0 5 votes vote down vote up
def on_btBrowse_clicked(self, *a):
		"""
		Display folder browser dialog to browse for folder... folder.
		Oh god, this new terminology sucks...
		"""
		if not self.is_new: return
		# Prepare dialog
		d = Gtk.FileChooserDialog(
			_("Select Folder for new Folder"),	# fuck me...
			self["editor"],
			Gtk.FileChooserAction.SELECT_FOLDER,
			(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
			Gtk.STOCK_OK, Gtk.ResponseType.OK))
		# Set default path to home directory
		d.set_current_folder(os.path.expanduser("~"))
		# Get response
		if d.run() == Gtk.ResponseType.OK:
			self["vpath"].set_text(d.get_filename())
			if len(self["vid"].get_text().strip()) == 0:
				# ID is empty, fill it with last path element
				try:
					lpl = os.path.split(d.get_filename())[-1]
					id = RE_GEN_ID.search(lpl).group(0).lower()
					self["vid"].set_text(id)
				except AttributeError:
					# Can't regexp anything
					pass
		d.destroy() 
Example #23
Source File: gameinfoDialog.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def on_pick_date(button, date_entry):
    # Parse the existing date
    date = date_entry.get_text()
    year, month, day = parseDateTag(date)

    # Prepare the date of the picker
    calendar = Gtk.Calendar()
    curyear, curmonth, curday = calendar.get_date()
    year = curyear if year is None else year
    month = curmonth if month is None else month - 1
    day = curday if day is None else day
    calendar.select_month(month, year)
    calendar.select_day(day)

    # Show the dialog
    dialog = Gtk.Dialog(_("Pick a date"),
                        None,
                        Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                        (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))

    sw = Gtk.ScrolledWindow()
    sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
    sw.add(calendar)

    dialog.get_content_area().pack_start(sw, True, True, 0)
    dialog.resize(300, 200)
    dialog.show_all()

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

    if response == Gtk.ResponseType.ACCEPT:
        year, month, day = calendar.get_date()
        date_entry.set_text("%04d.%02d.%02d" % (year, month + 1, day)) 
Example #24
Source File: prompttext.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def getUserTextDialog(parent, title, description):
    dialog = Gtk.Dialog(title, parent,
                        Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                        (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                         Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
    dialog.set_resizable(False)
    dialog.set_size_request(400, -1)

    vbx = Gtk.VBox()
    label = Gtk.Label(description)
    label.set_xalign(0)
    vbx.pack_start(label, True, True, 5)
    textedit = Gtk.Entry()
    textedit.connect("activate", lambda p: dialog.response(Gtk.ResponseType.ACCEPT))
    vbx.pack_end(textedit, True, True, 5)

    hbx = Gtk.HBox()
    hbx.pack_start(vbx, True, True, 10)

    dialog.get_content_area().pack_start(hbx, True, True, 5)
    dialog.show_all()
    if (dialog.run() == Gtk.ResponseType.ACCEPT):
        result = textedit.get_text()
    else:
        result = None
    dialog.destroy()
    return result 
Example #25
Source File: RemarkableWindow.py    From Remarkable with MIT License 5 votes vote down vote up
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))
        self.set_file_chooser_path(chooser)
        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) 
Example #26
Source File: ui.py    From pympress with GNU General Public License v2.0 5 votes vote down vote up
def adjust_frame_position(self, *args):
        """ Select how to align the frame on screen.
        """
        win_aspect_ratio = float(self.c_win.get_allocated_width()) / self.c_win.get_allocated_height()

        if win_aspect_ratio <= float(self.c_frame.get_property("ratio")):
            prop = "yalign"
        else:
            prop = "xalign"

        val = self.c_frame.get_property(prop)

        button = Gtk.SpinButton()
        button.set_adjustment(Gtk.Adjustment(lower=0.0, upper=1.0, step_increment=0.01))
        button.set_digits(2)
        button.set_value(val)
        button.connect("value-changed", self.update_frame_position, prop)

        popup = Gtk.Dialog(title = _("Adjust alignment of slides in projector screen"), transient_for = self.p_win)
        popup.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK)

        box = popup.get_content_area()
        box.add(button)
        popup.show_all()
        response = popup.run()
        popup.destroy()

        # revert if we cancelled
        if response == Gtk.ResponseType.CANCEL:
            self.c_frame.set_property(prop, val)
        else:
            self.config.set('content', prop, str(button.get_value())) 
Example #27
Source File: path.py    From gtg with GNU General Public License v3.0 5 votes vote down vote up
def on_button_clicked(self, sender):
        """Shows the filesystem explorer to choose a new file

        @param sender: not used, only here for signal compatibility
        """
        self.chooser = Gtk.FileChooserDialog(
            title=None,
            action=Gtk.FileChooserAction.SAVE,
            buttons=(Gtk.STOCK_CANCEL,
                     Gtk.ResponseType.CANCEL,
                     Gtk.STOCK_OK,
                     Gtk.ResponseType.OK))
        self.chooser.set_default_response(Gtk.ResponseType.OK)
        # set default file as the current self.path
        dirname, basename = os.path.split(self.textbox.get_text())
        self.chooser.set_current_name(basename)
        self.chosser.set_current_folder(dirname)

        # filter files
        afilter = Gtk.FileFilter()
        afilter.set_name("All files")
        afilter.add_pattern("*")
        self.chooser.add_filter(afilter)
        afilter = Gtk.FileFilter()
        afilter.set_name("XML files")
        afilter.add_mime_type("text/plain")
        afilter.add_pattern("*.xml")
        self.chooser.add_filter(afilter)
        response = self.chooser.run()
        if response == Gtk.ResponseType.OK:
            self.textbox.set_text(self.chooser.get_filename())
        self.chooser.destroy() 
Example #28
Source File: color_picker.py    From wpgtk with GNU General Public License v2.0 4 votes vote down vote up
def __init__(self, parent, current_file, gcolor):
        Gtk.Dialog.__init__(self, "Pick a Color", parent, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))

        self.set_default_size(150, 100)
        box = self.get_content_area()
        box.set_border_width(10)
        box.set_spacing(10)

        sat_box = Gtk.Box(spacing=10, orientation=Gtk.Orientation.HORIZONTAL)
        light_box = Gtk.Box(spacing=10, orientation=Gtk.Orientation.HORIZONTAL)

        self.colorchooser = Gtk.ColorChooserWidget(show_editor=True)
        self.colorchooser.set_use_alpha(False)
        self.colorchooser.set_rgba(gcolor)

        r, g, b, _ = list(map(lambda x: round(x*100*2.55), gcolor))
        hue, light, sat = util.rgb_to_hls(r, g, b)

        self.sat_lbl = Gtk.Label('Saturation')
        self.light_lbl = Gtk.Label('Light    ')

        sat_range = Gtk.Adjustment(0, 0, 1, 0.1, 0.1, 0)
        self.sat_slider = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL,
                                    adjustment=sat_range)
        self.sat_slider.set_value(-sat)
        self.sat_slider.set_digits(2)
        self.sat_slider.connect('value-changed', self.slider_changed, 'sat')

        light_range = Gtk.Adjustment(5, 0, 255, 1, 10, 0)
        self.light_slider = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL,
                                      adjustment=light_range)
        self.light_slider.set_value(light)
        self.light_slider.connect('value-changed',
                                  self.slider_changed, 'light')

        box.add(self.colorchooser)

        sat_box.pack_start(self.sat_lbl, True, True, 0)
        sat_box.pack_start(self.sat_slider, True, True, 0)

        light_box.pack_start(self.light_lbl, True, True, 0)
        light_box.pack_start(self.light_slider, True, True, 0)

        box.add(light_box)
        box.add(sat_box)

        self.show_all() 
Example #29
Source File: preferencesdialog.py    From lplayer with MIT License 4 votes vote down vote up
def __init__(self, window):
        #
        Gtk.Dialog.__init__(self, '{0} | {1}'.format(
            comun.APPNAME, _('Preferences')),
            window,
            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_icon_from_file(comun.ICON)

        frame = Gtk.Frame.new('Track options')
        frame.set_margin_top(5)
        frame.set_margin_bottom(5)
        frame.set_margin_left(5)
        frame.set_margin_right(5)
        self.get_content_area().add(frame)

        grid = Gtk.Grid()
        grid.set_margin_top(10)
        grid.set_margin_bottom(10)
        grid.set_margin_left(10)
        grid.set_margin_right(10)
        grid.set_column_spacing(5)
        grid.set_row_spacing(5)
        frame.add(grid)

        label = Gtk.Label('Must I download audio when it just added?')
        label.set_alignment(0, 0.5)
        grid.attach(label, 0, 0, 1, 1)

        self.download_on_added = Gtk.Switch()
        grid.attach(self.download_on_added, 1, 0, 1, 1)

        label = Gtk.Label('Must I remove audio when you listened it?')
        label.set_alignment(0, 0.5)
        grid.attach(label, 0, 1, 1, 1)

        self.remove_on_listened = Gtk.Switch()
        grid.attach(self.remove_on_listened, 1, 1, 1, 1)

        self.load_preferences()

        self.show_all() 
Example #30
Source File: RemarkableWindow.py    From Remarkable with MIT License 4 votes vote down vote up
def save_pdf(self, html):
        chooser = Gtk.FileChooserDialog("Export PDF", None, Gtk.FileChooserAction.SAVE,
                                        (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                         Gtk.STOCK_OK, Gtk.ResponseType.OK))
        self.set_file_chooser_path(chooser)
        pdf_filter = Gtk.FileFilter()
        pdf_filter.add_pattern("*.pdf")
        pdf_filter.set_name("PDF Files")
        chooser.add_filter(pdf_filter)
        chooser.set_do_overwrite_confirmation(True)
        response = chooser.run()
        if response == Gtk.ResponseType.OK:
            file_name = chooser.get_filename()
            if not file_name.endswith(".pdf"):
                file_name += ".pdf"
            try:
                pdfkit.from_string(html, file_name, options= {'quiet': '', 'page-size': 'Letter',
                    'margin-top': '0.75in',
                    'margin-right': '0.75in',
                    'margin-bottom': '0.75in',
                    'margin-left': '0.75in',
                    'encoding': "UTF-8",
                    'javascript-delay' : '550',
                    'no-outline': None})
            except:
                try:
                    # Failed so try with no options
                    pdfkit.from_string(html, file_name)
                except:
                    # Pdf Export failed, show warning message
                    if not self.pdf_error_warning:
                        self.pdf_error_warning = True
                        print("\nRemarkable Error:\tPDF Export Failed!!")

                    pdf_fail_dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR,
                            Gtk.ButtonsType.CANCEL, "PDF EXPORT FAILED")
                    pdf_fail_dialog.format_secondary_text(
                            "File export to PDF was unsuccessful.")
                    pdf_fail_dialog.run()
                    pdf_fail_dialog.destroy()
        elif response == Gtk.ResponseType.CANCEL:
            pass

        chooser.destroy()
        self.window.set_sensitive(True)