View Single Post
Old 05-26-2023, 10:51 PM   #4
Bradles
Zealot
Bradles turned on, tuned in, and dropped out.Bradles turned on, tuned in, and dropped out.Bradles turned on, tuned in, and dropped out.Bradles turned on, tuned in, and dropped out.Bradles turned on, tuned in, and dropped out.Bradles turned on, tuned in, and dropped out.Bradles turned on, tuned in, and dropped out.Bradles turned on, tuned in, and dropped out.Bradles turned on, tuned in, and dropped out.Bradles turned on, tuned in, and dropped out.Bradles turned on, tuned in, and dropped out.
 
Bradles's Avatar
 
Posts: 112
Karma: 35586
Join Date: Nov 2020
Location: Perth, Western Australia
Device: Apple Books & Kobo Libra H20
I have never used a GridLayout before, but I think a HBoxLayout in a VBoxLayout and a stretch on the end would do the trick. I'm no expert by any means.

Here's one I prepared earlier ;-):

Spoiler:
Code:
LABEL_WIDTH = 100
class ConfigWidget(QWidget):

    def __init__(self):

        QWidget.__init__(self)

        self.l = QVBoxLayout()
        self.setLayout(self.l)

        groupBox = QGroupBox(_("OpenAI API"))
        self.l.addWidget(groupBox)

        groupBox_vlayout = QVBoxLayout()
        groupBox.setLayout (groupBox_vlayout)


        # # # API URL # # #
        # H Layout
        apilayout = QHBoxLayout()
        groupBox_vlayout.addLayout(apilayout)

        # API label
        apilabel = QLabel(_('API &URL:'))
        apilabel.setMinimumWidth(LABEL_WIDTH)
        apilayout.addWidget(apilabel)

        # API edit
        self.apiedit = QLineEdit(self)
        self.apiedit.setText(prefs['api-url'])
        self.apiedit.setToolTip(_("This is the proxy to the backend API. You do not need to change this."))
        apilayout.addWidget(self.apiedit)
        apilabel.setBuddy(self.apiedit)
        apilabel.setToolTip(self.apiedit.toolTip())
        self.apiedit.setEnabled(False)


        # # # LANGUAGE # # #
        # H Layout
        langlayout = QHBoxLayout()
        groupBox_vlayout.addLayout(langlayout)

        # Language label
        langlabel = QLabel(_('&Language:'))
        langlabel.setMinimumWidth(LABEL_WIDTH)
        langlayout.addWidget(langlabel)

        # Language edit
        self.langedit = QLineEdit(self)
        self.langedit.setText(prefs['language'])
        self.langedit.setToolTip(_("The language in which to return results, e.g. English, Spanish, German, Klingon..."))
        langlayout.addWidget(self.langedit)
        langlabel.setBuddy(self.langedit)
        langlabel.setToolTip(self.langedit.toolTip())


        # # # MAX TOKENS # # #
        # H Layout
        maxlayout = QHBoxLayout()
        groupBox_vlayout.addLayout(maxlayout)

        # Max Length label
        maxtokenslabel = QLabel(_('&Max length:'))
        maxtokenslabel.setMinimumWidth(LABEL_WIDTH)
        maxlayout.addWidget(maxtokenslabel)

        # Max Length edit
        self.maxlength = QLineEdit(self)
        validator = QIntValidator(1, 2000, self)
        # the  lineedit SHOULD only accept integers between 1 and 2000, but actually accepts 9999!
        self.maxlength.setValidator(validator)
        self.maxlength.setText(prefs['max-length'])
        self.maxlength.setToolTip(_("The maximum length in tokens, where 1000 tokens is about 750 words."))
        maxlayout.addWidget(self.maxlength)
        maxtokenslabel.setBuddy(self.maxlength)        
        maxtokenslabel.setToolTip(self.maxlength.toolTip())


        # # # TEMPERATURE # # #
        # H Layout
        templayout = QHBoxLayout()
        groupBox_vlayout.addLayout(templayout)

        # Temperature label
        templabel = QLabel(_('&Temperature:'))
        templabel.setMinimumWidth(LABEL_WIDTH)
        templayout.addWidget(templabel)

        # Temperature slider (save as float in range 0.00:2.00)
        self.tempslider = QSlider(self)
        self.tempslider.setOrientation(Qt.Horizontal)
        self.tempslider.setMinimum(0)
        self.tempslider.setMaximum(200)
        self.tempslider.setToolTip(_("Control the randomness of results, where lower numbers are less random."))
        templayout.addWidget(self.tempslider)
        templabel.setBuddy(self.tempslider)        
        templabel.setToolTip(self.tempslider.toolTip())

        # Temperature value (updated in response to slider changing)
        self.tempvalue = QLabel()
        templayout.addWidget(self.tempvalue)

        # make sure above layouts align to the top
        groupBox_vlayout.addStretch()

        # do this last so tempvalue is ready to go
        self.tempslider.valueChanged.connect(self.temp_value_changed)
        self.tempslider.setValue(int(100 * float(prefs['temperature'])))
Bradles is offline   Reply With Quote