Пример #1
0
import sys

import GridLayout

from PyQt5.QtWidgets import QApplication, QMainWindow

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = QMainWindow()
    ui = GridLayout.Ui_MainWindow()
    # 向主窗口添加控件
    ui.setupUi(mainWindow)
    mainWindow.show()
    sys.exit(app.exec_())
Пример #2
0
    def onExec(self):
        """On app running"""

        onreleaseLeft = 0, 0
        firstPressed = False
        temp = ["0", "", False]
        ctrl = Controller()
        textWidth = 1

        while self.running:
            onkeydown = False
            key = None

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.running = False

                # make window resizable
                if event.type == pygame.VIDEORESIZE:
                    self.surface = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)

                # set the mouse position at first click
                if not firstPressed and event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                    self.onclickLeft = pygame.mouse.get_pos()
                    firstPressed = True
                #  set the position at mouse release
                if firstPressed and event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                    onreleaseLeft = pygame.mouse.get_pos()
                    firstPressed = False

                # keydown event
                if event.type == pygame.KEYDOWN:
                    key = self.keyDownEvent(event)
            
            # set background color for the screen
            self.surface.fill(self.bgcolor)

            # update mouse position
            self.mousePos()

            # set text for buttons
            buttons = [["C",  "+/-", "%", "÷", "×"],
                       ["(",   "7",  "8", "9", "-"],
                       [")",   "4",  "5", "6", "+"],
                       ["xʸ",  "1",  "2", "3", "="],
                       ["√x",  "0",  "0", ".", "="]]

            # determine the property of the buttons
            result_field_height = 100
            input_field_height = 40
            display_field_height = result_field_height + input_field_height

            # set bg for button group panel
            pygame.draw.rect(self.surface, (40, 44, 55), (0, result_field_height, self.surface.get_width(), self.surface.get_height() - result_field_height))
            
            grid = GridLayout(buttons, (0, display_field_height, self.surface.get_width(), self.surface.get_height()), 20)

            for rect in grid.generate():
                if rect is not None:
                    btn = RoundButton(self.surface, self.mouse, self.onclickLeft, onreleaseLeft, onkeydown, borderRadius=10)
                    i, j = grid.getIndex()
                    b = buttons[i][j]
                    btn.setText(b)
                    btn.setRect((rect[0], rect[1], rect[2], rect[3]))

                    if b == "=":
                        btn.setBGColor((51, 235, 145))
                        btn.setSound("sound/buttonclick_big.mp3")
                    elif i == 0 or j == len(buttons[0]) - 1 or j == 0:
                        btn.setBGColor((74, 81, 99))
                        btn.setSound("sound/buttonclick_big.mp3")
                    else:
                        btn.setSound("sound/buttonclick_small.mp3")

                    btn.draw()
                    
                    if b == key:
                        btn.keydown()
                        
                    if btn.onClick():
                        ctrl.addInput(b)
                        temp = ctrl.onHandle()
                    
            # set and draw backspace button
            backspaceButton = ImageButton(self.surface, self.mouse, self.onclickLeft, onreleaseLeft, onkeydown, "icon/outline_backspace_white_18dp.png", "icon/baseline_backspace_white_18dp.png", (40, 44, 55),(self.surface.get_width() - 50, result_field_height + input_field_height / 2 - 15, 36, 36))
            backspaceButton.setSound("sound/buttonclick_big.mp3")
            backspaceButton.draw()

            if key == "del":
                backspaceButton.keydown()

            # when click backspace button, send value to controller
            if backspaceButton.onClick():
                self.text = "del"
                ctrl.addInput("del")
                # temp = " ".join(ctrl.onHandle())
                temp = ctrl.onHandle()
            if onreleaseLeft != (0, 0):
                self.onclickLeft = 0, 0
                onreleaseLeft = 0, 0

            # self.onclickLeft = 0, 0
            # ctrl = Controller()
            # displayInput = Text(self.surface, temp, "Consolas", fontColor=(255, 255, 255), align="right", pos=(self.surface.get_width() - 60, result_field_height + input_field_height / 2 + 4))
            # inputLength = len(displayInput)
            # if inputLength < 22:
            #     displayInput.setFontSize(25)
            # elif inputLength < 50:
            #     displayInput.setFontSize(20)
            # displayInput.draw()

            displayResult = Text(self.surface, temp[0], "Consolas", pos=(self.surface.get_width() - 20, result_field_height / 2), align="right", fontColor=(255, 255, 255))
            resultLength = len(displayResult)
            ctrl.setInputLength(resultLength)
            w = self.surface.get_width() - 40

            # change font size for displayResult if it reach the limit
            if resultLength <= w // 22:
                displayResult.setFontSize(40)
            elif resultLength <= w // 17:
                displayResult.setFontSize(30)
            elif resultLength <= w // 11:
                displayResult.setFontSize(20)
            else: # max 42 chars
                displayResult.setFontSize(20)
                temp[0] = temp[0][:w // 11]
            ctrl.setMaxChar(w // 11)


            # if re < textWidth // resultLength
            
            displayResult.draw()
            textWidth = displayResult.getRect()[2]
            # print(1//2)

            pygame.display.update()
        
        pygame.quit()
        quit()
Пример #3
0
    def onExec(self):
        """On app running"""

        onreleaseLeft = 0, 0
        firstPressed = False
        temp = ["0", "", False]
        ctrl = Controller()
        textWidth = 1

        while self.running:
            onkeydown = False
            key = None

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.running = False

                # make window resizable
                if event.type == pygame.VIDEORESIZE:
                    self.surface = pygame.display.set_mode((event.w, event.h),
                                                           pygame.RESIZABLE)

                # set the mouse position at first click
                if not firstPressed and event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                    self.onclickLeft = pygame.mouse.get_pos()
                    firstPressed = True
                #  set the position at mouse release
                if firstPressed and event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                    onreleaseLeft = pygame.mouse.get_pos()
                    firstPressed = False

                # keydown event
                if event.type == pygame.KEYDOWN:
                    key = self.keyDownEvent(event)

            # set background color for the screen
            self.surface.fill(self.bgcolor)

            # update mouse position
            self.mousePos()

            # set text for buttons
            buttons = [["C", "+/-", "%", "÷", "×"], ["(", "7", "8", "9", "-"],
                       [")", "4", "5", "6", "+"], ["xʸ", "1", "2", "3", "="],
                       ["√x", "0", "0", ".", "="]]

            # determine the property of the buttons
            result_field_height = 100
            input_field_height = 40
            display_field_height = result_field_height + input_field_height

            # set bg for button group panel
            pygame.draw.rect(self.surface, (40, 44, 55),
                             (0, result_field_height, self.surface.get_width(),
                              self.surface.get_height() - result_field_height))

            grid = GridLayout(
                buttons, (0, display_field_height, self.surface.get_width(),
                          self.surface.get_height()), 20)

            for rect in grid.generate():
                if rect is not None:
                    btn = RoundButton(self.surface,
                                      self.mouse,
                                      self.onclickLeft,
                                      onreleaseLeft,
                                      onkeydown,
                                      borderRadius=10)
                    i, j = grid.getIndex()
                    b = buttons[i][j]
                    btn.setText(b)
                    btn.setRect((rect[0], rect[1], rect[2], rect[3]))

                    if b == "=":
                        btn.setBGColor((51, 235, 145))
                        btn.setSound("sound/buttonclick_big.mp3")
                    elif i == 0 or j == len(buttons[0]) - 1 or j == 0:
                        btn.setBGColor((74, 81, 99))
                        btn.setSound("sound/buttonclick_big.mp3")
                    else:
                        btn.setSound("sound/buttonclick_small.mp3")

                    btn.draw()

                    if b == key:
                        btn.keydown()

                    if btn.onClick():
                        ctrl.addInput(b)
                        temp = ctrl.onHandle()

            # set and draw backspace button
            backspaceButton = ImageButton(
                self.surface, self.mouse, self.onclickLeft, onreleaseLeft,
                onkeydown, "icon/outline_backspace_white_18dp.png",
                "icon/baseline_backspace_white_18dp.png", (40, 44, 55),
                (self.surface.get_width() - 50,
                 result_field_height + input_field_height / 2 - 15, 36, 36))
            backspaceButton.setSound("sound/buttonclick_big.mp3")
            backspaceButton.draw()

            if key == "del":
                backspaceButton.keydown()

            # when click backspace button, send value to controller
            if backspaceButton.onClick():
                self.text = "del"
                ctrl.addInput("del")
                # temp = " ".join(ctrl.onHandle())
                temp = ctrl.onHandle()
            if onreleaseLeft != (0, 0):
                self.onclickLeft = 0, 0
                onreleaseLeft = 0, 0

            # self.onclickLeft = 0, 0
            # ctrl = Controller()
            # displayInput = Text(self.surface, temp, "Consolas", fontColor=(255, 255, 255), align="right", pos=(self.surface.get_width() - 60, result_field_height + input_field_height / 2 + 4))
            # inputLength = len(displayInput)
            # if inputLength < 22:
            #     displayInput.setFontSize(25)
            # elif inputLength < 50:
            #     displayInput.setFontSize(20)
            # displayInput.draw()

            displayResult = Text(self.surface,
                                 temp[0],
                                 "Consolas",
                                 pos=(self.surface.get_width() - 20,
                                      result_field_height / 2),
                                 align="right",
                                 fontColor=(255, 255, 255))
            resultLength = len(displayResult)
            ctrl.setInputLength(resultLength)
            w = self.surface.get_width() - 40

            # change font size for displayResult if it reach the limit
            if resultLength <= w // 22:
                displayResult.setFontSize(40)
            elif resultLength <= w // 17:
                displayResult.setFontSize(30)
            elif resultLength <= w // 11:
                displayResult.setFontSize(20)
            else:  # max 42 chars
                displayResult.setFontSize(20)
                temp[0] = temp[0][:w // 11]
            ctrl.setMaxChar(w // 11)

            # if re < textWidth // resultLength

            displayResult.draw()
            textWidth = displayResult.getRect()[2]
            # print(1//2)

            pygame.display.update()

        pygame.quit()
        quit()
Пример #4
0
    def controlUi(self, MainWindow):

        MainWindow.setObjectName("MainWindow")
        #         MainWindow.resize(1000, 550)
        font = QtGui.QFont()
        font.setItalic(True)
        MainWindow.setFont(font)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        #         layout = QtWidgets.QHBoxLayout(self.scrollAreaWidgetContents)

        self.gridLayout_centralwidget = QtWidgets.QGridLayout(
            self.centralwidget)

        ######  Instantiating GUI classes

        self.inout_resource_gui = IO_ResourceGUI.InOut_resource(
            self.centralwidget, self.gridLayout_centralwidget)
        self.analysisgui = AnalysisGUI.analyzer(self.centralwidget,
                                                self.gridLayout_centralwidget)
        #         self.gridLayout_centralwidget.addWidget(self.analysisgui, 1, 11, 10, 12)
        self.analysisgui.setEnabled(False)
        self.displaygui = DisplayGUI_Copy1.display()
        self.displaygui.show()
        #self.displaygui = DisplayGUI.display(self.centralwidget)
        self.displaygui.setEnabled(False)

        self.inputoutputcontrol = InputOutput.inputoutput_control()

        #         self.gridLayout_centralwidget.addWidget(self.inout_resource_gui, 1, 1, 4, 10)

        self.image_analyzer = Analysis.ImageAnalyzer(self.analysisgui,
                                                     self.inout_resource_gui)
        #self.ImDisplay = Display.imagedisplayer(self.analysisgui,self.centralwidget)
        self.ImDisplay = Display_Copy1.imagedisplayer(self.analysisgui,
                                                      self.centralwidget,
                                                      self.analysisgui)
        self.PlateGrid = GridLayout.gridgenerator(
            self.centralwidget, self.gridLayout_centralwidget)
        self.PlateGrid.setEnabled(False)

        self.CV_Reader = MetaData_Reader.CellVoyager()

        #         self.setLayout(self.gridLayout_centralwidget)
        MainWindow.setCentralWidget(self.centralwidget)

        ######  Input Output loader controllers

        self.inout_resource_gui.LoadMetadataButton.clicked.connect(
            lambda: self.ON_CLICK_LOADBUTTON(self.inout_resource_gui))
        self.inout_resource_gui.DisplayCheckBox.stateChanged.connect(
            lambda: self.ImDisplay.display_initializer(
                self.Meta_Data_df, self.displaygui, self.inout_resource_gui))

        self.inout_resource_gui.DisplayCheckBox.stateChanged.connect(
            lambda: self.PlateGrid.GRID_INITIALIZER(
                self.Meta_Data_df, self.displaygui, self.inout_resource_gui,
                self.ImDisplay))
        self.PlateGrid.tableWidget.itemClicked.connect(
            lambda: self.PlateGrid.on_click_table(
                self.Meta_Data_df, self.displaygui, self.inout_resource_gui,
                self.ImDisplay))
        self.PlateGrid.FOVlist.itemClicked.connect(
            lambda: self.PlateGrid.on_click_list(self.ImDisplay, self.
                                                 displaygui))
        self.PlateGrid.Zlist.itemClicked.connect(
            lambda: self.PlateGrid.on_click_list(self.ImDisplay, self.
                                                 displaygui))
        self.PlateGrid.Timelist.itemClicked.connect(
            lambda: self.PlateGrid.on_click_list(self.ImDisplay, self.
                                                 displaygui))

        #self.inout_resource_gui.DisplayCheckBox.stateChanged.connect(lambda: INSTANTIATE_DISPLAY())

        ####### Display GUI controlers

        #         self.displaygui.ColScroller.sliderMoved.connect(lambda:
        #                                                         self.ImDisplay.COL_SCROLLER_MOVE_UPDATE(self.displaygui))
        #         self.displaygui.ColSpinBox.valueChanged.connect(lambda:
        #                                                         self.ImDisplay.COL_SPINBOX_UPDATE(self.displaygui))

        #         self.displaygui.RowScroller.sliderMoved.connect(lambda:
        #                                                         self.ImDisplay.ROW_SCROLLER_MOVE_UPDATE(self.displaygui))

        #         self.displaygui.RowSpinBox.valueChanged.connect(lambda:
        #                                                         self.ImDisplay.ROW_SPINBOX_UPDATE(self.displaygui))

        #         self.displaygui.ZScroller.sliderMoved.connect(lambda:
        #                                                       self.ImDisplay.Z_SCROLLER_MOVE_UPDATE(self.displaygui))

        #         self.displaygui.ZSpinBox.valueChanged.connect(lambda:
        #                                                       self.ImDisplay.Z_SPINBOX_UPDATE(self.displaygui))

        #         self.displaygui.FOVScroller.sliderMoved.connect(lambda:
        #                                                         self.ImDisplay.FOV_SCROLLER_MOVE_UPDATE(self.displaygui))
        #         self.displaygui.FOVSpinBox.valueChanged.connect(lambda: self.ImDisplay.FOV_SPINBOX_UPDATE(self.displaygui))

        #         self.displaygui.TScroller.sliderMoved.connect(lambda: self.ImDisplay.T_SCROLLER_MOVE_UPDATE(self.displaygui))
        #         self.displaygui.TSpinBox.valueChanged.connect(lambda: self.ImDisplay.T_SPINBOX_UPDATE(self.displaygui))
        ###### CHANNELS CHECKBOXES
        self.displaygui.Ch1CheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.displaygui.Ch2CheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.displaygui.Ch3CheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.displaygui.Ch4CheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.displaygui.Ch5CheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))

        self.displaygui.Ch1maxproject.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.displaygui.Ch2maxproject.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.displaygui.Ch3maxproject.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.displaygui.Ch4maxproject.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.displaygui.Ch5maxproject.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))

        ###### histogram controllers
        self.displaygui.MaxHistSlider.sliderReleased.connect(
            lambda: self.ImDisplay.MAX_HIST_SLIDER_UPDATE(self.displaygui))

        self.displaygui.MinHistSlider.sliderReleased.connect(
            lambda: self.ImDisplay.MIN_HIST_SLIDER_UPDATE(self.displaygui))

        #         self.displaygui.MinHistSpinBox.valueChanged.connect(lambda:
        #                                                             self.ImDisplay.MIN_HIST_SPINBOX_UPDATE(self.displaygui))

        #         self.displaygui.MaxHistSpinBox.valueChanged.connect(lambda:
        #                                                             self.ImDisplay.MAX_HIST_SPINBOX_UPDATE(self.displaygui))

        ####### Nuclei and spot visualization controllers

        self.displaygui.NuclMaskCheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.NucDetectionSlider.sliderReleased.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.NucSeparationSlider.sliderReleased.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.NucleiAreaSlider.sliderReleased.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))

        self.analysisgui.NucDetectMethod.currentIndexChanged.connect(
            lambda: self.analysisgui.INITIALIZE_SEGMENTATION_PARAMETERS())
        self.analysisgui.NucDetectMethod.currentIndexChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))

        self.displaygui.NucPreviewMethod.currentIndexChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))

        self.displaygui.SpotsCheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))

        self.analysisgui.SpotCh1CheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.SpotCh2CheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.SpotCh3CheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.SpotCh4CheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.SpotCh5CheckBox.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))

        ####### Analysis Gui Controllers
        self.batchanalysis = BatchAnalyzer.BatchAnalysis(
            self.analysisgui, self.image_analyzer, self.inout_resource_gui)
        #self.analysisgui.NucMaxZprojectCheckBox.stateChanged.connect(lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.SpotMaxZProject.stateChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.RunAnalysis.clicked.connect(
            lambda: self.batchanalysis.ON_APPLYBUTTON(self.Meta_Data_df))

        self.analysisgui.ResetButton.clicked.connect(
            lambda: self.ON_RESET_BUTTON())
        self.analysisgui.ThresholdSlider.sliderReleased.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.SensitivitySpinBox.valueChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))
        self.analysisgui.spotanalysismethod.currentIndexChanged.connect(
            lambda: self.ImDisplay.GET_IMAGE_NAME(self.displaygui))

        self.analysisgui.ThresholdSlider.sliderReleased.connect(
            lambda: self.image_analyzer.UPDATE_SPOT_ANALYSIS_PARAMS())
        self.analysisgui.SensitivitySpinBox.valueChanged.connect(
            lambda: self.image_analyzer.UPDATE_SPOT_ANALYSIS_PARAMS())
        self.analysisgui.SpotPerChSpinBox.valueChanged.connect(
            lambda: self.image_analyzer.UPDATE_SPOT_ANALYSIS_PARAMS())
        self.analysisgui.spotanalysismethod.currentIndexChanged.connect(
            lambda: self.image_analyzer.UPDATE_SPOT_ANALYSIS_PARAMS())

        self.analysisgui.spotchannelselect.currentIndexChanged.connect(
            lambda: self.image_analyzer.UPDATE_SPOT_ANALYSIS_GUI_PARAMS())
        #  self.analysisgui.CloseButton.clicked.connect(self.closeEvent)
        ##################

        ####### Menu Bar

        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1000, 0))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        self.menuTool = QtWidgets.QMenu(self.menubar)
        self.menuTool.setObjectName("menuTool")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionLoad = QtWidgets.QMenu(self.menuFile)
        self.actionLoad.setObjectName("actionLoad")
        self.actionLoad_image = QtWidgets.QAction(self.actionLoad)
        self.actionLoad_image.setObjectName("actionLoad_image")
        self.LoadConfig = QtWidgets.QAction(MainWindow)
        self.LoadConfig.setObjectName("LoadConfig")
        self.saveConfig = QtWidgets.QAction(MainWindow)
        self.saveConfig.setObjectName("saveConfig")
        self.actionexit = QtWidgets.QAction(MainWindow)
        self.actionexit.setObjectName("actionexit")
        self.menuFile.addMenu(self.actionLoad)
        self.actionLoad.addAction(self.actionLoad_image)
        self.menuFile.addAction(self.actionexit)
        self.menuTool.addAction(self.LoadConfig)
        self.menuTool.addAction(self.saveConfig)
        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuTool.menuAction())

        self.saveConfig.triggered.connect(
            lambda: self.analysisgui.file_save(self.image_analyzer))
        self.LoadConfig.triggered.connect(
            lambda: self.analysisgui.LOAD_CONFIGURATION(self.image_analyzer))

        self.retranslateUi(MainWindow)
        self.analysisgui.AnalysisMode.setCurrentIndex(4)
        self.inout_resource_gui.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
Пример #5
0
import sys 
from PyQt5.QtWidgets import QApplication 
 
from GridLayout import * 
 
if __name__ == '__main__':
	a = QApplication(sys.argv)  
	form = GridLayout() 
	form.show() 
 
	a.exec_()