def open_scratchpad_dialog(self): dialog = gtk.FileChooserDialog(_("Open Scratchpad..."), self.app.drawWindow, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) preview = gtk.Image() dialog.set_preview_widget(preview) dialog.connect("update-preview", self.update_preview_cb, preview) add_filters_to_dialog(self.file_filters, dialog) if self.app.scratchpad_filename: dialog.set_filename(self.app.scratchpad_filename) else: # choose the most recent save folder self.set_recent_items() for item in reversed(self.recent_items): uri = item.get_uri() fn = helpers.uri2filename(uri) dn = os.path.dirname(fn) if os.path.isdir(dn): dialog.set_current_folder(dn) break try: if dialog.run() == gtk.RESPONSE_OK: dialog.hide() self.app.scratchpad_filename = dialog.get_filename().decode('utf-8') self.open_scratchpad(self.app.scratchpad_filename) finally: dialog.destroy()
def open_recent_cb(self, action): """Callback for RecentAction""" if not self.confirm_destructive_action(): return uri = action.get_current_uri() fn = helpers.uri2filename(uri) self.open_file(fn)
def open_scratchpad_dialog(self): dialog = gtk.FileChooserDialog( _("Open Scratchpad..."), self.app.drawWindow, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK), ) dialog.set_default_response(gtk.RESPONSE_OK) preview = gtk.Image() dialog.set_preview_widget(preview) dialog.connect("update-preview", self.update_preview_cb, preview) add_filters_to_dialog(self.file_filters, dialog) if self.app.scratchpad_filename: dialog.set_filename(self.app.scratchpad_filename) else: # choose the most recent save folder self.set_recent_items() for item in reversed(self.recent_items): uri = item.get_uri() fn = helpers.uri2filename(uri) dn = os.path.dirname(fn) if os.path.isdir(dn): dialog.set_current_folder(dn) break try: if dialog.run() == gtk.RESPONSE_OK: dialog.hide() self.app.scratchpad_filename = dialog.get_filename().decode("utf-8") self.open_scratchpad(self.app.scratchpad_filename) finally: dialog.destroy()
def open_last_cb(self, action): """Callback to open the last file""" if not self.recent_items: return if not self.confirm_destructive_action(): return uri = self.recent_items.pop().get_uri() fn = helpers.uri2filename(uri) self.open_file(fn)
def drag_data_received(self, widget, context, x, y, selection, info, t): if info == 1: if selection.data: uri = selection.data.split("\r\n")[0] fn = helpers.uri2filename(uri) if os.path.exists(fn): if self.app.filehandler.confirm_destructive_action(): self.app.filehandler.open_file(fn) elif info == 2: # color color = RGBColor.new_from_drag_data(selection.data) self.app.brush_color_manager.set_color(color) self.app.brush_color_manager.push_history(color)
def set_recent_items(self): # this list is consumed in open_last_cb # Note: i.exists() does not work on Windows if the pathname # contains utf-8 characters. Since GIMP also saves its URIs # with utf-8 characters into this list, I assume this is a # gtk bug. So we use our own test instead of i.exists(). self.recent_items = [ i for i in gtk2compat.gtk.recent_manager_get_default().get_items() if "mypaint" in i.get_applications() and os.path.exists(helpers.uri2filename(i.get_uri())) ] self.recent_items.reverse()
def drag_data_received(self, widget, context, x, y, selection, info, t): if info == 1: if selection.data: uri = selection.data.split("\r\n")[0] fn = helpers.uri2filename(uri) if os.path.exists(fn): if self.app.filehandler.confirm_destructive_action(): self.app.filehandler.open_file(fn) elif info == 2: # color color = [((ord(selection.data[v]) | (ord(selection.data[v+1]) << 8)) / 65535.0) for v in range(0,8,2)] self.app.brush.set_color_rgb(color[:3]) self.app.ch.push_color(self.app.brush.get_color_hsv())
def _drag_data_received_cb(self, widget, context, x, y, data, info, time): """Handles data being received""" rawdata = data.get_data() if not rawdata: return if info == 1: # file uris uri = rawdata.split("\r\n")[0] fn = helpers.uri2filename(uri) if os.path.exists(fn): if self.app.filehandler.confirm_destructive_action(): self.app.filehandler.open_file(fn) elif info == 2: # color color = RGBColor.new_from_drag_data(rawdata) self.app.brush_color_manager.set_color(color) self.app.brush_color_manager.push_history(color)
def save_as_cb(self, action): start_in_folder = None if self.filename: current_filename = self.filename else: current_filename = "" # choose the most recent save folder self.set_recent_items() for item in reversed(self.recent_items): uri = item.get_uri() fn = helpers.uri2filename(uri) dn = os.path.dirname(fn) if os.path.isdir(dn): start_in_folder = dn break if action.get_name() == "Export": # Do not change working file self.save_as_dialog(self.save_file, suggested_filename=current_filename, export=True) else: self.save_as_dialog(self.save_file, suggested_filename=current_filename)
def save_as_cb(self, action): start_in_folder = None if self.filename: current_filename = self.filename else: current_filename = '' # choose the most recent save folder self.set_recent_items() for item in reversed(self.recent_items): uri = item.get_uri() fn = helpers.uri2filename(uri) dn = os.path.dirname(fn) if os.path.isdir(dn): start_in_folder = dn break if action.get_name() == 'Export': # Do not change working file self.save_as_dialog(self.save_file, suggested_filename = current_filename, export=True) else: self.save_as_dialog(self.save_file, suggested_filename = current_filename)
def save_as_cb(self, action): if not self.save_dialog: self.init_save_dialog() dialog = self.save_dialog if self.filename: dialog_set_filename(dialog, self.filename) else: dialog_set_filename(dialog, '') # choose the most recent save folder self.set_recent_items() for item in reversed(self.recent_items): uri = item.get_uri() fn = helpers.uri2filename(uri) dn = os.path.dirname(fn) if os.path.isdir(dn): dialog.set_current_folder(dn) break try: # Loop until we have filename with an extension while dialog.run() == gtk.RESPONSE_OK: filename = dialog.get_filename().decode('utf-8') name, ext = os.path.splitext(filename) saveformat = self.saveformat_combo.get_active() # If no explicitly selected format, use the extension to figure it out if saveformat == SAVE_FORMAT_ANY: cfg = self.app.preferences['saving.default_format'] default_saveformat = self.config2saveformat[cfg] if ext: try: saveformat = self.ext2saveformat[ext] except KeyError: saveformat = default_saveformat else: saveformat = default_saveformat desc, ext_format, options = self.saveformats[saveformat] # if ext: if ext_format != ext: # Minor ugliness: if the user types '.png' but # leaves the default .ora filter selected, we # use the default options instead of those # above. However, they are the same at the moment. options = {} assert(filename) dialog.hide() if action.get_name() == 'Export': # Do not change working file self.save_file(filename, True, **options) else: self.save_file(filename, **options) break filename = name + ext_format # trigger overwrite confirmation for the modified filename dialog_set_filename(dialog, filename) dialog.response(gtk.RESPONSE_OK) finally: dialog.hide() dialog.destroy() # avoid GTK crash: https://gna.org/bugs/?17902 self.save_dialog = None