# (c) Copyright 2009-2013. CodeWeavers, Inc.
import gobject
gobject.threads_init()
import gtk
import bottlequery
import cxguitools
# for localization
from cxutils import cxgettext as _
_RECREATE_BUTTON = 1
class PluginEditDialog(object):
def __init__(self, bottlename):
self.bottlename = bottlename
# Import widget modules so gtk.Builder() finds them
import cxpluginwidget # pylint: disable=W0612
self.xml = gtk.Builder()
self.xml.set_translation_domain("crossover")
self.xml.add_from_file(cxguitools.get_ui_path("cxpluginedit"))
self.xml.connect_signals(self)
self.dialog = self.xml.get_object('plugin-edit-dialog')
self.edit_widget = self.xml.get_object('plugin-editor')
properties = bottlequery.get_bottle_properties(bottlename)
if properties['managed']:
self.xml.get_object("recreate_button").hide()
self.xml.get_object("apply_button").hide()
self.xml.get_object("cancel_button").hide()
self.xml.get_object("ok_button").hide()
else:
self.xml.get_object("close_button").hide()
self.edit_widget.set_bottle(bottlename, properties['managed'])
self.dialog.set_title(_('Plugins in %(bottlename)s') % {'bottlename':bottlename})
self.edit_widget.refresh(self.refresh_finished, self.refresh_fail)
self.edit_widget.show()
self.dialog.show()
def on_response(self, _dialog, response_id):
if response_id == gtk.RESPONSE_CANCEL:
self.dialog.destroy()
elif response_id == gtk.RESPONSE_APPLY:
self.disable_buttons()
self.edit_widget.commit(self.enable_buttons, self.apply_fail)
elif response_id == gtk.RESPONSE_OK:
self.disable_buttons()
self.edit_widget.commit(self.ok_finished, self.apply_fail)
elif response_id == _RECREATE_BUTTON:
self.disable_buttons()
self.edit_widget.recreate_plugins(self.enable_buttons, self.apply_fail)
def ok_finished(self):
self.dialog.destroy()
def apply_fail(self, error):
self.enable_buttons()
cxguitools.CXMessageDlg(
primary=_("Could not save changes to plugins"),
secondary=error,
parent=self.dialog,
message_type=gtk.MESSAGE_ERROR)
def on_delete(self, _widget, _event):
self.dialog.destroy()
def disable_buttons(self):
self.dialog.set_response_sensitive(_RECREATE_BUTTON, False)
self.dialog.set_response_sensitive(gtk.RESPONSE_CANCEL, False)
self.dialog.set_response_sensitive(gtk.RESPONSE_APPLY, False)
self.dialog.set_response_sensitive(gtk.RESPONSE_OK, False)
def enable_buttons(self):
self.dialog.set_response_sensitive(_RECREATE_BUTTON, True)
self.dialog.set_response_sensitive(gtk.RESPONSE_CANCEL, True)
self.dialog.set_response_sensitive(gtk.RESPONSE_APPLY, True)
self.dialog.set_response_sensitive(gtk.RESPONSE_OK, True)
def refresh_finished(self):
self.enable_buttons()
def quit_message_box(self, _response):
self.dialog.destroy()
def refresh_fail(self, error):
self.dialog.hide()
cxguitools.CXMessageDlg(
primary=_("Could not read plugins for %(bottlename)s") % {'bottlename': self.bottlename},
secondary=error,
parent=self.dialog, response_function=self.quit_message_box,
message_type=gtk.MESSAGE_ERROR)
def quit_requested(self, _caller):
# pylint: disable=R0201
cxguitools.toplevel_quit()
def start(bottle):
PluginEditDialog(bottle.name)