コード例 #1
0
ファイル: FileDialogs.py プロジェクト: cosmic-sdr/gr-proto
    def get_rectified_filename(self):
        """
        Run the dialog and get the filename.
        If this is a save dialog and the file name is missing the extension, append the file extension.
        If the file name with the extension already exists, show a overwrite dialog.
        If this is an open dialog, return a list of filenames.

        Returns:
            the complete file path
        """
        if gtk.FileChooserDialog.run(self) != gtk.RESPONSE_OK:
            return None  #response was cancel
        #############################################
        # Handle Save Dialogs
        #############################################
        if self.type in (SAVE_FLOW_GRAPH, SAVE_CONSOLE, SAVE_IMAGE):
            filename = self.get_filename()
            extension = {
                SAVE_FLOW_GRAPH: Preferences.file_extension(),
                SAVE_CONSOLE: TEXT_FILE_EXTENSION,
                SAVE_IMAGE: IMAGE_FILE_EXTENSION,
            }[self.type]
            #append the missing file extension if the filter matches
            if path.splitext(filename)[1].lower() != extension:
                filename += extension
            self.set_current_name(
                path.basename(filename))  #show the filename with extension
            if path.exists(filename):  #ask the user to confirm overwrite
                if MessageDialogHelper(
                        gtk.MESSAGE_QUESTION,
                        gtk.BUTTONS_YES_NO,
                        self.parent,
                        title='Confirm Overwrite!',
                        markup=Utils.parse_template(FILE_OVERWRITE_MARKUP_TMPL,
                                                    filename=filename),
                ) == gtk.RESPONSE_NO:
                    return self.get_rectified_filename()
            return filename
        #############################################
        # Handle Open Dialogs
        #############################################
        elif self.type in (OPEN_FLOW_GRAPH, OPEN_QSS_THEME):
            filenames = self.get_filenames()
            for filename in filenames:
                if not path.exists(filename):  #show a warning and re-run
                    MessageDialogHelper(
                        gtk.MESSAGE_WARNING,
                        gtk.BUTTONS_CLOSE,
                        self.parent,
                        title='Cannot Open!',
                        markup=Utils.parse_template(FILE_DNE_MARKUP_TMPL,
                                                    filename=filename),
                    )
                    return self.get_rectified_filename()
            return filenames
コード例 #2
0
ファイル: MainWindow.py プロジェクト: monikaomsharma/sandhi
    def _save_changes(self):
        """
		Save changes to flow graph?
		@return true if yes
		"""
        return MessageDialogHelper(
            gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, 'Unsaved Changes!',
            'Would you like to save changes before closing?'
        ) == gtk.RESPONSE_YES
コード例 #3
0
    def _save_changes(self):
        """
        Save changes to flow graph?

        Returns:
            the response_id (see buttons variable below)
        """
        buttons = ('Close without saving', gtk.RESPONSE_CLOSE,
                   gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE,
                   gtk.RESPONSE_OK)
        return MessageDialogHelper(
            gtk.MESSAGE_QUESTION, gtk.BUTTONS_NONE, 'Unsaved Changes!',
            'Would you like to save changes before closing?', gtk.RESPONSE_OK,
            buttons)