示例#1
0
    def test_45(self):

        triggered = ""

        class TriggerLog:
            triggered = ""

            def triggered1(self, b):
                if b:
                    self.triggered += "1"
                else:
                    self.triggered += "0"

            def triggered0(self):
                self.triggered += "*"

        # Ability to connect to signals while ignoring arguments and
        # to emit signals

        b = pya.QPushButton()

        log = TriggerLog()

        b.clicked(log.triggered1)

        self.assertEqual(log.triggered, "")
        b.emit_clicked(True)
        self.assertEqual(log.triggered, "1")
        b.emit_clicked(False)
        self.assertEqual(log.triggered, "10")

        b.clicked(log.triggered0)

        b.emit_clicked(True)
        self.assertEqual(log.triggered, "10*")
        b.emit_clicked(False)
        self.assertEqual(log.triggered, "10**")

        # We do the same with free functions since they behave differently in Python:

        global trigger_log
        trigger_log = ""

        def triggered_f0():
            global trigger_log
            trigger_log += "x"

        def triggered_f1(b):
            global trigger_log
            if b:
                trigger_log += "+"
            else:
                trigger_log += "-"

        b.clicked(triggered_f1)

        self.assertEqual(trigger_log, "")
        b.emit_clicked(True)
        self.assertEqual(trigger_log, "+")
        b.emit_clicked(False)
        self.assertEqual(trigger_log, "+-")

        b.clicked(triggered_f0)

        b.emit_clicked(True)
        self.assertEqual(trigger_log, "+-x")
        b.emit_clicked(False)
        self.assertEqual(trigger_log, "+-xx")
示例#2
0
    def settings(self, parent=None):
        if parent is None:
            parent = self
        settingw = pya.QWidget(self)
        vbox = pya.QVBoxLayout(settingw)
        settingw.setLayout(vbox)
        self.settingspath = kgit.settings_path
        self.settings = {}

        scrollarea = pya.QScrollArea(self)
        optionswidget = pya.QWidget(self)
        scrollarea.setWidget(optionswidget)
        scrollarea.setWidgetResizable(True)

        optionvbox = pya.QVBoxLayout(optionswidget)
        categorydict = vars(kgit.settings)

        hbSplitter = pya.QHBoxLayout()
        vboxbuttons = pya.QVBoxLayout()
        vbox.addLayout(hbSplitter)
        hbSplitter.addWidget(scrollarea)
        hbSplitter.addLayout(vboxbuttons)

        resetButton = pya.QPushButton('Restore Defaults', self)
        resetButton.clicked(self.restoreDefaults)
        vboxbuttons.addWidget(resetButton)

        vboxbuttons.addStretch()

        # Repository Settings

        cat = 'Repository'
        groupbox = pya.QGroupBox(cat, self)
        optionvbox.addWidget(groupbox)
        vb = pya.QVBoxLayout(groupbox)
        self.settings['repository'] = {}
        repdic = self.settings['repository']
        repdic['url'] = [
            kgit.settings.repository.url(), kgit.settings.repository.url
        ]
        l = pya.QHBoxLayout()
        le = pya.QLineEdit(repdic['url'][0], self)

        def assignurl(text):
            repdic['url'][0] = text

        le.textChanged = assignurl
        la = pya.QLabel(kgit.settings.repository.url.description, self)
        l.addWidget(le)
        l.addWidget(la)
        vb.addLayout(l)
        l = pya.QHBoxLayout()
        repdic['autoupdate'] = [
            kgit.settings.repository.autoupdate(),
            kgit.settings.repository.autoupdate
        ]
        b = pya.QCheckBox(kgit.settings.repository.autoupdate.description,
                          groupbox)
        if repdic['autoupdate'][0]:
            b.setChecked(True)
        else:
            b.setChecked(False)

        def updateclicked(checked):
            repdic['autoupdate'][0] = checked

        b.toggled = updateclicked
        l.addWidget(b)
        vb.addLayout(l)

        # Log settings

        cat = "Logs"
        groupbox = pya.QGroupBox(cat, self)
        optionvbox.addWidget(groupbox)
        vb = pya.QVBoxLayout(groupbox)
        self.settings['logging'] = {}
        logdic = self.settings['logging']
        logdic['filelvl'] = [
            kgit.settings.logging.logfilelevel.value.index,
            kgit.settings.logging.logfilelevel
        ]
        logdic['streamlvl'] = [
            kgit.settings.logging.logstreamlevel.value.index,
            kgit.settings.logging.logstreamlevel
        ]
        ## File Logging
        v = pya.QComboBox(self)
        l = pya.QHBoxLayout()
        for i in kgit.settings.logging.levels():
            v.addItem(i)
        v.currentIndex = logdic['filelvl'][0]
        vb.addLayout(l)
        l.addWidget(v)
        d = pya.QLabel(kgit.settings.logging.logfilelevel.description, self)

        def logfileindexchanged(index):
            logdic['filelvl'][0] = index

        v.currentIndexChanged = logfileindexchanged
        l.addWidget(d)
        l.addStretch()
        ## Stream Logging
        v = pya.QComboBox(self)
        l = pya.QHBoxLayout()
        for i in kgit.settings.logging.levels():
            v.addItem(i)
        v.currentIndex = logdic['streamlvl'][0]
        vb.addLayout(l)
        l.addWidget(v)
        d = pya.QLabel(kgit.settings.logging.logfilelevel.description, self)

        def logfileindexchanged(index):
            logdic['streamlvl'][0] = index

        v.logfileindexchanged = logfileindexchanged
        l.addWidget(d)
        l.addStretch()
        vbox.addStretch()

        save = pya.QPushButton("Save", self)
        save.clicked = self.save
        abort = pya.QPushButton("Cancel", self)
        abort.clicked = self.abort
        hbox = pya.QHBoxLayout()
        vbox.addLayout(hbox)
        hbox.addWidget(abort)
        hbox.addStretch()
        hbox.addWidget(save)

        optionvbox.addStretch()

        return settingw
