def new_query_page(self, parent, tab_name=None, query_id=None):
        # Start the busy routine to indicate to the users something is happening

        self.parent.parent.busyCursor = "watch"
        self.parent.parent.busyWidgets = [
            self.parent.parent.pane2.pane("EditPaneTop"),
            self.parent.parent.pane2.pane("EditPaneBottom"),
            self.parent.parent.pane2.pane("EditPaneStatus"),
            self.parent.parent.pane.pane("ControlPane"),
        ]
        pub_busy.busyStart(self.parent.parent)

        try:
            properties = {}
            projectName = self.parent.query_fields["project"].get()  # Must have projectName
            handler = getHandlerByName(projectName, None, self.Session)
            tabcolor = Pmw.Color.changebrightness(self.parent.parent, pub_controls.query_tab_color, 0.6)

            # works up to here

            if query_id is None:
                for x in self.parent.query_fields.keys():
                    query_string = self.parent.query_fields[x].get().lstrip()
                    if (query_string == "-Any-") or (len(query_string) == 0):
                        properties[x] = (2, "%")
                    elif query_string != "-Any-":
                        properties[x] = (1, query_string)

                if properties["id"] == (2, "%"):
                    del properties["id"]  # This causes an error because you cannot modify the 'id'

                listProperties = False

                result, headers = queryDatasets(projectName, handler, self.Session, properties)
                # works up to here

                # running this causes it to fail!
                self.new_page(
                    parent,
                    tabName=None,
                    tab_color=tabcolor,
                    page_type="query",
                    query_result=result,
                    list_fields=headers,
                )

            else:
                result, headers = queryDatasets(projectName, handler, self.Session, properties)
                for x in result:
                    query_id_found = False
                    if query_id == x[0][:-1]:
                        self.new_page(
                            parent,
                            tabName=None,
                            tab_color=tabcolor,
                            page_type="query",
                            query_result=[x],
                            list_fields=headers,
                        )
                        query_id_found = True
                        break
                if query_id_found is False:
                    warning("The specified dataset id '%s' was not found.", query_id)

            # fails here

            # Enable the "Data Publication" button
            self.parent.ControlButton3.configure(state="normal")

            datasetNames = []
            for x in result:
                datasetNames.append(x[1])
            dmap, offline_map, extraFields = queryDatasetMap(datasetNames, self.Session, extra_fields=True)
            # Check if offline or not, then set the iteration values for each page

            selected_page = self.parent.parent.main_frame.selected_top_page
            self.parent.parent.hold_offline[selected_page] = offline_map
            self.parent.parent.main_frame.projectName[selected_page] = projectName
            self.parent.parent.main_frame.dmap[selected_page] = dmap
            self.parent.parent.main_frame.extraFields[selected_page] = extraFields
            self.parent.parent.main_frame.datasetMapfile[selected_page] = None
            self.parent.parent.directoryMap[selected_page] = None
            self.parent.parent.main_frame.dirp_firstfile[selected_page] = None
            self.parent.parent.defaultGlobalValues[selected_page] = {}

        except:
            pub_busy.busyEnd(self.parent.parent)  # catch here in order to turn off the busy cursor ganz
            raise
        finally:
            pub_busy.busyEnd(self.parent.parent)
