Пример #1
0
 def reload(self, *args):
     """Reload the list using the MplusOutput class. Might be used as a callback
        so has variable number of arguments."""
     self.critical = False #recalc
     if not self.filename: return False
     try:
         if os.path.exists(self.filename):
             self.output = MplusOutput(self.filename)
             self.estimates = self.output.get_estimates()
         else:
             sys.stderr.write('Mplus output file not found: %s\n'%self.filename)
             return False
     except Exception, e:
         sys.stderr.write('Could not reload application: %s\n'%str(e))
         self.filename = ''# Undo filename setting
         #filechooser.set_filename(None) # How to do this
         return False
Пример #2
0
class JruleGTK:
    """Graphical user interface for the MplusOutput class using 
       GTK+ and Glade."""

    def __init__(self):
        # Session vars, TODO: get from ini file
        self.filename = '' # The file to be read
        self.last_directory = 'test/'

        self.critical = False # just a caching var, False triggers calculations
        self.plot = EmptyThing() # A hack to fool .reload()

        # Set the Glade file
        self.gladefile = "JruleMplus.glade"  
        self.tree = gtk.glade.XML(self.gladefile) 

        # Get various widgets necessary later
        self.window = self.tree.get_widget("main_window")
        self.aboutbox = self.tree.get_widget("about")
        self.statusbar = self.tree.get_widget("statusbar")
        self.alpha_entry = self.tree.get_widget("alpha_entry")
        self.power_entry = self.tree.get_widget("power_entry")
        self.delta_entry = self.tree.get_widget("delta_entry")
        self.filechooser = FileChooser(self) # see FileChooser class below
        self.treeview = TreeView(self) # see ItemList class below
        self.messager = Messager(self) 
        self.combo_parameter = ComboBox('combo_parameter', self, ['BY', 'ON', 'WITH'])
        self.combo_group = ComboBox('combo_group', self, []) # TODO: fill in
        self.combo_decision = ComboBox('combo_decision', self, ['Misspecified', 
            'Not misspecified', 'Check EPC', 'Not enough information'])
        
        self.update_status() # show current file in status bar
        
        self.treecolors = {'Inconclusive': '#dee3e3',
            'Misspecified': '#e38f8f',
            'Not misspecified': '#6be05f',
            'Misspecified (EPC >= delta)': '#e3b3b3',
            'Not misspecified (EPC < delta)' : '#a8e8a1',
        } # default colors to give the background of the treeview
        self.use_colors = True # Whether to color bg of treeview

        # connect widget signals to class functions
        self.window.connect("destroy", gtk.main_quit)

        dic = { "on_window_destroy" : gtk.main_quit,
                "on_quit_mi_activate" :gtk.main_quit,
                "on_about_mi_activate" : self.show_about,
                "on_filechooser_file_set" : self.set_file,
                "on_open_mi_activate" : self.set_file_from_menu,
                "on_about_response" : self.about_response,
                "on_delta_entry_changed" : self.reload, # on out of tab
                "on_save" : self.save_tree,
                "on_print" : self.print_tree,
        }
        self.tree.signal_autoconnect(dic) 
        self.window.show()
        self.reload() # fill the tree if there is a file
        self.plot = JPlot(self)

    def reset_filter(self):
        "Reset the application wide filter on parameters"
        self.filtered_parameters = range(len(self.parameters))
        self.already_filtered = []

    def get_parameters(self):
        "Get the parameters from the indices"
        return [self.parameters[ind] for ind in self.filtered_parameters]

    def filter_param(self, index):
        "Filter out parameter with <index>. Assumes reset filter has been called"
        if not index in self.already_filtered:
            self.already_filtered.append(index)
            self.filtered_parameters.remove(index)

    def jpaste(self, number):
        """Utility function to write a floating point number to text.
           Currently not yet in use."""
        return eval("\%1." + self.digits + "f") % float(number)

    def set_file_from_menu(self, menuitem):
        '''What happens if user selects Open from menu'''
        self.set_file(None, filename = self.filechooser.ask())

    def set_file(self, filechooser=None, filename=''):
        """Given the user's choice of file, save this data and reload the list."""
        if filechooser: self.filename = filechooser.get_filename()
        elif filename: self.filename = filename
        else: sys.stderr.write('[108] An error occurred trying to open the file.\n')
        sys.stderr.write("File chosen is %s.\n" % self.filename)
        self.update_status()
        if not self.reload():
            self.messager.display_message('A problem occurred trying to read ' + 
                '%s as an Mplus output file.' % self.filename +
                ' Please make sure you have selected the right file.')

    def reload(self, *args):
        """Reload the list using the MplusOutput class. Might be used as a callback
           so has variable number of arguments."""
        self.critical = False #recalc
        if not self.filename: return False
        try:
            if os.path.exists(self.filename):
                self.output = MplusOutput(self.filename)
                self.estimates = self.output.get_estimates()
            else:
                sys.stderr.write('Mplus output file not found: %s\n'%self.filename)
                return False
        except Exception, e:
            sys.stderr.write('Could not reload application: %s\n'%str(e))
            self.filename = ''# Undo filename setting
            #filechooser.set_filename(None) # How to do this
            return False
        # If all went well, put the items found into the treeview
        self.treeview.populate_tree()
        if self.plot: self.plot.reload()
        return True