示例#3
0
    def repoManager(self, parent=None):
        if parent is None:
            parent = self

        widget = pya.QWidget(self)

        vbox = pya.QVBoxLayout(widget)
        widget.setLayout(vbox)

        self.repolist = pya.QListWidget(widget)
        repos = kgit.getRepos()

        items = []

        for r in repos:
            s = yaml.safe_load(r.read_text())
            if '/' in s['name']:
                description = (f"Name:\t\t{s['name'].rsplit('/',1)[1]}\n"
                               f"Project:\t\t{s['name'].rsplit('/',1)[0]}\n")
            else:
                description = f"Name:\t\t{s['name']}\n"
            description += "Location:\t\tlocal\n"
            if 'author' in s:
                description += f"Author:\t\t{s['author']}\n"
                pass
            description += f"Project URL:\t\t{s['url']}"
            if 'subdir' in s:
                description += f"\nProject Sub-URL:\t{s['subdir']}"
            item = pya.QListWidgetItem(description)
            item.whatsThis = s['name']
            repo = git.Repo(r.parent)
            if repo.git.status('s'):
                pass
            items.append(item)
            self.repolist.addItem(item)
        remoterepos = kgit.getRemoteRepos()
        if remoterepos is not None:
            for r in remoterepos:
                if r['name'] in [i.whatsThis for i in items]:
                    continue
                if '/' in r['name']:
                    description = (
                        f"Name:\t\t{r['name'].rsplit('/',1)[1]}\n"
                        f"Project:\t\t{r['name'].rsplit('/',1)[0]}\n")
                else:
                    description = f"Name:\t\t{r['name']}\n"
                description += "Location:\t\tremote\n"
                description += f"Project URL:\t\t{r['url']}"
                if 'subdir' in r:
                    description += f"\nProject Sub-URL:\t{r['subdir']}"

                item = pya.QListWidgetItem(description)
                item.whatsThis = r['name']
                self.repolist.addItem(item)

        vbox.addWidget(self.repolist)

        buttonbox = pya.QHBoxLayout(widget)
        downloadbutton = pya.QPushButton("Download && Install", widget)
        downloadbutton.clicked = self.downloadRepos
        buttonbox.addWidget(downloadbutton)
        buttonbox.addStretch()
        removebutton = pya.QPushButton("Remove", widget)
        buttonbox.addWidget(removebutton)
        vbox.addLayout(buttonbox)

        return widget
    def __init__(self, parent=None):
        super(ImageToLayout, self).__init__()
        self.setWindowTitle("Image to Layout")

        self.window_width = 800
        self.window_height = 600

        self.resize(self.window_width, self.window_height)

        self.layout = pya.QGridLayout(self)

        self.input_text = pya.QLineEdit(self)
        self.input_text.setAcceptDrops(True)
        self.input_text.setFont(pya.QFont('Times', 15))

        self.input_text.setText("select image:")

        self.file_dialog = pya.QFileDialog(self)
        self.file_dialog.setFont(pya.QFont('Times', 10))

        self.select_file_button = pya.QPushButton("select image", self)
        self.select_file_button.setFont(pya.QFont('Times', 15, pya.QFont.Bold))
        self.select_file_button.clicked(self.select_file_button_clicked)

        self.convert_button = pya.QPushButton("convert to OASIS file", self)
        self.convert_button.setFont(pya.QFont('Times', 15, pya.QFont.Bold))
        self.convert_button.clicked(self.covert_buttion_clicked)

        self.raw_image_label = pya.QLabel()

        self.raw_image_info_label = pya.QLabel("image size:")
        self.raw_image_info_label.setVisible(False)

        self.threshold_text = pya.QLineEdit(self)
        self.threshold_text.setAcceptDrops(True)
        self.threshold_text.setFont(pya.QFont('Times', 15))
        self.threshold_text.setText("set threshold: 0 - 255")

        self.dbu_text = pya.QLineEdit(self)
        self.dbu_text.setAcceptDrops(True)
        self.dbu_text.setFont(pya.QFont('Times', 15))
        self.dbu_text.setText("set DBU: ")

        self.inverse_checkbox = pya.QCheckBox("inverse", self)
        self.inverse_checkbox.setFont(pya.QFont('Times', 15))

        self.progress_bar = pya.QProgressBar(self)

        self.layout.addWidget(self.input_text, 0, 0)
        self.layout.addWidget(self.select_file_button, 0, 1)
        self.layout.addWidget(self.raw_image_label, 1, 0, 3, 1)

        self.layout.addWidget(self.threshold_text, 1, 1)
        self.layout.addWidget(self.inverse_checkbox, 2, 1)
        self.layout.addWidget(self.dbu_text, 3, 1)

        self.layout.addWidget(self.raw_image_info_label, 4, 0)

        self.layout.addWidget(self.progress_bar, 5, 0)
        self.layout.addWidget(self.convert_button, 5, 1)

        self.setLayout(self.layout)
    def __init__(self, parent=None):
        self.settingspath = kppc.settings_path
        self.vbox = pya.QVBoxLayout()
        self.setLayout(self.vbox)
        self.settings = {}
        self.setWindowTitle("KLayoutPhotonicPCells Settings")
        self.setMinimumWidth(300)
        vsize = len(vars(kppc.settings))

        self.scrollarea = pya.QScrollArea(self)
        self.optionswidget = pya.QWidget(self)
        self.scrollarea.setWidget(self.optionswidget)
        self.scrollarea.setWidgetResizable(True)

        #self.vbox.addWidget(self.scrollarea)
        self.optionvbox = pya.QVBoxLayout(self.optionswidget)
        categorydict = vars(kppc.settings)

        hbSplitter = pya.QHBoxLayout()
        vboxbuttons = pya.QVBoxLayout()
        self.vbox.addLayout(hbSplitter)
        hbSplitter.addWidget(self.scrollarea)
        hbSplitter.addLayout(vboxbuttons)

        recompileButton = pya.QPushButton('Recompile', self)
        recompileButton.clicked(self.recompile)
        vboxbuttons.addWidget(recompileButton)

        resetButton = pya.QPushButton('Restore Defaults', self)
        resetButton.clicked(self.restoreDefaults)
        vboxbuttons.addWidget(resetButton)

        vboxbuttons.addStretch()

        for i, cat in enumerate(categorydict.keys()):
            groupbox = pya.QGroupBox(cat, self)
            self.optionvbox.addWidget(groupbox)
            vb = pya.QVBoxLayout(groupbox)
            self.settings[cat] = {}

            settingdict = vars(categorydict[cat])
            for j, setting in enumerate(settingdict):

                if setting[0] == '_':
                    continue

                opt = settingdict[setting]
                desc_str = f"_{setting}_DESC"
                if desc_str in settingdict:
                    desc = settingdict[desc_str]
                else:
                    desc = setting

                if isinstance(opt, bool):
                    v = pya.QCheckBox(desc, self)
                    vb.addWidget(v)
                    v.toggeled = v.setChecked(opt)
                    self.settings[cat][setting] = (
                        v, lambda x: bool(x.checkState.to_i()))
                elif isinstance(opt, int):
                    l = pya.QHBoxLayout()
                    vb.addLayout(l)
                    t = pya.QLabel(desc, self)
                    v = pya.QSpinBox(self)
                    l.addWidget(v)
                    l.addWidget(t)
                    l.addStretch()
                    v.value = opt
                    minset = f"_{setting}_MIN"
                    maxset = f"_{setting}_MAX"
                    if minset in settingdict:
                        v.minimum = settingdict[minset]
                    if maxset in settingdict:
                        v.maximum = settingdict[maxset]
                    self.settings[cat][setting] = (v, lambda x: x.value)
                elif isinstance(opt, list):
                    v = pya.QComboBox(self)
                    l = pya.QHBoxLayout()
                    index = int(opt[0])
                    strs = opt[1:]
                    for i in strs:
                        v.addItem(i)
                    v.currentIndex = index
                    vb.addLayout(l)
                    l.addWidget(v)
                    d = pya.QLabel(desc, self)
                    l.addWidget(d)
                    l.addStretch()
                    self.settings[cat][setting] = (
                        v, lambda x, l=strs: [x.currentIndex] + l)
                else:
                    continue
        self.vbox.addStretch()

        save = pya.QPushButton("Save", self)
        save.clicked = self.save
        abort = pya.QPushButton("Cancel", self)
        abort.clicked = self.abort
        self.hbox = pya.QHBoxLayout()
        self.vbox.addLayout(self.hbox)
        self.hbox.addWidget(abort)
        self.hbox.addStretch()
        self.hbox.addWidget(save)
