summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2014-01-26 17:59:09 -0500
committerCole Robinson <crobinso@redhat.com>2014-01-26 18:01:10 -0500
commit2a34b353da1fd9750718605c240b6f3fbd74b0f0 (patch)
treee3977db53293ba7aebdbc60fd76a60c458fff115
parent58d5e0b799e93e9e026aa8e3161302a0344458b8 (diff)
downloadvirt-manager-2a34b353da1fd9750718605c240b6f3fbd74b0f0.tar.gz
uihelpers: Move browse_local to error.py
It doesn't fit any better, but now it's accessible to all UI classes more easily.
-rw-r--r--virtManager/createpool.py5
-rw-r--r--virtManager/details.py14
-rw-r--r--virtManager/engine.py17
-rw-r--r--virtManager/error.py85
-rw-r--r--virtManager/storagebrowse.py5
-rw-r--r--virtManager/uihelpers.py87
6 files changed, 102 insertions, 111 deletions
diff --git a/virtManager/createpool.py b/virtManager/createpool.py
index f98f84e9..67f50176 100644
--- a/virtManager/createpool.py
+++ b/virtManager/createpool.py
@@ -536,6 +536,5 @@ class vmmCreatePool(vmmGObjectUI):
if foldermode:
mode = Gtk.FileChooserAction.SELECT_FOLDER
- return uihelpers.browse_local(self.topwin, dialog_name, self.conn,
- dialog_type=mode,
- start_folder=startfolder)
+ return self.err.browse_local(self.conn, dialog_name,
+ dialog_type=mode, start_folder=startfolder)
diff --git a/virtManager/details.py b/virtManager/details.py
index 5578aa00..bcdfa380 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -1494,14 +1494,12 @@ class vmmDetails(vmmGObjectUI):
now = str(datetime.datetime.now()).split(".")[0].replace(" ", "_")
default = "Screenshot_%s_%s.png" % (self.vm.get_name(), now)
- path = uihelpers.browse_local(
- self.topwin,
- _("Save Virtual Machine Screenshot"),
- self.vm.conn,
- _type=("png", "PNG files"),
- dialog_type=Gtk.FileChooserAction.SAVE,
- browse_reason=self.config.CONFIG_DIR_SCREENSHOT,
- default_name=default)
+ path = self.err.browse_local(
+ self.vm.conn, _("Save Virtual Machine Screenshot"),
+ _type=("png", "PNG files"),
+ dialog_type=Gtk.FileChooserAction.SAVE,
+ browse_reason=self.config.CONFIG_DIR_SCREENSHOT,
+ default_name=default)
if not path:
logging.debug("No screenshot path given, skipping save.")
return
diff --git a/virtManager/engine.py b/virtManager/engine.py
index 3f4498f5..0bd50a6d 100644
--- a/virtManager/engine.py
+++ b/virtManager/engine.py
@@ -33,7 +33,6 @@ import libvirt
from virtinst import util
from virtManager import packageutils
-from virtManager import uihelpers
from virtManager.about import vmmAbout
from virtManager.baseclass import vmmGObject
from virtManager.clone import vmmCloneVM
@@ -908,11 +907,10 @@ class vmmEngine(vmmGObject):
path = None
if not managed:
- path = uihelpers.browse_local(src.topwin,
- _("Save Virtual Machine"),
- conn,
- dialog_type=Gtk.FileChooserAction.SAVE,
- browse_reason=self.config.CONFIG_DIR_SAVE)
+ path = src.err.browse_local(
+ conn, _("Save Virtual Machine"),
+ dialog_type=Gtk.FileChooserAction.SAVE,
+ browse_reason=self.config.CONFIG_DIR_SAVE)
if not path:
return
@@ -956,10 +954,9 @@ class vmmEngine(vmmGObject):
"connections is not yet supported"))
return
- path = uihelpers.browse_local(src.topwin,
- _("Restore Virtual Machine"),
- conn,
- browse_reason=self.config.CONFIG_DIR_RESTORE)
+ path = src.err.browse_local(
+ conn, _("Restore Virtual Machine"),
+ browse_reason=self.config.CONFIG_DIR_RESTORE)
if not path:
return
diff --git a/virtManager/error.py b/virtManager/error.py
index 01779d40..c1186a2d 100644
--- a/virtManager/error.py
+++ b/virtManager/error.py
@@ -203,6 +203,91 @@ class vmmErrorDialog(vmmGObject):
return response
+ def browse_local(self, conn, dialog_name, start_folder=None,
+ _type=None, dialog_type=None,
+ confirm_func=None, browse_reason=None,
+ choose_button=None, default_name=None):
+ """
+ Helper function for launching a filechooser
+
+ @dialog_name: String to use in the title bar of the filechooser.
+ @conn: vmmConnection used by calling class
+ @start_folder: Folder the filechooser is viewing at startup
+ @_type: File extension to filter by (e.g. "iso", "png")
+ @dialog_type: Maps to FileChooserDialog 'action'
+ @confirm_func: Optional callback function if file is chosen.
+ @browse_reason: The vmmConfig.CONFIG_DIR* reason we are browsing.
+ If set, this will override the 'folder' parameter with the gconf
+ value, and store the user chosen path.
+ """
+ import os
+
+ # Initial setup
+ overwrite_confirm = False
+
+ if dialog_type is None:
+ dialog_type = Gtk.FileChooserAction.OPEN
+ if dialog_type == Gtk.FileChooserAction.SAVE:
+ if choose_button is None:
+ choose_button = Gtk.STOCK_SAVE
+ overwrite_confirm = True
+
+ if choose_button is None:
+ choose_button = Gtk.STOCK_OPEN
+
+ fcdialog = Gtk.FileChooserDialog(title=dialog_name,
+ parent=self._parent,
+ action=dialog_type,
+ buttons=(Gtk.STOCK_CANCEL,
+ Gtk.ResponseType.CANCEL,
+ choose_button,
+ Gtk.ResponseType.ACCEPT))
+ fcdialog.set_default_response(Gtk.ResponseType.ACCEPT)
+
+ if default_name:
+ fcdialog.set_current_name(default_name)
+
+ # If confirm is set, warn about a file overwrite
+ if confirm_func:
+ overwrite_confirm = True
+ fcdialog.connect("confirm-overwrite", confirm_func)
+ fcdialog.set_do_overwrite_confirmation(overwrite_confirm)
+
+ # Set file match pattern (ex. *.png)
+ if _type is not None:
+ pattern = _type
+ name = None
+ if type(_type) is tuple:
+ pattern = _type[0]
+ name = _type[1]
+
+ f = Gtk.FileFilter()
+ f.add_pattern("*." + pattern)
+ if name:
+ f.set_name(name)
+ fcdialog.set_filter(f)
+
+ # Set initial dialog folder
+ if browse_reason:
+ start_folder = self.config.get_default_directory(
+ conn, browse_reason)
+
+ if start_folder is not None:
+ if os.access(start_folder, os.R_OK):
+ fcdialog.set_current_folder(start_folder)
+
+ # Run the dialog and parse the response
+ ret = None
+ if fcdialog.run() == Gtk.ResponseType.ACCEPT:
+ ret = fcdialog.get_filename()
+ fcdialog.destroy()
+
+ # Store the chosen directory in gconf if necessary
+ if ret and browse_reason and not ret.startswith("/dev"):
+ self.config.set_default_directory(
+ os.path.dirname(ret), browse_reason)
+ return ret
+
class _errorDialog (Gtk.MessageDialog):
"""
diff --git a/virtManager/storagebrowse.py b/virtManager/storagebrowse.py
index f2fc781a..79e68c3d 100644
--- a/virtManager/storagebrowse.py
+++ b/virtManager/storagebrowse.py
@@ -308,9 +308,8 @@ class vmmStorageBrowser(vmmGObjectUI):
if not self.local_args.get("dialog_name"):
self.local_args["dialog_name"] = None
- filename = uihelpers.browse_local(parent=self.topwin,
- conn=self.conn,
- **self.local_args)
+ filename = self.err.browse_local(
+ self.conn, **self.local_args)
if filename:
self._do_finish(path=filename)
diff --git a/virtManager/uihelpers.py b/virtManager/uihelpers.py
index 5b3df35d..298ae965 100644
--- a/virtManager/uihelpers.py
+++ b/virtManager/uihelpers.py
@@ -823,93 +823,6 @@ def spin_get_helper(widget):
return adj.get_value()
-
-def browse_local(parent, dialog_name, conn, start_folder=None,
- _type=None, dialog_type=None,
- confirm_func=None, browse_reason=None,
- choose_button=None, default_name=None):
- """
- Helper function for launching a filechooser
-
- @param parent: Parent window for the filechooser
- @param dialog_name: String to use in the title bar of the filechooser.
- @param conn: vmmConnection used by calling class
- @param start_folder: Folder the filechooser is viewing at startup
- @param _type: File extension to filter by (e.g. "iso", "png")
- @param dialog_type: Maps to FileChooserDialog 'action'
- @param confirm_func: Optional callback function if file is chosen.
- @param browse_reason: The vmmConfig.CONFIG_DIR* reason we are browsing.
- If set, this will override the 'folder' parameter with the gconf
- value, and store the user chosen path.
-
- """
- # Initial setup
- overwrite_confirm = False
-
- if dialog_type is None:
- dialog_type = Gtk.FileChooserAction.OPEN
- if dialog_type == Gtk.FileChooserAction.SAVE:
- if choose_button is None:
- choose_button = Gtk.STOCK_SAVE
- overwrite_confirm = True
-
- if choose_button is None:
- choose_button = Gtk.STOCK_OPEN
-
- fcdialog = Gtk.FileChooserDialog(title=dialog_name,
- parent=parent,
- action=dialog_type,
- buttons=(Gtk.STOCK_CANCEL,
- Gtk.ResponseType.CANCEL,
- choose_button,
- Gtk.ResponseType.ACCEPT))
- fcdialog.set_default_response(Gtk.ResponseType.ACCEPT)
-
- if default_name:
- fcdialog.set_current_name(default_name)
-
- # If confirm is set, warn about a file overwrite
- if confirm_func:
- overwrite_confirm = True
- fcdialog.connect("confirm-overwrite", confirm_func)
- fcdialog.set_do_overwrite_confirmation(overwrite_confirm)
-
- # Set file match pattern (ex. *.png)
- if _type is not None:
- pattern = _type
- name = None
- if type(_type) is tuple:
- pattern = _type[0]
- name = _type[1]
-
- f = Gtk.FileFilter()
- f.add_pattern("*." + pattern)
- if name:
- f.set_name(name)
- fcdialog.set_filter(f)
-
- # Set initial dialog folder
- if browse_reason:
- start_folder = config.running_config.get_default_directory(conn,
- browse_reason)
-
- if start_folder is not None:
- if os.access(start_folder, os.R_OK):
- fcdialog.set_current_folder(start_folder)
-
- # Run the dialog and parse the response
- ret = None
- if fcdialog.run() == Gtk.ResponseType.ACCEPT:
- ret = fcdialog.get_filename()
- fcdialog.destroy()
-
- # Store the chosen directory in gconf if necessary
- if ret and browse_reason and not ret.startswith("/dev"):
- config.running_config.set_default_directory(os.path.dirname(ret),
- browse_reason)
- return ret
-
-
def get_list_selection(widget):
selection = widget.get_selection()
active = selection.get_selected()