mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
util: Break out common function to conditionally set gtk property
This commit is contained in:
parent
28ffe05490
commit
cae9e95f12
@ -22,14 +22,14 @@ import gtk.glade
|
||||
|
||||
import logging
|
||||
|
||||
import virtManager.util as util
|
||||
|
||||
def safe_set_text(self, text):
|
||||
try:
|
||||
# pygtk < 2.10 doesn't support test property
|
||||
self.get_property("text")
|
||||
self.set_property("text", text)
|
||||
except TypeError:
|
||||
# pygtk < 2.10 doesn't support test property
|
||||
if not util.safe_set_prop(self, "text", text):
|
||||
self.set_markup(text)
|
||||
|
||||
|
||||
class vmmErrorDialog (gtk.MessageDialog):
|
||||
def __init__ (self, parent=None, flags=0, typ=gtk.MESSAGE_INFO,
|
||||
buttons=gtk.BUTTONS_NONE, message_format=None,
|
||||
|
@ -261,3 +261,17 @@ def bind_escape_key_close(vmmobj):
|
||||
vmmobj.close()
|
||||
|
||||
vmmobj.topwin.connect("key-press-event", close_on_escape)
|
||||
|
||||
def safe_set_prop(self, prop, value):
|
||||
"""
|
||||
Make sure a gtk property is supported, and set to value
|
||||
|
||||
Return True if property was sucessfully set, False otherwise
|
||||
"""
|
||||
|
||||
try:
|
||||
self.get_property(prop)
|
||||
self.set_property(prop, value)
|
||||
return True
|
||||
except TypeError:
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user