[whiteboard] Port to new FileChooser API
This commit is contained in:
@@ -19,7 +19,8 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gajim import gtkgui_helpers
|
|
||||||
|
from gajim.common import app
|
||||||
try:
|
try:
|
||||||
import gi
|
import gi
|
||||||
gi.require_version('GooCanvas', '2.0')
|
gi.require_version('GooCanvas', '2.0')
|
||||||
@@ -28,7 +29,56 @@ try:
|
|||||||
except:
|
except:
|
||||||
HAS_GOOCANVAS = False
|
HAS_GOOCANVAS = False
|
||||||
from nbxmpp import Node
|
from nbxmpp import Node
|
||||||
from gajim.dialogs import FileChooserDialog
|
|
||||||
|
try:
|
||||||
|
from gajim.filechoosers import NativeFileChooserDialog, Filter
|
||||||
|
|
||||||
|
NEW_FILECHOOSER = True
|
||||||
|
|
||||||
|
class SvgSaveDialog(NativeFileChooserDialog):
|
||||||
|
|
||||||
|
_title = _('Save File as…')
|
||||||
|
_filters = [Filter(_('All files'), '*', False),
|
||||||
|
Filter(_('SVG files'), '*.svg', True)]
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
from gajim.dialogs import FileChooserDialog
|
||||||
|
|
||||||
|
NEW_FILECHOOSER = False
|
||||||
|
|
||||||
|
class SvgChooserDialog(FileChooserDialog):
|
||||||
|
def __init__(self, on_response_ok=None, on_response_cancel=None):
|
||||||
|
'''
|
||||||
|
Choose in which SVG file to store the image
|
||||||
|
'''
|
||||||
|
def on_ok(widget, callback):
|
||||||
|
'''
|
||||||
|
check if file exists and call callback
|
||||||
|
'''
|
||||||
|
path_to_file = self.get_filename()
|
||||||
|
widget.destroy()
|
||||||
|
callback(path_to_file)
|
||||||
|
|
||||||
|
FileChooserDialog.__init__(self,
|
||||||
|
title_text=_('Save Image as...'),
|
||||||
|
action=Gtk.FileChooserAction.SAVE,
|
||||||
|
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE,
|
||||||
|
Gtk.ResponseType.OK),
|
||||||
|
current_folder='',
|
||||||
|
default_response=Gtk.ResponseType.OK,
|
||||||
|
on_response_ok=(on_ok, on_response_ok),
|
||||||
|
on_response_cancel=on_response_cancel)
|
||||||
|
|
||||||
|
filter_ = Gtk.FileFilter()
|
||||||
|
filter_.set_name(_('All files'))
|
||||||
|
filter_.add_pattern('*')
|
||||||
|
self.add_filter(filter_)
|
||||||
|
|
||||||
|
filter_ = Gtk.FileFilter()
|
||||||
|
filter_.set_name(_('SVG Files'))
|
||||||
|
filter_.add_pattern('*.svg')
|
||||||
|
self.add_filter(filter_)
|
||||||
|
self.set_filter(filter_)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
A whiteboard widget made for Gajim.
|
A whiteboard widget made for Gajim.
|
||||||
@@ -109,6 +159,10 @@ class Whiteboard(object):
|
|||||||
self.image.clear_canvas()
|
self.image.clear_canvas()
|
||||||
|
|
||||||
def on_export_button_clicked(self, widget):
|
def on_export_button_clicked(self, widget):
|
||||||
|
if NEW_FILECHOOSER:
|
||||||
|
SvgSaveDialog(self.image.export_svg,
|
||||||
|
transient_for=app.app.get_active_window())
|
||||||
|
else:
|
||||||
SvgChooserDialog(self.image.export_svg)
|
SvgChooserDialog(self.image.export_svg)
|
||||||
|
|
||||||
def on_fg_color_button_color_set(self, widget):
|
def on_fg_color_button_color_set(self, widget):
|
||||||
@@ -247,40 +301,6 @@ class Whiteboard(object):
|
|||||||
|
|
||||||
self.recieving = {}
|
self.recieving = {}
|
||||||
|
|
||||||
class SvgChooserDialog(FileChooserDialog):
|
|
||||||
def __init__(self, on_response_ok=None, on_response_cancel=None):
|
|
||||||
'''
|
|
||||||
Choose in which SVG file to store the image
|
|
||||||
'''
|
|
||||||
def on_ok(widget, callback):
|
|
||||||
'''
|
|
||||||
check if file exists and call callback
|
|
||||||
'''
|
|
||||||
path_to_file = self.get_filename()
|
|
||||||
widget.destroy()
|
|
||||||
callback(path_to_file)
|
|
||||||
|
|
||||||
FileChooserDialog.__init__(self,
|
|
||||||
title_text=_('Save Image as...'),
|
|
||||||
action=Gtk.FileChooserAction.SAVE,
|
|
||||||
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE,
|
|
||||||
Gtk.ResponseType.OK),
|
|
||||||
current_folder='',
|
|
||||||
default_response=Gtk.ResponseType.OK,
|
|
||||||
on_response_ok=(on_ok, on_response_ok),
|
|
||||||
on_response_cancel=on_response_cancel)
|
|
||||||
|
|
||||||
filter_ = Gtk.FileFilter()
|
|
||||||
filter_.set_name(_('All files'))
|
|
||||||
filter_.add_pattern('*')
|
|
||||||
self.add_filter(filter_)
|
|
||||||
|
|
||||||
filter_ = Gtk.FileFilter()
|
|
||||||
filter_.set_name(_('SVG Files'))
|
|
||||||
filter_.add_pattern('*.svg')
|
|
||||||
self.add_filter(filter_)
|
|
||||||
self.set_filter(filter_)
|
|
||||||
|
|
||||||
|
|
||||||
class SVGObject():
|
class SVGObject():
|
||||||
''' A class to store the svg document and make changes to it.'''
|
''' A class to store the svg document and make changes to it.'''
|
||||||
|
|||||||
Reference in New Issue
Block a user