Пример #1
0
 def test_get_tag_attrs_fromDicts5(self):
     o_d = dict(background='white',
                foreground='blue',
                borderwidth='2',
                relief=tk.SOLID,
                underline=10)
     f_d = dict(
         family='Courier New',
         underline=1,
         overstrike=0,
     )
     case = 'title'
     gen_text = ttwidgets.gen_tag_attrs(None,
                                        o_d,
                                        f_d,
                                        case,
                                        kmode='option')
     #                                  abbrev=True) # , debug=True)
     expected_text = 'background=white foreground=blue borderwidth=2 ' \
                     'relief=solid family="Courier New" funderline=1 ' \
                     'foverstrike=0 ' \
                     'underline=10 case=title'
     o_exp_d, f_exp_d, case_exp = ttwidgets.parse_tag_attrs(expected_text)
     if True:  # ttwidgets.PyVers_f < 3.6: # False: #
         gen_text = sorted(ttwidgets.split_attrs(gen_text))
         expected_text = sorted(ttwidgets.split_attrs(expected_text))
     self.assertEqual(gen_text, expected_text)
     self.assertEqual(o_d, o_exp_d)
     self.assertEqual(f_d, f_exp_d)
     self.assertEqual(case, case_exp)
Пример #2
0
 def test_get_tag_attrs_fromDicts2(self):
     o_d = dict(family='Courier New',
                background='white',
                fg='blue',
                bd='2',
                relief=tk.SOLID,
                funderline=1,
                foverstrike=0,
                underline=10)
     gen_text = ttwidgets.gen_tag_attrs(options=o_d, kmode='alias')
     # abbrev=True) # , debug=True)
     expected_text = 'fam="Courier New" bg=white fg=blue bd=2 rel=solid ' \
                     'u=1 o=0 ul=10'
     if ttwidgets.PyVers_f < 3.6:  # False: # True: #
         gen_text = sorted(ttwidgets.split_attrs(gen_text))
         expected_text = sorted(ttwidgets.split_attrs(expected_text))
     self.assertEqual(gen_text, expected_text)
Пример #3
0
 def test_get_tag_attrs_fromDicts1(self):
     o_d = dict(family="Courier New",
                background='white',
                fg='blue',
                bd='2',
                relief=tk.SOLID,
                funderline=1,
                foverstrike=0,
                underline=10)
     gen_text = ttwidgets.gen_tag_attrs(None, o_d, kmode='')
     # abbrev=False) # , debug=True)
     expected_text = 'family="Courier New" background=white fg=blue bd=2' \
                     ' relief=solid funderline=1 foverstrike=0 underline=10'
     if ttwidgets.PyVers_f < 3.6:  # False: # True: #
         gen_text = sorted(ttwidgets.split_attrs(gen_text))
         expected_text = sorted(ttwidgets.split_attrs(expected_text))
     self.assertEqual(gen_text, expected_text)
Пример #4
0
 def test_get_tag_attrs_fromWidget1(self):
     but = ttwidgets.Button(bg='wheat',
                            text='<tag fg=red>red</tag> and <tag'
                            ' background=blue>blue</tag>')
     gen_text = but.gen_tag_attrs(kmode='', extend=True)
     # abbrev=True) # , debug=True)
     expected_text = [
         'background=wheat text="<tag fg=red>red</tag> and '
         '<tag background=blue>blue</tag>"', 'foreground=red text=red',
         'text=" and "', 'background=blue text=blue'
     ]
     if ttwidgets.PyVers_f < 3.6:  # False: # True: # False: #
         gen_text = \
             [sorted(ttwidgets.split_attrs(elem)) for elem in gen_text]
         expected_text = \
             [sorted(ttwidgets.split_attrs(elem)) for elem in expected_text]
     self.assertEqual(gen_text, expected_text)
Пример #5
0
 def test_get_tag_attrs_fromWidget4(self):
     # toplevel = tk.Tk()
     but = ttwidgets.Button(bg='wheat',
                            text='<tag fg=red>red</tag> and <tag'
                            ' background=blue>blue</tag>')
     gen_text = but.gen_tag_attrs(kmode='option', extend=False)
     # abbrev=True) # , debug=True)
     expected_text = [
         'background=wheat text="<tag fg=red>red</tag> '
         'and <tag background=blue>blue</tag>"', 'foreground=red', '',
         'background=blue'
     ]
     # print('\n\n', pprint.pformat(gen_text))
     # print('\n\n', pprint.pformat(expected_text))
     if ttwidgets.PyVers_f < 3.6:  # False: # True: # False: #
         gen_text = \
             [sorted(ttwidgets.split_attrs(elem)) for elem in gen_text]
         expected_text = \
             [sorted(ttwidgets.split_attrs(elem)) for elem in expected_text]
     self.assertEqual(gen_text, expected_text)
Пример #6
0
        print("BUT %d STATE is " % num, new_state.upper(), ", was ", state)
        if isinstance(but, TTButton):
            print("BUT %d DUMP():" % num, but.dump())
        else:
            print("BUT %d CONFIG():" % num, but.config())

    def example_method(num=-1):
        """Print message when button is released."""
        print("BUTTON %d COMMAND!" % num)
        # button = root.buttons[num]  # UNUSED

    root = tk.Tk()
    sv = tk.StringVar(name="sv")
    build_the_gui()
    print(
        split_attrs("""family="Courier New" """ +
                    """family='Times  New   Roman' size=12 upper"""))
    print(strip_tags("""one <t b>bold</t>"""))
    text_str = "one\n\ntwo<t cap>Capital Letters</t><t bitmap=question></t>"
    # <t fg="red" tit>Red\nBurn\n</t>\n
    text_chunks = split_tagged_text_into_chunks(text_str)
    print("TEXT is ", text_str, ", TEXT CHUNKS is ", text_chunks)
    divs = [split_chunk(ch) for ch in text_chunks]
    print("DIVS are ", divs)
    wrapped = wrap_tagged_text(text_str, 5)
    print(
        "MATCH? ",
        wrapped == text_str,
        "\n",
        repr(text_str),
        "\n",
        repr(wrapped),