Example #1
0
    def __init__(self, primary):
        primary_frame = basic_widgets.Frame(primary)
        WidgetPanel.__init__(self, primary_frame)
        self.variables = AppVariables()

        self.init_w_horizontal_layout()
        primary_frame.pack(fill=tkinter.BOTH, expand=tkinter.YES)
        self.button_panel.pack(fill=tkinter.X, expand=tkinter.NO)
        self.pyplot_panel.pack(expand=tkinter.YES)
        self.canvas_demo_image_panel.pack(expand=tkinter.YES)

        # bind events to callbacks here
        self.button_panel.fname_select.config(
            command=self.callback_initialize_canvas_image)
        self.button_panel.rect_select.config(
            command=self.callback_set_to_select)

        self.button_panel.draw_line.config(command=self.callback_draw_line)
        self.button_panel.draw_arrow.config(command=self.callback_draw_arrow)
        self.button_panel.draw_rect.config(command=self.callback_draw_rect)
        self.button_panel.draw_polygon.config(
            command=self.callback_draw_polygon)
        self.button_panel.draw_point.config(command=self.callback_draw_point)
        self.button_panel.edit.config(command=self.callback_edit)
        self.button_panel.color_selector.config(
            command=self.callback_activate_color_selector)
        self.button_panel.remap_dropdown.on_selection(self.callback_remap)

        self.canvas_demo_image_panel.canvas.on_left_mouse_click(
            self.callback_handle_canvas_left_mouse_click)
        self.canvas_demo_image_panel.canvas.on_left_mouse_release(
            self.callback_handle_canvas_left_mouse_release)
Example #2
0
    def init_w_basic_widget_list(self, n_rows, n_widgets_per_row_list):
        """
        This is a convenience method to initialize a basic widget panel.  To use this first make a subclass
        This should also be the primary method to initialize a panel.  Other convenience methods can be made
        to perform the button/widget location initialization, but all of those methods should perform their
        ordering then reference this method to actually perform the initialization.

        Parameters
        ----------
        n_rows : int
        n_widgets_per_row_list : List[int]

        Returns
        -------
        None
        """

        self._rows = [basic_widgets.Frame(self) for i in range(n_rows)]
        for row in self._rows:
            row.config(borderwidth=2)
            row.pack(fill=tkinter.BOTH, expand=tkinter.YES)

        # find transition points
        transitions = np.cumsum(n_widgets_per_row_list)
        row_num = 0
        for i, widget_name in enumerate(self._widget_list):
            widget_descriptor = getattr(self.__class__, widget_name, None)
            if widget_descriptor is None:
                raise ValueError(
                    'widget class {} has no widget named {}'.format(
                        self.__class__.__name__, widget_name))

            if widget_name != widget_descriptor.name:
                raise ValueError(
                    'widget {} of class {} has inconsistent name {}'.format(
                        widget_name, self.__class__.__name__,
                        widget_descriptor.name))

            widget_type = widget_descriptor.the_type

            # check whether things have been instantiated
            current_value = getattr(self, widget_name)
            if current_value is not None:
                current_value.destroy()

            if i in transitions:
                row_num += 1

            widget_text = widget_descriptor.default_text
            widget = widget_type(self._rows[row_num])
            widget.pack(side="left",
                        padx=self.padx,
                        pady=self.pady,
                        fill=tkinter.BOTH,
                        expand=tkinter.YES)
            if hasattr(widget_type, 'set_text') and widget_text is not None:
                widget.set_text(widget_text.replace("_", " "))
            setattr(self, widget_name, widget)
        self.pack(fill=tkinter.BOTH, expand=tkinter.YES)
Example #3
0
    def __init__(self, primary):
        self.primary = primary

        primary_frame = basic_widgets.Frame(primary)
        WidgetPanel.__init__(self, primary_frame)

        self.init_w_horizontal_layout()

        lat = 35.05452800184999
        lon = -106.59258099877832
        collect_start = numpy.datetime64('2016-09-21T16:41:07.000000')
        collect_duration = 14.47132
        collector_name = 'Sandia FARAD X-band'
        core_name = '0508C01_PS0009_CC000000_N03_M1_PC054036_HH_wfcc_sv'
        azimuth = 241.15240495122976
        graze = 28.403774480669846
        layover = 263.96070589564016
        shadow = -90.0
        multipath = 66.5880303387554
        side_of_track = 'R'
        col_impulse_response_width = 0.1903215223097113
        row_impulse_response_width = 0.1606955380577428
        grid_column_sample_spacing = 0.04462
        grid_row_sample_spacing = 0.03767
        image_plane = 'SLANT'
        tx_rf_bandwidth = 2843.7592056795997
        rniirs = None
        polarization = 'H:H'

        data_container = MetaIconDataContainer(lat=lat,
                                               lon=lon,
                                               collect_start=collect_start,
                                               collect_duration=collect_duration,
                                               collector_name=collector_name,
                                               core_name=core_name,
                                               azimuth=azimuth,
                                               graze=graze,
                                               layover=layover,
                                               shadow=shadow,
                                               multipath=multipath,
                                               side_of_track=side_of_track,
                                               col_impulse_response_width=col_impulse_response_width,
                                               row_impulse_response_width=row_impulse_response_width,
                                               grid_column_sample_spacing=grid_column_sample_spacing,
                                               grid_row_sample_spacing=grid_row_sample_spacing,
                                               image_plane=image_plane,
                                               tx_rf_bandwidth=tx_rf_bandwidth,
                                               rniirs=rniirs,
                                               polarization=polarization,
                                               )
        self.metaicon_popup_panel = tkinter.Toplevel(self.primary)
        self.metaicon = MetaIcon(self.metaicon_popup_panel)
        self.metaicon.create_from_metaicon_data_container(data_container)
        # hide the main window so just the metaicon popup is showing
        self.primary.withdraw()

        # quit the program when the user closes the metaicon popup
        self.metaicon_popup_panel.protocol("WM_DELETE_WINDOW", self.primary.quit)
Example #4
0
    def __init__(self, primary):
        """

        Parameters
        ----------
        primary : tkinter.Toplevel|tkinter.Tk
        """

        self.root = primary
        self.primary_frame = basic_widgets.Frame(primary)
        WidgetPanel.__init__(self, self.primary_frame)
        WidgetWithMetadata.__init__(self, primary)
        self.image_panel = ImagePanel(self.primary_frame)  # type: ImagePanel
        self.side_panel = SidePanel(self.primary_frame)  # type: SidePanel
        self.variables = AppVariables()
        self.set_title()

        self.image_panel.pack(side=tkinter.LEFT, fill=tkinter.BOTH, expand=tkinter.TRUE)
        self.side_panel.pack(expand=tkinter.FALSE)
        self.primary_frame.pack(fill=tkinter.BOTH, expand=tkinter.YES)

        # set up event listeners
        self.side_panel.buttons.line_draw.config(command=self.arrow_draw_command)
        self.side_panel.buttons.point_draw.config(command=self.draw_point_command)

        self.image_panel.canvas.variables.state.line_width = self.variables.line_width
        # hide unnecessary tools
        self.image_panel.hide_tools(['shape_drawing', 'select'])
        self.image_panel.hide_shapes()

        # define menus
        menubar = tkinter.Menu()
        # file menu
        filemenu = tkinter.Menu(menubar, tearoff=0)
        filemenu.add_command(label="Open Image", command=self.callback_select_files)
        filemenu.add_command(label="Open Directory", command=self.callback_select_directory)
        filemenu.add_separator()
        filemenu.add_command(label="Exit", command=self.exit)
        # menus for informational popups
        popups_menu = tkinter.Menu(menubar, tearoff=0)
        popups_menu.add_command(label="Metaicon", command=self.metaicon_popup)
        popups_menu.add_command(label="Metaviewer", command=self.metaviewer_popup)
        # ensure menus cascade
        menubar.add_cascade(label="File", menu=filemenu)
        menubar.add_cascade(label="Metadata", menu=popups_menu)

        # handle packing
        primary.config(menu=menubar)

        # bind useful events from our canvas
        self.image_panel.canvas.bind('<<ImageIndexChanged>>', self.callback_index_changed)  # has the effect of refreshing the canvas
        self.image_panel.canvas.bind('<<ShapeCoordsFinalized>>', self.callback_shape_edited)  # has the effect that the shape is finished drawing (i.e. changed)
        self.image_panel.canvas.bind('<<ShapeCoordsEdit>>', self.callback_shape_edited)  # has the effect that the shape is edited
        self.image_panel.canvas.bind('<<ShapeCreate>>', self.callback_shape_create)  # has the effect that a new shape is created
        self.image_panel.canvas.bind('<<ShapeDelete>>', self.callback_shape_delete)  # has the effect that a shape is deleted
Example #5
0
    def __init__(self, primary):
        """

        Parameters
        ----------
        primary : tkinter.Toplevel|tkinter.Tk
        """

        self.root = primary
        self.primary_frame = basic_widgets.Frame(primary)
        WidgetPanel.__init__(self, self.primary_frame)
        WidgetWithMetadata.__init__(self, primary)
        self.variables = AppVariables()

        self.init_w_horizontal_layout()
        self.set_title()

        # define menus
        menubar = tkinter.Menu()
        # file menu
        filemenu = tkinter.Menu(menubar, tearoff=0)
        filemenu.add_command(label="Open Image",
                             command=self.callback_select_files)
        filemenu.add_command(label="Open Directory",
                             command=self.callback_select_directory)
        filemenu.add_separator()
        filemenu.add_command(label="Exit", command=self.exit)
        # menus for informational popups
        popups_menu = tkinter.Menu(menubar, tearoff=0)
        popups_menu.add_command(label="Metaicon", command=self.metaicon_popup)
        popups_menu.add_command(label="Metaviewer",
                                command=self.metaviewer_popup)
        # ensure menus cascade
        menubar.add_cascade(label="File", menu=filemenu)
        menubar.add_cascade(label="Metadata", menu=popups_menu)

        # handle packing
        self.primary_frame.pack(fill=tkinter.BOTH, expand=tkinter.YES)
        primary.config(menu=menubar)

        # hide extraneous tool elements
        self.image_panel.hide_tools('shape_drawing')
        self.image_panel.hide_shapes()

        # bind canvas events for proper functionality
        # this makes for bad performance on a larger image - do not activate
        # self.image_panel.canvas.bind('<<SelectionChanged>>', self.handle_selection_change)
        self.image_panel.canvas.bind('<<SelectionFinalized>>',
                                     self.handle_selection_change)
        self.image_panel.canvas.bind('<<RemapChanged>>',
                                     self.handle_remap_change)
        self.image_panel.canvas.bind('<<ImageIndexChanged>>',
                                     self.handle_image_index_changed)
Example #6
0
    def __init__(self, primary):
        self.root = primary
        self.primary_frame = basic_widgets.Frame(primary)
        self.variables = AppVariables()
        WidgetPanel.__init__(self, self.primary_frame)
        WidgetWithMetadata.__init__(self, primary)

        self.init_w_horizontal_layout()
        self.set_title()

        # define menus
        menubar = tkinter.Menu()
        # file menu
        filemenu = tkinter.Menu(menubar, tearoff=0)
        filemenu.add_command(label="Open Image",
                             command=self.callback_select_files)
        filemenu.add_command(label="Open Directory",
                             command=self.callback_select_directory)
        filemenu.add_separator()
        filemenu.add_command(label="Exit", command=self.exit)
        # menus for informational popups
        popups_menu = tkinter.Menu(menubar, tearoff=0)
        popups_menu.add_command(label="Weight Plots",
                                command=self.create_weights_plot)
        popups_menu.add_command(label="Metaicon", command=self.metaicon_popup)
        popups_menu.add_command(label="Metaviewer",
                                command=self.metaviewer_popup)
        # ensure menus cascade
        menubar.add_cascade(label="File", menu=filemenu)
        menubar.add_cascade(label="Metadata", menu=popups_menu)

        # handle packing
        self.primary_frame.pack(fill=tkinter.BOTH, expand=tkinter.YES)
        primary.config(menu=menubar)

        # hide extraneous tool elements
        self.row_centered_image_panel.hide_tools(['shape_drawing', 'select'])
        self.row_centered_image_panel.hide_shapes()
        self.row_centered_image_panel.hide_select_index()

        self.column_centered_image_panel.hide_tools(
            ['shape_drawing', 'select'])
        self.column_centered_image_panel.hide_shapes()
        self.column_centered_image_panel.hide_select_index()
Example #7
0
    def __init__(self, root):
        """

        Parameters
        ----------
        root : tkinter.Toplevel|tkinter.Tk
        """

        self.root = root
        self.browse_directory = os.path.expanduser('~')
        self._file_name = None
        self.label_schema = LabelSchema()  # type: LabelSchema
        self._new_file = None
        self._unsaved_edits = None

        self.primary = basic_widgets.Frame(root)
        WidgetPanel.__init__(self, self.primary)
        self.init_w_rows()
        # self.init_w_basic_widget_list(7, [2, 2, 2, 2, 2, 2, 1])
        # modify packing so that the viewer gets the extra space
        self.version_label.master.pack(expand=tkinter.FALSE, fill=tkinter.X)
        self.version_date_label.master.pack(expand=tkinter.FALSE,
                                            fill=tkinter.X)
        self.classification_label.master.pack(expand=tkinter.FALSE,
                                              fill=tkinter.X)
        self.confidence_label.master.pack(expand=tkinter.FALSE, fill=tkinter.X)
        self.geometries_label.master.pack(expand=tkinter.FALSE, fill=tkinter.X)
        self.edit_button.master.pack(expand=tkinter.FALSE, fill=tkinter.X)
        self.move_up_button.master.pack(expand=tkinter.FALSE, fill=tkinter.X)
        self.schema_viewer.master.pack(expand=tkinter.TRUE,
                                       side=tkinter.BOTTOM)

        # setup the appearance of labels
        self.version_label.config(relief=tkinter.RIDGE,
                                  justify=tkinter.LEFT,
                                  padding=5)
        self.version_date_label.config(relief=tkinter.RIDGE,
                                       justify=tkinter.LEFT,
                                       padding=5)
        self.classification_label.config(relief=tkinter.RIDGE,
                                         justify=tkinter.LEFT,
                                         padding=5)
        self.confidence_label.config(relief=tkinter.RIDGE,
                                     justify=tkinter.LEFT,
                                     padding=5)
        self.geometries_label.config(relief=tkinter.RIDGE,
                                     justify=tkinter.LEFT,
                                     padding=5)

        # setup the GUI callbacks and appearance of labels
        self.version_entry.config(state='disabled',
                                  validate='focusout',
                                  validatecommand=self._version_entry_validate)
        self.version_date_entry.config(state='disabled')
        self.classification_entry.config(
            state='disabled',
            validate='focusout',
            validatecommand=self._classification_validate)
        self.confidence_entry.config(state='disabled',
                                     validate='focusout',
                                     validatecommand=self._confidence_validate)
        self.geometries_entry.config(state='disabled')
        self.edit_button.config(command=self.edit_entry)
        self.new_button.config(command=self.new_entry)
        self.delete_button.config(command=self.delete_entry)
        self.move_up_button.config(command=self.move_up)
        self.move_down_button.config(command=self.move_down)

        # set up the menu bar
        menu = tkinter.Menu()
        filemenu = tkinter.Menu(menu, tearoff=0)
        filemenu.add_command(label="New Schema", command=self.new_schema)
        filemenu.add_command(label="Open Schema", command=self.open_schema)
        filemenu.add_command(label="Save", command=self.save)
        filemenu.add_separator()
        filemenu.add_command(label="Exit", command=self.exit)
        menu.add_cascade(label="File", menu=filemenu)
        self.primary.pack(expand=tkinter.YES, fill=tkinter.BOTH)
        root.config(menu=menu)
Example #8
0
    def init_w_basic_widget_list(self, n_rows, n_widgets_per_row_list):
        """
        This is a convenience method to initialize a basic widget panel, and
        should also be the primary method to initialize a panel.

        Other convenience methods can be made to perform the button/widget location
        initialization, but all of those methods should perform their ordering,
        then reference this method to actually perform the initialization.

        Parameters
        ----------
        n_rows : int
        n_widgets_per_row_list : List[int]

        Returns
        -------
        None
        """

        if n_rows != len(n_widgets_per_row_list):
            raise ValueError(
                'Argument mismatch for class {}. The number of rows must match the '
                'length of the provided list.'.format(self.__class__))

        self._rows = [basic_widgets.Frame(self) for _ in range(n_rows)]
        for row in self._rows:
            row.config(borderwidth=2)
            row.pack(fill=tkinter.BOTH, expand=tkinter.YES)

        # find transition points
        transitions = numpy.cumsum(n_widgets_per_row_list)
        row_num = 0

        for i, widget_name in enumerate(self._widget_list):
            widget_descriptor = getattr(self.__class__, widget_name, None)

            if widget_descriptor is None:
                raise ValueError(
                    'widget class {} has no widget descriptor named {}. The tk_builder init...() '
                    'methods cannot be used for initialization without the descriptor pattern.'
                    .format(self.__class__.__name__, widget_name))

            if widget_name != widget_descriptor.name:
                raise ValueError(
                    'widget {} of class {} has inconsistent name {}'.format(
                        widget_name, self.__class__.__name__,
                        widget_descriptor.name))

            widget_type = widget_descriptor.the_type

            # check whether things have been instantiated
            current_value = getattr(self, widget_name)
            if current_value is not None:
                current_value.destroy()

            if i in transitions:
                row_num += 1

            try:
                widget_text = widget_descriptor.default_text
            except AttributeError:
                widget_text = None
            widget = widget_type(self._rows[row_num])
            widget.pack(side="left",
                        padx=self.padx,
                        pady=self.pady,
                        fill=tkinter.BOTH,
                        expand=tkinter.YES)
            if hasattr(widget_type, 'set_text') and widget_text is not None:
                widget.set_text(widget_text.replace("_", " "))
            setattr(self, widget_name, widget)
        self.pack(fill=tkinter.BOTH, expand=tkinter.YES)