示例#6
0
文件: menu.py 项目: joamatab/kgit
    def settings(self, parent=None):
        if parent is None:
            parent = self
        settingw = pya.QWidget(self)
        vbox = pya.QVBoxLayout(settingw)
        settingw.setLayout(vbox)
        self.settingspath = kgit.settings_path
        self.settings = {}

        scrollarea = pya.QScrollArea(self)
        optionswidget = pya.QWidget(self)
        scrollarea.setWidget(optionswidget)
        scrollarea.setWidgetResizable(True)

        optionvbox = pya.QVBoxLayout(optionswidget)
        categorydict = vars(kgit.settings)

        hbSplitter = pya.QHBoxLayout()
        vboxbuttons = pya.QVBoxLayout()
        vbox.addLayout(hbSplitter)
        hbSplitter.addWidget(scrollarea)
        hbSplitter.addLayout(vboxbuttons)

        resetButton = pya.QPushButton('Restore Defaults', self)
        resetButton.clicked(self.restoreDefaults)
        vboxbuttons.addWidget(resetButton)

        vboxbuttons.addStretch()

        # General Settings

        cat = 'Repository'
        groupbox = pya.QGroupBox(cat, self)
        optionvbox.addWidget(groupbox)
        vb = pya.QVBoxLayout(groupbox)
        self.settings['repository'] = {}
        repdic = self.settings['repository']
        repdic['url'] = (kgit.settings.repository.url(),
                         kgit.settings.repository.url)
        l = pya.QHBoxLayout()
        le = pya.QLineEdit(repdic['url'][0], self)
        la = pya.QLabel(kgit.settings.repository.url.description, self)
        l.addWidget(le)
        l.addWidget(la)
        vb.addLayout(l)

        # Log settings

        cat = "Logs"
        groupbox = pya.QGroupBox(cat, self)
        optionvbox.addWidget(groupbox)
        vb = pya.QVBoxLayout(groupbox)
        self.settings['logging'] = {}
        logdic = self.settings['logging']
        logdic['filelvl'] = (kgit.settings.logging.logfilelevel.value.index,
                             kgit.settings.logging.logfilelevel)
        logdic['streamlvl'] = (
            kgit.settings.logging.logstreamlevel.value.index,
            kgit.settings.logging.logstreamlevel)
        ## File Logging
        v = pya.QComboBox(self)
        l = pya.QHBoxLayout()
        for i in kgit.settings.logging.levels():
            v.addItem(i)
        v.currentIndex = logdic['filelvl'][0]
        vb.addLayout(l)
        l.addWidget(v)
        d = pya.QLabel(kgit.settings.logging.logfilelevel.description, self)
        l.addWidget(d)
        l.addStretch()
        ## Stream Logging
        v = pya.QComboBox(self)
        l = pya.QHBoxLayout()
        for i in kgit.settings.logging.levels():
            v.addItem(i)
        v.currentIndex = logdic['streamlvl'][0]
        vb.addLayout(l)
        l.addWidget(v)
        d = pya.QLabel(kgit.settings.logging.logfilelevel.description, self)
        l.addWidget(d)
        l.addStretch()
        vbox.addStretch()

        save = pya.QPushButton("Save", self)
        save.clicked = self.save
        abort = pya.QPushButton("Cancel", self)
        abort.clicked = self.abort
        hbox = pya.QHBoxLayout()
        vbox.addLayout(hbox)
        hbox.addWidget(abort)
        hbox.addStretch()
        hbox.addWidget(save)

        optionvbox.addStretch()

        return settingw