Esempio n. 1
0
    def test_PctSpinBox_get_probability_sets_to_max_or_min(self):
        box = PctSpinBox()
        box.insert(0, '500')
        self.assertEqual(box.get_probability(), 1.0)
        self.assertEqual(box.get(), '100')

        box.delete(0, tk.END)
        self.assertEqual(box.get_probability(), 0.0)
        self.assertEqual(box.get(), '0')
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        super(ErrorDetails, self).__init__(*args, **kwargs)

        error_probability = tk.Frame(master=self)

        default_size = Font(font='TkDefaultFont').cget('size')
        tk.Label(master=error_probability,
                 text='% chance for error: ',
                 font=(None, default_size + 2)).pack(side=tk.LEFT)

        self.error_probability = PctSpinBox(master=error_probability,
                                            width=INTBOX_WIDTH)
        self.error_probability.pack(side=tk.LEFT)

        self.noun_errors = tk.IntVar()
        self.pronoun_errors = tk.IntVar()
        self.verb_errors = tk.IntVar()
        self.is_do_errors = tk.IntVar()
        self.preposition_transpose_errors = tk.IntVar()
        self.punctuation_errors = tk.IntVar()
        self.select_all = tk.IntVar()

        error_probability.pack(padx=10, pady=10)
        tk.Label(master=self,
                 text='select types of errors\n-------------').pack()
        tk.Checkbutton(master=self,
                       text='select/de-select all',
                       variable=self.select_all,
                       command=self._toggle_all).pack(anchor=tk.W)
        tk.Checkbutton(master=self,
                       text='noun errors',
                       variable=self.noun_errors).pack(anchor=tk.W, padx=15)
        tk.Checkbutton(master=self,
                       text='pronoun errors',
                       variable=self.pronoun_errors).pack(anchor=tk.W, padx=15)
        tk.Checkbutton(master=self,
                       text='verb errors',
                       variable=self.verb_errors).pack(anchor=tk.W, padx=15)
        tk.Checkbutton(master=self,
                       text='is do errors',
                       variable=self.is_do_errors).pack(anchor=tk.W, padx=15)
        tk.Checkbutton(master=self,
                       text='transpose preposition errors',
                       variable=self.preposition_transpose_errors).pack(
                           anchor=tk.W, padx=15)
        tk.Checkbutton(master=self,
                       text='period errors',
                       variable=self.punctuation_errors).pack(anchor=tk.W,
                                                              padx=15)
Esempio n. 3
0
class GrammarDetails(SetVariablesFrame):

    def __init__(self, *args, **kwargs):
        super(GrammarDetails, self).__init__(*args, **kwargs)

        self.probability_plural_noun = PctSpinBox(master=self, width=INTBOX_WIDTH)
        self.probability_negative_verb = PctSpinBox(master=self, width=INTBOX_WIDTH)
        self.probability_pronoun = PctSpinBox(master=self, width=INTBOX_WIDTH)
        plu_label = tk.Label(master=self, text='% chance of plural noun')
        neg_label = tk.Label(master=self, text='% chance of negative verb')
        pro_label = tk.Label(master=self, text='% chance of pronoun')

        self.tense = tk.StringVar()
        self._init_radio_button()

        plu_label.grid(row=0)
        self.probability_plural_noun.grid(row=0, column=1)
        neg_label.grid(row=1)
        self.probability_negative_verb.grid(row=1, column=1)
        pro_label.grid(row=2)
        self.probability_pronoun.grid(row=2, column=1)

    def _init_radio_button(self):
        self.tense.set('simple_present')
        radio_button_frame = tk.Frame(master=self, borderwidth=10, relief=tk.GROOVE)
        tk.Label(master=radio_button_frame, text='choose a tense').pack(anchor=tk.W)
        button_choices = [('simple present', 'simple_present'), ('simple past', 'simple_past')]
        for text, value in button_choices:
            b = tk.Radiobutton(master=radio_button_frame, text=text,
                               variable=self.tense, value=value)
            b.pack(anchor=tk.W)
        radio_button_frame.grid(rowspan=len(button_choices) + 1, column=2, padx=10)

    def get_values(self):
        """
        :keys:
            - tense
            - probability_plural_noun
            - probability_negative_verb
            - probability_pronoun
        """
        return {
            'tense': self.tense.get(),
            'probability_plural_noun': self.probability_plural_noun.get_probability(),
            'probability_negative_verb': self.probability_negative_verb.get_probability(),
            'probability_pronoun': self.probability_pronoun.get_probability()
        }
Esempio n. 4
0
    def test_SetVariableFrame_set_variable_WTF_edge_case_bool_is_int_and_Tk_evaluates_to_zero(
            self):
        frame = SetVariablesFrame()
        frame.int = IntSpinBox(range_=(0, 10))
        frame.pct = PctSpinBox()

        frame.set_variable('int', True)
        self.assertEqual(frame.int.get_int(), 0)

        frame.set_variable('pct', True)
        self.assertEqual(frame.pct.get_probability(), 0.0)
Esempio n. 5
0
    def test_SetVariableFrame_unanticipated_value_raises_error(self):
        frame = SetVariablesFrame()
        frame.pct = PctSpinBox()
        frame.int_box = IntSpinBox(range_=(2, 5))
        frame.int_var = tk.IntVar()
        frame.str_var = tk.StringVar()

        self.assertRaises(ValueError, frame.set_variable, 'pct', '.1')
        self.assertRaises(ValueError, frame.set_variable, 'int_box', 1.0)
        self.assertRaises(ValueError, frame.set_variable, 'int_var', 1.0)
        self.assertRaises(ValueError, frame.set_variable, 'str_var', True)
