Пример #1
0
    def remove_tag(self, *args):
        result = messagebox.askquestion(
            "Delete Tag",
            "Are you sure you want to delete Tag: {}?".format(
                args[0][0]['label']),
            icon='question')  #call the messagebox to confirm  as a deletion
        if result:  #if confirm is true
            #update json to remove tag
            self.tags = [
                item for item in self.tags
                if item['label'] != args[0][0]['label']
                and item['colour'] != args[0][0]['colour']
            ]

            self.tag_writer = jsonFileReaderWriter(file_locations['tags'],
                                                   "tags")
            # self.tag_writer.create_json_file({"tags": self.tags}) #will overwrite json file with new tag colour or will re-write json file so always replaces tag file. A good way to prevent file not found errors
            self.tag_writer.write_file(self.tags)

            #call again to get updated
            self.tags_writer = TagFileLoader(file_locations['tags'])
            self.tags = self.tags_writer.return_tags()

            self.create_tags_table(self.tags_frame)  #update table

            self.refresh_tags_list(
                'Default Tag')  #refresh the default tags list
            self.value = True  #A tag has been removed so outside tabs will need to be refreshed with the new tags list
Пример #2
0
    def add_tag(self):
        if len(self.tag_entry.get()
               ) > 0:  #if there is text present in the label entry box
            #get tag from label box, (strip removes the whitespace from the edges)
            self.added_tag['label'] = self.tag_entry.get().strip(
            )  #strip the text
            #check that the tag is not already present
            tag_replicated = False  #Using simple boolean pivot to see if tag is replicated
            for tag in self.tags:
                if tag['label'] == self.added_tag['label']:
                    tag_replicated = True
                    self.tag_entry[
                        'highlightthickness'] = 2  #highlight it to show that it needs to be adjusted
                    self.error_msg[
                        'text'] = "Tag Name Already Exists."  #If the tag name already exists then let the user know through error message
                    self.error_msg.grid(row=0,
                                        column=0,
                                        padx=10,
                                        columnspan=2,
                                        sticky="W")

            if not tag_replicated:  #if there is no replicated
                self.tags.append(self.added_tag)  #add new tag

                #add tag to JSON file Does not check contents of file but rather what was loaded in it at the start
                self.tag_writer = jsonFileReaderWriter(file_locations['tags'],
                                                       "tags")
                # self.tag_writer.create_json_file({"tags": self.tags}) #will overwrite json file with new tag colour or will re-write json file so always replaces tag file. A good way to prevent file not found errors
                self.tag_writer.write_file(self.tags)

                #Need to reload as jsonFIleWrtier is only called once in this class, need to show updated
                self.tags_writer = TagFileLoader(file_locations['tags'])
                self.tags = self.tags_writer.return_tags()  #pull tags

                self.clear_tag()  #clear the new tag to be added
                self.create_tags_table(self.tags_frame)  #refresh the table
                self.refresh_tags_list(
                    'Default Tag')  #refresh the default tags list
                self.value = True  #A change has been made & therefore the wider tabs would need to be reset
        else:
            self.tag_entry[
                'highlightthickness'] = 2  #highlight the box in red to alert user, done this instead of warning label
            self.error_msg[
                'text'] = "Tag Name Required."  #update error message if no text added
            self.error_msg.grid(row=0,
                                column=0,
                                padx=10,
                                columnspan=2,
                                sticky="W")
            self.tag_entry.insert(tk.END,
                                  "Add...")  #add in normal placeholder text
            self.tag_entry.bind(
                "<Button-1>",
                lambda e: self.watch_for_txtbx_click(self.tag_entry.get(
                )))  #bind function on the event of clicking the text box
Пример #3
0
 def get_transformation_matrix(self):
     try:
         file_reader = jsonFileReaderWriter(
             self.folder + "/" + self.slice_name + '.json', self.datakey)
         file_contents = file_reader.read_file()
         return file_contents[
             self.
             datakey]  #pass through the matrix using the datakey method
     except:
         print("ERROR, finding Transformation Matrix")
         return None
Пример #4
0
    def __init__(self, filename):
        self.filename = filename
        #defaults for the tags, if file is deleted
        self.defaults = [{
            "label": "Suspicious: PI-RAD 1",
            "colour": "#FF0000"
        }, {
            "label": "Suspicious: PI-RAD 2",
            "colour": "#FF0000"
        }, {
            "label": "Suspicious: PI-RAD 3",
            "colour": "#FF0000"
        }, {
            "label": "Suspicious: PI-RAD 4",
            "colour": "#FF0000"
        }, {
            "label": "Suspicious: PI-RAD 5",
            "colour": "#FF0000"
        }, {
            "label": "Anatomical",
            "colour": "#228B22"
        }, {
            "label": "Other",
            "colour": "#FFFF00"
        }]

        #Load tags file & create if has been deleted
        try:
            self.tag_file_writer = jsonFileReaderWriter(
                self.filename, "tags")  #read the tags file
            self.tags = self.tag_file_writer.read_key_data(
            )  #read the data under key 'tags'

            if len(self.tags) == 0:
                #if no tags then re-input with default tags
                self.tag_file_writer.write_file(self.defaults)
                #file is just default tags currently
                self.tags = self.defaults
                print(
                    "ERROR WITH TAGS FILE, Tags not present. Default tags added."
                )  #Let the user know
            else:
                self.tags = self.check_tags(self.tags)
                print("Tags Present & checked.")  #Let the user know

        except FileNotFoundError:
            print("System cannot find path specified using address: " +
                  self.filename)
