jeejz / pythonProjects

1 stars 0 forks source link

PySimpleGUIQt - Horizontal and Vertical separators! #2

Open MikeTheWatchGuy opened 5 years ago

MikeTheWatchGuy commented 5 years ago

I just released version 0.13.0 of PySimpleGUIQt. It has fully functioning Horizontal and Vertical separators.

By the way, you can get longer lines.... you need to use Columns to do this. I'll create an example for you to see. I'm pretty sure it'll work in tkinter where the line spans multiple rows.

MikeTheWatchGuy commented 5 years ago

OK, I figured out how to make the long lines you want:

    psg.SetOptions(border_width=0)
    lines = []
    for line in range(4):
        cols = []
        col = []
        for cell in range(4):
            col = []
            cols.append(psg.VerticalSeparator())
            for x in range(3):
                row = []
                for y in range(3):
                    row.append(psg.InputText(default_text=test_val[keyGen], do_not_clear=True, size=(3, 1), key=keyGen, change_submits=True, justification='center'))
                col.append(row)
            col.append([psg.T('_'*14)])
            cols.append(psg.Column(col))
        cols.append(psg.VerticalSeparator())
        lines.append(cols)
    layout = [*lines,
              [psg.OK(), psg.Cancel() ]]

    window =  psg.Window('Submit Question',auto_size_text=True ).Layout(layout)

    prev_val = {}
    while True:
        event, value = window.Read()

image

Is this a little more like what you're seeking?

It took implementing the lines in Qt to figure out that it was already possible using PySimpleGUI.

Finally, you can change the import from PySimpleGUI to PySimpleGUIQt and it looks almost identical.

image

MikeTheWatchGuy commented 5 years ago

snag-0282

The best so far in my opinion, at least of the ones I've been making:

import PySimpleGUIQt as psg

psg.SetOptions(border_width=0)
lines = []
lines.append([psg.HorizontalSeparator()])
for line in range(4):
    cols = []
    col = []
    for cell in range(4):
        col = []
        cols.append(psg.VerticalSeparator())
        for x in range(3):
            row = []
            for y in range(3):
                row.append(psg.InputText(default_text='', do_not_clear=True, size=(3, 1), change_submits=True, justification='center'))
            col.append(row)
        cols.append(psg.Column(col))
    cols.append(psg.VerticalSeparator())
    lines.append(cols)
    lines.append([psg.HorizontalSeparator()])
layout = [*lines,
          [psg.OK(), psg.Cancel() ]]

window =  psg.Window('Submit Question',auto_size_text=True ).Layout(layout)

prev_val = {}
while True:
    event, value = window.Read()
MikeTheWatchGuy commented 5 years ago

image

TaDa!

Perfect boxes. And it was easy...

Use a Frame with a title of '' instead of Column and you'll get a box!

It even works on Qt....

image

import PySimpleGUI as psg
# from SuDoKuSolver import SudokuRefManipClass as refc

def draw_box():
     #test_val[keyGen]
    column = [[]]
    input1 = []
    for i in range(1,10):
        for j in range(1,10):
            keyGen = str(i)+str(j)
            input1.append(psg.InputText(default_text=test_val[keyGen], do_not_clear=True,
                                        size=(3, 3), key=keyGen, change_submits=True, justification='center'))
            if j == 3 or j == 6 :
                input1.append(psg.Text('|'))
        column.append(input1)
        input1 = []
        if i%3 == 0:
            column.append([psg.Text('_' * 50,justification='CENTER')])

    psg.SetOptions(border_width=0)
    lines = []
    # lines.append([psg.HorizontalSeparator()])
    for line in range(4):
        cols = []
        col = []
        for cell in range(4):
            col = []
            # cols.append(psg.VerticalSeparator())
            for x in range(3):
                row = []
                for y in range(3):
                    row.append(psg.InputText(default_text=test_val[keyGen], do_not_clear=True, size=(3, 1), key=keyGen, change_submits=True, justification='center'))
                col.append(row)
            cols.append(psg.Frame('', col))
        # cols.append(psg.VerticalSeparator())
        lines.append(cols)
        # lines.append([psg.HorizontalSeparator()])
    layout = [*lines,
              [psg.OK(), psg.Cancel() ]]

    window =  psg.Window('Submit Question',auto_size_text=True ).Layout(layout)

    prev_val = {}
    while True:
        event, value = window.Read()
        if prev_val.__len__() == 0:
            prev_val = value
        # rc = refc.SudokuRefListClass()
        if event is None or event == 'Exit' or event == 'Cancel':
            break

        inp_tx = window.FindElement(event)
        is_upd_flag = False
        if not inp_tx.Get().isdigit():
            inp_tx.Update('')
        elif inp_tx.Get() == '0':
            inp_tx.Update('')
        else:
            is_upd_flag = True
            if inp_tx.Get().__len__() > 1 :
                inp_tx.Update(str(inp_tx.Get()).__getitem__(1))
            else:
                inp_tx.Update(inp_tx.Get())

        if not is_upd_flag:
            if prev_val[event] is not inp_tx.Get():
                print('prev {0} - curr {1}'.format(prev_val[event], inp_tx.Get()))
                is_upd_flag = True

        value[event] = inp_tx.Get()
        print(event, value)

        if is_upd_flag:
            rc.update_sudoku_with_event_value(event, value)
        prev_val = value

draw_box()
MikeTheWatchGuy commented 5 years ago

Hey when are you going to update your code? I was looking forward to seeing more of it. Is it complete now?

nburno commented 3 years ago

Hi, Is this the only way to draw vertical and horizontal with PySimpleGUI QT?!! And if you change the default tiny font you missed up with the alignment. As well it does not accept some parameters mentioned in the manual like justification in column element and size with buttons, and nowhere to have position parameter for the elements. At the end you spend alot of time with trial and error for the effective elements' parameters and by adding some spaces with sg.Text here and there to have something acceptable .

PySimpleGUI commented 3 years ago

An alpha is about to start for a new version of PySimpleGUIQt. Let's see how it goes.

The features developed over the past year have been focused, needed to be focused, on the tkinter port. They'll be ported over eventually or some of the Qt unique elements like the Stretch element will perhaps help.

There's also an Call Ref doc being produced for this Alpha. Things are looking better for the Qt port.