Commit 943e6369 authored by Philipp Hörist's avatar Philipp Hörist

[whiteboard] Port to new FileChooser API

parent b5004a5f
......@@ -19,7 +19,8 @@
##
from gi.repository import Gtk
from gajim import gtkgui_helpers
from gajim.common import app
try:
import gi
gi.require_version('GooCanvas', '2.0')
......@@ -28,7 +29,56 @@ try:
except:
HAS_GOOCANVAS = False
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.
......@@ -109,7 +159,11 @@ class Whiteboard(object):
self.image.clear_canvas()
def on_export_button_clicked(self, widget):
SvgChooserDialog(self.image.export_svg)
if NEW_FILECHOOSER:
SvgSaveDialog(self.image.export_svg,
transient_for=app.app.get_active_window())
else:
SvgChooserDialog(self.image.export_svg)
def on_fg_color_button_color_set(self, widget):
c = self.fg_color_select_button.get_rgba()
......@@ -247,40 +301,6 @@ class Whiteboard(object):
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():
''' A class to store the svg document and make changes to it.'''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment