Beispiel #1
0
 def hide_date(self):
     if self._show:
         self._selected_label.destroy()
         self._selected_label = None
         util.stretchy_rows(self, range(7))
         self["height"] = int(self["height"] * 7 / 8)
     self._show = False
Beispiel #2
0
    def update_prediction(self, level=-1, adjust_task=None):
        """Change the plotted prediction.

        :param level: The % of "coverage" to display, or -1 to mean plot all the
          relative risk.
        """
        def make_fig():
            fig = mtp.new_figure((20, 20))
            ax = fig.add_subplot(1, 1, 1)
            prediction = self.model.current_prediction
            if level == -1:
                plot_risk(prediction, ax, adjust_task)
            else:
                plot_coverage(prediction, level, ax, adjust_task)
            ax.set_aspect(1)
            fig.set_tight_layout(True)
            return fig

        if not hasattr(self, "_plot") or self._plot is None:
            frame = ttk.LabelFrame(self, text=_text["graph_name"])
            frame.grid(row=10,
                       column=0,
                       columnspan=2,
                       padx=2,
                       pady=2,
                       sticky=tk.NSEW)
            util.stretchy_rows_cols(frame, [0], [0])
            util.stretchy_rows(self, [10])
            util.stretchy_columns(self, [0, 1])
            self._plot = mtp.CanvasFigure(frame)
            self._plot.grid(padx=2, pady=2, sticky=tk.NSEW)
        self._plot.set_figure_task(make_fig, dpi=50)
Beispiel #3
0
 def __init__(self, parent, model):
     super().__init__(parent)
     self._model = model
     self._show = False
     util.stretchy_columns(self, range(7))
     util.stretchy_rows(self, range(7))
     self._add_widgets()
     self._make_square()
Beispiel #4
0
 def show_date(self):
     if not self._show:
         self._show = True
         self._selected_label = ttk.Label(self, anchor=tk.CENTER)
         self._selected_label.grid(row=7,
                                   column=0,
                                   columnspan=7,
                                   sticky=tk.EW)
         util.stretchy_rows(self, range(8))
         self._update_date()
         self["height"] = int(self["height"] * 8 / 7)
Beispiel #5
0
 def _add_widgets(self):
     frame = ttk.Frame(self)
     frame.grid(row=0, column=0, padx=2, pady=2, sticky=tk.W)
     la = ttk.Label(frame,
                    text=_text["sf"].format(
                        funcs.string_ellipse(self.model.settings_filename,
                                             80)))
     la.grid(row=0, column=0)
     frame = ttk.LabelFrame(self, text=_text["config"])
     frame.grid(row=10, column=0, padx=2, pady=2, sticky=tk.NSEW)
     self._add_config_box(frame)
     frame = ttk.LabelFrame(self, text=_text["info"])
     frame.grid(row=11, column=0, padx=2, pady=2, sticky=tk.NSEW)
     tooltips.ToolTipYellow(frame, _text["info_tt"])
     util.stretchy_rows(frame, [0])
     self._add_info_box(frame)
     frame = ttk.Frame(self)
     frame.grid(row=20, column=0, padx=2, pady=2, sticky=tk.EW)
     util.stretchy_columns(frame, [0, 1])
     b = ttk.Button(frame, text=_text["okay"], command=self._okay)
     b.grid(row=0, column=0, padx=2, pady=2, sticky=tk.NSEW)
     b = ttk.Button(frame, text=_text["cancel"], command=self._cancel)
     b.grid(row=0, column=1, padx=2, pady=2, sticky=tk.NSEW)
Beispiel #6
0
        date = self._source()
        self._dp_widget.date_picker.selected_date = date
        self._dp_widget.date_picker.month_year = (date.month, date.year)
        self._dp_widget.date_picker.command = self._cmd
        self._parent.wait_window(self._dp_widget)
        if self._date is not None:
            self._sink(self._date)
        # Seems that I need to do this to stop the keyboard focus being lost
        # forever to the now hidden top window!
        self._widget.focus_force()


if __name__ == "__main__":
    root = tk.Tk()
    util.stretchy_columns(root, [0])
    util.stretchy_rows(root, [0])
    dp = DatePicker(root)
    dp.widget["borderwidth"] = 5
    dp.widget["relief"] = "groove"
    dp.widget.grid(sticky=tk.NSEW)
    frame = tk.Frame(root)
    frame.grid()

    def sunday():
        dp.first_day_of_week = "Sun"

    def monday():
        dp.first_day_of_week = "Mon"

    def go_month():
        dp.month_year = (1, 2016)