def __init__(self, bt1_text, bt1_funct, bt2_text, bt2_funct): if Validator.is_type([bt1_text, bt2_text], str) and Validator.is_function([bt1_funct, bt2_funct]): super().__init__() self.title(var.TITLE_TEXT) self.title_frame = widgets.Frame(self, row=1, padx=var.BORDER, pady=var.BORDER) self.title_label = widgets.Title(self.title_frame, var.TITLE_TEXT) self.info_frame = widgets.Frame(self, row=3, padx=var.BORDER, pady=var.BORDER) self.info_label = widgets.Label(self.info_frame, "") self.bot_frame = widgets.Frame(self, row=4, sticky="ew", padx=var.BORDER, pady=var.BORDER) self.bot_frame.grid_columnconfigure(0, weight=1) self.bot_frame.grid_columnconfigure(2, weight=1) self.left_button_frame = widgets.Frame(self.bot_frame, row=0, column=0, sticky="w") self.right_button_frame = widgets.Frame(self.bot_frame, row=0, column=2, sticky="e") self.left_button = widgets.Button(self.left_button_frame, bt1_text, bt1_funct) self.right_button = widgets.Button(self.right_button_frame, bt2_text, bt2_funct) self.protocol("WM_DELETE_WINDOW", self._on_destroy) self.resizable(False, False) else: raise InappropriateArgsError("a main template!")
def __init__(self, parent, text, action, **kwargs): if (Validator.is_type(parent, tkinter.Tk) or Validator.is_type(parent, Frame)) \ and Validator.is_type(text, str) and Validator.is_function(action): super().__init__(master=parent, text=text, command=action, width=12) self.config(bg=var.BUTTON_BACKGROUND, fg=var.BUTTON_TEXTCOLOR) self.grid(kwargs) else: raise InappropriateArgsError("creating a button!")
def __init__(self, bt_text, bt_funct, field_numbers, loaded_from, readonly=False, detected=None): """ creates a template with Sudoku field. :param bt_text: text of the button :param bt_funct: function of the button :param field_numbers: numbers that are in the field... 2d array with 9 elements each """ if Validator.is_type(bt_text, str) and Validator.is_function(bt_funct) and \ Validator.is_type(readonly, bool) and Validator.is_9x9_integers_field(field_numbers): tkinter._default_root = self super().__init__("Go Back", self._go_back, bt_text, bt_funct) self.content_frame = widgets.Frame(self, row=2, padx=var.BORDER, pady=var.BORDER) self.field_numbers = field_numbers # 2d list of input digits self.readonly = readonly self.loaded_from = loaded_from self.detected = detected # non empty fields (from original field) if self.detected is None: self.detected = [] self.text_edits = self._generate_field() # 2d list of entries self._set_to_screen_center() else: raise InappropriateArgsError("creating a sudoku field template!")
def test_correct_is_function(self): self.assertEqual(Validator.is_function(test), True) self.assertEqual(Validator.is_function([test, test]), True)
def test_incorrect_is_function(self): self.assertEqual(Validator.is_function("Not a function"), False) self.assertEqual(Validator.is_function(3), False) self.assertEqual(Validator.is_function([test, "Nope", "not"]), False)