src/modules/gui/searcherror.py
changeset 2991 75e616731cc3
parent 2990 2cc6693a7d83
child 2992 e48a94cff862
equal deleted inserted replaced
2990:2cc6693a7d83 2991:75e616731cc3
     1 #!/usr/bin/python
       
     2 #
       
     3 # CDDL HEADER START
       
     4 #
       
     5 # The contents of this file are subject to the terms of the
       
     6 # Common Development and Distribution License (the "License").
       
     7 # You may not use this file except in compliance with the License.
       
     8 #
       
     9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
    10 # or http://www.opensolaris.org/os/licensing.
       
    11 # See the License for the specific language governing permissions
       
    12 # and limitations under the License.
       
    13 #
       
    14 # When distributing Covered Code, include this CDDL HEADER in each
       
    15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    16 # If applicable, add the following below this CDDL HEADER, with the
       
    17 # fields enclosed by brackets "[]" replaced with your own identifying
       
    18 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    19 #
       
    20 # CDDL HEADER END
       
    21 #
       
    22 # Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
       
    23 # Use is subject to license terms.
       
    24 #
       
    25 
       
    26 import sys
       
    27 try:
       
    28         import pango
       
    29 except ImportError:
       
    30         sys.exit(1)
       
    31 import pkg.gui.misc as gui_misc
       
    32 
       
    33 class SearchError:
       
    34         def __init__(self, builder, gconf, parent):
       
    35                 self.gconf = gconf
       
    36                 self.parent = parent
       
    37                 self.api_search_error_dialog = \
       
    38                     builder.get_object("api_search_error")
       
    39                 self.api_search_error_textview = \
       
    40                     builder.get_object("api_search_error_text")
       
    41                 self.api_search_checkbox = \
       
    42                     builder.get_object("api_search_checkbox")
       
    43                 self.api_search_button = \
       
    44                     builder.get_object("api_search_button")
       
    45                 infobuffer = self.api_search_error_textview.get_buffer()
       
    46                 infobuffer.create_tag("bold", weight=pango.WEIGHT_BOLD)
       
    47                 self.pylintstub = None
       
    48 
       
    49         def setup_signals(self):
       
    50                 signals_table = [
       
    51                     (self.api_search_checkbox, "toggled",
       
    52                      self.__on_api_search_checkbox_toggled),
       
    53                     (self.api_search_button, "clicked",
       
    54                      self.__on_api_search_button_clicked),
       
    55                     (self.api_search_error_dialog, "delete_event",
       
    56                      self.__on_api_search_error_delete_event)
       
    57                     ]
       
    58                 for widget, signal_name, callback in signals_table:
       
    59                         widget.connect(signal_name, callback)
       
    60 
       
    61         def set_modal_and_transient(self, parent_window):
       
    62                 gui_misc.set_modal_and_transient(self.api_search_error_dialog,
       
    63                     parent_window)
       
    64 
       
    65         def __on_api_search_error_delete_event(self, widget, event):
       
    66                 self.__on_api_search_button_clicked(None)
       
    67 
       
    68         def __on_api_search_button_clicked(self, widget):
       
    69                 self.api_search_error_dialog.hide()
       
    70 
       
    71         def __on_api_search_checkbox_toggled(self, widget):
       
    72                 active = self.api_search_checkbox.get_active()
       
    73 
       
    74                 repos = self.parent.get_current_repos_with_search_errors()
       
    75                 if len(repos) > 0:
       
    76                         if active:
       
    77                                 for pub, err_type, err_str in  repos:
       
    78                                         if pub not in self.gconf.not_show_repos:
       
    79                                                 self.gconf.not_show_repos += pub + ","
       
    80                                         self.pylintstub = err_type
       
    81                                         self.pylintstub = err_str
       
    82                         else:
       
    83                                 for pub, err_type, err_str in repos:
       
    84                                         self.gconf.not_show_repos = \
       
    85                                             self.gconf.not_show_repos.replace(
       
    86                                             pub + ",", "")
       
    87                         self.gconf.set_not_show_repos(self.gconf.not_show_repos)
       
    88 
       
    89         def display_search_errors(self, show_all):
       
    90                 repos = self.parent.get_current_repos_with_search_errors()
       
    91                 infobuffer = self.api_search_error_textview.get_buffer()
       
    92                 infobuffer.set_text("")
       
    93                 textiter = infobuffer.get_end_iter()
       
    94                 for pub, err_type, err_str in repos:
       
    95 
       
    96                         if show_all or (pub not in self.gconf.not_show_repos):
       
    97                                 infobuffer.insert_with_tags_by_name(textiter,
       
    98                                     "%(pub)s (%(err_type)s)\n" % {"pub": pub,
       
    99                                     "err_type": err_type}, "bold")
       
   100                                 infobuffer.insert(textiter, "%s\n" % (err_str))
       
   101 
       
   102                 self.api_search_checkbox.set_active(False)
       
   103                 self.api_search_error_dialog.show()
       
   104                 self.api_search_button.grab_focus()
       
   105