Esempio n. 6
0
    def __init__(self, *args, **kwargs):
        super(GrammarDetails, self).__init__(*args, **kwargs)

        self.probability_plural_noun = PctSpinBox(master=self, width=INTBOX_WIDTH)
        self.probability_negative_verb = PctSpinBox(master=self, width=INTBOX_WIDTH)
        self.probability_pronoun = PctSpinBox(master=self, width=INTBOX_WIDTH)
        plu_label = tk.Label(master=self, text='% chance of plural noun')
        neg_label = tk.Label(master=self, text='% chance of negative verb')
        pro_label = tk.Label(master=self, text='% chance of pronoun')

        self.tense = tk.StringVar()
        self._init_radio_button()

        plu_label.grid(row=0)
        self.probability_plural_noun.grid(row=0, column=1)
        neg_label.grid(row=1)
        self.probability_negative_verb.grid(row=1, column=1)
        pro_label.grid(row=2)
        self.probability_pronoun.grid(row=2, column=1)
Esempio n. 7
0
class ErrorDetails(SetVariablesFrame):
    def __init__(self, *args, **kwargs):
        super(ErrorDetails, self).__init__(*args, **kwargs)

        error_probability = tk.Frame(master=self)

        default_size = Font(font='TkDefaultFont').cget('size')
        tk.Label(master=error_probability,
                 text='% chance for error: ',
                 font=(None, default_size + 2)).pack(side=tk.LEFT)

        self.error_probability = PctSpinBox(master=error_probability,
                                            width=INTBOX_WIDTH)
        self.error_probability.pack(side=tk.LEFT)

        self.noun_errors = tk.IntVar()
        self.pronoun_errors = tk.IntVar()
        self.verb_errors = tk.IntVar()
        self.is_do_errors = tk.IntVar()
        self.preposition_transpose_errors = tk.IntVar()
        self.punctuation_errors = tk.IntVar()
        self.select_all = tk.IntVar()

        error_probability.pack(padx=10, pady=10)
        tk.Label(master=self,
                 text='select types of errors\n-------------').pack()
        tk.Checkbutton(master=self,
                       text='select/de-select all',
                       variable=self.select_all,
                       command=self._toggle_all).pack(anchor=tk.W)
        tk.Checkbutton(master=self,
                       text='noun errors',
                       variable=self.noun_errors).pack(anchor=tk.W, padx=15)
        tk.Checkbutton(master=self,
                       text='pronoun errors',
                       variable=self.pronoun_errors).pack(anchor=tk.W, padx=15)
        tk.Checkbutton(master=self,
                       text='verb errors',
                       variable=self.verb_errors).pack(anchor=tk.W, padx=15)
        tk.Checkbutton(master=self,
                       text='is do errors',
                       variable=self.is_do_errors).pack(anchor=tk.W, padx=15)
        tk.Checkbutton(master=self,
                       text='transpose preposition errors',
                       variable=self.preposition_transpose_errors).pack(
                           anchor=tk.W, padx=15)
        tk.Checkbutton(master=self,
                       text='period errors',
                       variable=self.punctuation_errors).pack(anchor=tk.W,
                                                              padx=15)

    def _toggle_all(self):
        all_state = self.select_all.get()
        for intvar in [
                self.noun_errors, self.pronoun_errors, self.verb_errors,
                self.is_do_errors, self.preposition_transpose_errors,
                self.punctuation_errors
        ]:
            intvar.set(all_state)

    def get_values(self):
        """
        :keys:
            - error_probability
            - noun_errors
            - pronoun_errors
            - verb_errors
            - is_do_errors
            - preposition_transpose_errors
            - punctuation_errors
        """
        return {
            'error_probability':
            self.error_probability.get_probability(),
            'noun_errors':
            bool(self.noun_errors.get()),
            'pronoun_errors':
            bool(self.pronoun_errors.get()),
            'verb_errors':
            bool(self.verb_errors.get()),
            'is_do_errors':
            bool(self.is_do_errors.get()),
            'preposition_transpose_errors':
            bool(self.preposition_transpose_errors.get()),
            'punctuation_errors':
            bool(self.punctuation_errors.get())
        }
Esempio n. 8
0
 def test_SetVariableFrame_set_variable_EDGE_CASE_pct_spin_box_set_int(
         self):
     frame = SetVariablesFrame()
     frame.pct = PctSpinBox()
     frame.set_variable('pct', 5)
     self.assertEqual(frame.pct.get_probability(), 0.05)
Esempio n. 9
0
 def test_SetVariableFrame_PctSpinBox_and_int(self):
     frame = SetVariablesFrame()
     frame.pct = PctSpinBox()
     frame.set_variable('pct', 2)
     self.assertEqual(frame.pct.get_probability(), 0.02)
Esempio n. 10
0
    def test_PctSpinBox_set_probability(self):
        box = PctSpinBox()
        box.set_probability(0.22)
        self.assertEqual(box.get_probability(), 0.22)
        self.assertEqual(box.get(), '22')

        box.set_probability(1.1)
        self.assertEqual(box.get_probability(), 1.0)

        box.set_probability(-0.2)
        self.assertEqual(box.get_probability(), 0.0)
Esempio n. 11
0
 def test_PctSpinBox(self):
     box = PctSpinBox()
     self.assertEqual(box.range, (0, 100))
     box.insert(0, '2')
     self.assertEqual(box.get_int(), 20)
     self.assertEqual(box.get_probability(), 0.2)