예제 #2
0
    def dataset_page(self, dataset=None, Session=None, handler=None):
        if handler != None:
            try:
                self.parent.canvas.pack_forget()  # Remove the white canvas
            except:
                pass

        self.field_list = {}
        validate = []
        mandatory = []
        options = {}
        values = {}
        #--------------------------------------------------------------------------------
        # Generate a dataset page with dummy fields if no dataset was given
        #--------------------------------------------------------------------------------
        if handler == None:
            return_fields = [
                "Project", "Dataset name", "Model", "Experiment", "Run number",
                "Product", "Format"
            ]
            validate = [1, 2, 3, 4, 1, 2, 3, 4, 1]
            mandatory = [
                True, False, True, False, True, False, True, False, True
            ]
            options = values = {
                "Project": None,
                "Dataset name": None,
                "Model": None,
                "Experiment": None,
                "Run number": None,
                "Product": None,
                "Format": None
            }
        else:
            #--------------------------------------------------------------------------------
            # Retrieve the dataset fields and properties from the queryDataset command
            #--------------------------------------------------------------------------------
            list_fields = getQueryFields(handler)
            properties = {'id': (1, dataset.get_id(Session))}
            for x in list_fields:
                if x is not "id": properties[x] = (2, "%")
            values, return_fields = queryDatasets(dataset.get_project(Session),
                                                  handler, Session, properties)
            for x in return_fields:
                validate.append(handler.getFieldType(x))
                options[x] = handler.getFieldOptions(x)
                mandatory.append(handler.isMandatory(x))

        #--------------------------------------------------------------------------------
        # View the dataset fields in the page
        #--------------------------------------------------------------------------------
        for i in range(len(return_fields)):
            #print " ganz dataset test %s", return_fields[i]
            #print values[0][i]
            value = values[0][i]
            try:
                self.field_list[return_fields[i]] = show_field(
                    self.parent, self.dataset_frame,
                    return_fields[i].capitalize(), options[return_fields[i]],
                    value, mandatory[i], validate[i])
            except:
                field = return_fields[i]
                opts = options[field]
                mand = mandatory[i]
                valid = validate[i]
                error(
                    "Error in show_fields: field=%s, options=%s, value=%s, mandatory=%s, validate=%s"
                    % (field, ` opts `, ` value `, mand, valid))
                error(traceback.format_exc())
                raise

        Pmw.alignlabels(
            self.field_list.values())  # alien the labels for a clean look

        self.dataset_frame.pack(side='left', expand=1, fill='both', pady=2)

        #--------------------------------------------------------------------------------
        # Create and pack the Group to display the message about mandatory fields
        #--------------------------------------------------------------------------------
        txtFont = tkFont.Font(self.parent,
                              family=pub_controls.text_font_type,
                              size=pub_controls.text_font_size,
                              weight=font_weight)
        g = Pmw.Group(self.dataset_sframe.interior(),
                      tag_text='Mandatory Fields',
                      tag_font=txtFont)
        g.pack(fill='x', padx=36)
        cw = Tkinter.Label(
            g.interior(),
            text=
            'All fields that begin with an asterisk\n"*" and in blue, must have an entry.',
            font=txtFont)
        cw.pack(padx=2, pady=2, expand='yes', fill='both')
예제 #3
0
   def dataset_page( self, dataset = None, Session = None, handler = None ):
        if handler != None:
           try: self.parent.canvas.pack_forget()  # Remove the white canvas
           except: pass

        self.field_list = {}
        validate = []
        mandatory = []
        options = {}
        values = {}
        #--------------------------------------------------------------------------------
        # Generate a dataset page with dummy fields if no dataset was given
        #--------------------------------------------------------------------------------
        if handler == None:
           return_fields = ["Project", "Dataset name", "Model", "Experiment", "Run number", "Product", "Format"]
           validate = [1,2,3,4,1,2,3,4,1]
           mandatory = [True,False,True,False,True,False,True,False,True]
           options = values = {"Project":None, "Dataset name":None, "Model":None, "Experiment":None, "Run number":None, "Product":None, "Format":None}
        else:
           #--------------------------------------------------------------------------------
           # Retrieve the dataset fields and properties from the queryDataset command
           #--------------------------------------------------------------------------------
           list_fields = getQueryFields( handler )
           properties = {'id':(1, dataset.get_id( Session ))}
           for x in list_fields:
               if x is not "id": properties[ x ] = (2, "%")
           values, return_fields = queryDatasets(dataset.get_project( Session ), handler, Session, properties)
           for x in return_fields:
                validate.append( handler.getFieldType( x ) )
                options[ x ] = handler.getFieldOptions( x )
                mandatory.append( handler.isMandatory( x ) )

        #--------------------------------------------------------------------------------
        # View the dataset fields in the page
        #--------------------------------------------------------------------------------
        for i in range(len(return_fields)):
            #print " ganz dataset test %s", return_fields[i]
            #print values[0][i]
            value = values[0][i]
            try:
                self.field_list[return_fields[i]] = show_field( self.parent, self.dataset_frame, return_fields[i].capitalize(), options[ return_fields[i] ], value, mandatory[i], validate[i] )
            except:
                field = return_fields[i]
                opts = options[field]
                mand = mandatory[i]
                valid = validate[i]
                error("Error in show_fields: field=%s, options=%s, value=%s, mandatory=%s, validate=%s"%(field, `opts`, `value`, mand, valid))
                error(traceback.format_exc())
                raise

        Pmw.alignlabels (self.field_list.values()) # alien the labels for a clean look

        self.dataset_frame.pack(side = 'left', expand=1, fill='both' , pady = 2)

        #--------------------------------------------------------------------------------
        # Create and pack the Group to display the message about mandatory fields
        #--------------------------------------------------------------------------------
        txtFont=tkFont.Font(self.parent, family = pub_controls.text_font_type, size=pub_controls.text_font_size, weight=font_weight)
	g = Pmw.Group(self.dataset_sframe.interior(),
                      tag_text='Mandatory Fields',
                      tag_font=txtFont
                     )
	g.pack(fill = 'x', padx = 36)
	cw = Tkinter.Label(g.interior(),
		text = 'All fields that begin with an asterisk\n"*" and in blue, must have an entry.',
                font = txtFont
             )
	cw.pack(padx = 2, pady = 2, expand='yes', fill='both')