Пример #5
0
    def change_tag_colour(self, *args):
        colour = colorchooser.askcolor(
            title="Change Colour: Tag {}".format(args[0][0]['label']),
            color=args[0][0]['colour'])  #setup the colour chooser
        if colour != None:

            #add tag to JSON file - Use jsonFileWriter for this as not checking contents
            for tag in self.tags:
                if (tag['label']
                        == args[0][0]['label']) and (tag['colour']
                                                     == args[0][0]['colour']):
                    tag['colour'] = colour[1]

            self.tag_writer = jsonFileReaderWriter(file_locations['tags'],
                                                   "tags")
            # self.tag_writer.create_json_file({"tags": self.tags}) #will overwrite json file with new tag colour or will re-write json file so always replaces tag file. A good way to prevent file not found errors
            self.tag_writer.write_file(self.tags)

            #call again to get updated
            self.tags_writer = TagFileLoader(file_locations['tags'])
            self.tags = self.tags_writer.return_tags()

            self.create_tags_table(self.tags_frame)  #update table
            self.value = True  #A tag's colour has been changed
Пример #6
0
    def prepare_settings(self):
        #Hardcoded default settings I have provided
        SETTINGS = [{
            "setting": "Precision",
            "category": "polygons",
            "configuable": True,
            "default_value": 2,
            "type": "number",
            "task": "Change Precision"
        }, {
            "setting": "Line Thickness",
            "category": "polygons",
            "configuable": True,
            "default_value": 4,
            "type": "number",
            "task": "Change Line Thickness"
        }, {
            "setting": "Unknown Tag Colour",
            "category": "polygons",
            "configuable": True,
            "default_value": "#FFC0CB",
            "type": "color",
            "task": "Choose Unknown Tag Colour"
        }, {
            "setting": "Selected Polygon Colour",
            "category": "polygons",
            "configuable": True,
            "default_value": "#0000FF",
            "type": "color",
            "task": "Choose Selected Polygon Colour"
        }, {
            "setting": "Selected Vertex Colour",
            "category": "polygons",
            "configuable": True,
            "default_value": "#FFFF00",
            "type": "color",
            "task": "Choose Selected Vertex Colour"
        }, {
            "setting": "Selected Vertex Size",
            "category": "polygons",
            "configuable": True,
            "default_value": 125,
            "type": "number",
            "task": "Choose Selected Vertex Size"
        }, {
            "setting": "Figure Background",
            "category": "polygons",
            "configuable": True,
            "default_value": "#C8C8C8",
            "type": "color",
            "task": "Choose Figure Background Colour"
        }, {
            "setting": "Default Tag",
            "category": "tags",
            "configuable": True,
            "default_value": 0,
            "type": "dropdown",
            "task": "Choose Default Tag"
        }]
        try:
            #Find file
            settings_writer = jsonFileReaderWriter(self.settings_data_filename,
                                                   "settings")  #read the file
            settings_data = settings_writer.read_key_data(
            )  #just reads the data under key settings

            #if there is data in the file
            if len(settings_data) > 0:
                #Compare each value in the settings & ensure that correct data is provided for config & default_value
                i = 0
                for setting in settings_data:
                    try:
                        value = [
                            item['default_value'] for item in settings_data
                            if item['setting'] == SETTINGS[i]['setting']
                        ][0]
                        if (SETTINGS[i]["type"] == "number"):
                            #Ensure that the value is an integer for default value
                            try:
                                value = int(value)
                                SETTINGS[i][
                                    'default_value'] = value  #assign the value if is integer
                            except ValueError:
                                #Keep default value if not integer
                                print(
                                    "ERROR WITH settings.json: " +
                                    SETTINGS[i]['setting'] +
                                    " default value is not a number."
                                )  #I print this to let the user know there is an error upon load
                        if (SETTINGS[i]["type"] == "color"):
                            #Ensure that value is HEX value
                            if HexValidator().validate_value(value):
                                SETTINGS[i][
                                    'default_value'] = value  #assign the value if is validated hex string
                            else:
                                #Keep default value if not colour
                                print("ERROR WITH settings.json: " +
                                      SETTINGS[i]['setting'] +
                                      " default_colour value is not a HEX.")

                        #Get config value for the setting
                        config = [
                            item['configuable'] for item in settings_data
                            if item['setting'] == SETTINGS[i]['setting']
                        ][0]
                        if (config == True or config == False
                            ):  #If the config value is True or False
                            SETTINGS[i][
                                'configuable'] = config  #re-assign value
                        else:
                            print("ERROR WITH settings.json: " +
                                  SETTINGS[i]['setting'] +
                                  " config value is not a Boolean.")
                    except IndexError:
                        #Where the setting is not available. Default value from this list is kept.
                        print("ERROR WITH settings.json: " +
                              SETTINGS[i]['setting'] +
                              " is not present in JSON File.")
                    except KeyError:
                        #Where setting is not called setting or default_value or configuable. Default value is kept.
                        print("ERROR WITH settings.json: " +
                              SETTINGS[i]['setting'] +
                              " is not formatted correctly in JSON File.")
                    i += 1
            else:
                print("ERROR WITH settings.json: " +
                      "No settings found in file. Default settings used.")
                # settings_writer.create_json_file({"settings": SETTINGS}) #append the default settings to the file if nothing there
                settings_writer.write_file(SETTINGS)

        except FileNotFoundError:
            #use default settings above if file not found
            print("ERROR WITH settings.json: " + "Cannot find JSON File")

            #I add these to the settings for temp use when program is live.
            #Current value is changed for when the value is different to default but default is remembered
            #Temp value is the temp value that is chosen by the user when polygon settings is open
        for setting in SETTINGS:
            setting['current_value'] = setting['default_value']
            setting['temp_value'] = None

        #Return the settings for the program
        return SETTINGS