class MyColorDialog(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): col = QColor(0, 0, 0) self.btn = QPushButton('ColorDialog', self) self.btn.move(20, 20) self.btn.clicked.connect(self.showColorDialog) self.frame = QFrame(self) self.frame.move(150, 20) self.frame.setStyleSheet('QWidget {background-color: %s}' % col.name()) self.setGeometry(300, 300, 500, 400) self.setWindowTitle('Color Example') self.show() def showColorDialog(self): color = QColorDialog.getColor() print(color) print("type", type(color)) self.frame.setStyleSheet('QWidget {background-color: %s}' % color.name())
def initUI(self): self.setWindowTitle("liujinr") self.setGeometry(300, 100, 400, 300) myframe1 = QFrame(self) myframe1.move(50, 50) lbl_1 = QLabel("省", myframe1) lbl_1.move(0, 3) combox_1 = QComboBox(myframe1) combox_1.move(20, 0) # 省份 combox_1.addItem("请选择省份") combox_1.addItem("浙江") combox_1.addItem("江苏") combox_1.addItem("安徽") combox_1.addItem("北京") combox_1.activated[str].connect(self.myActived) # 这个[str]就像java中的泛型,可以指定传递数据的数据类型 lbl_1 = QLabel("市", myframe1) lbl_1.move(110, 3) # 市级别 self.combox_2 = QComboBox(myframe1) self.combox_2.move(125, 0) # 市份 # self.combox_2.addItem("请选择市份") # self.combox_2.addItem("沈阳") # self.combox_2.addItem("大连") # self.combox_2.addItem("西城") # self.combox_2.addItem("海淀") self.show()
class ExpressionForm(QFrame): def __init__(self, parent=None): super().__init__(parent) self.tableWidget = QTableWidget(self) self.setStyleSheet("background-color:transparent;") self.resize(1050, 700) self.move(0, 0) self.tableWidget.resize(500, 260) self.tableWidget.move(280, 200) self.frame = QFrame(self) self.frame.resize(500, 50) self.frame.move(280, 460) self.frame.setStyleSheet("background-color:white") self.make_icon() def make_icon(self): self.tableWidget.setShowGrid(False) self.tableWidget.verticalHeader().setVisible(False) self.tableWidget.horizontalHeader().setVisible(False) self.tableWidget.setStyleSheet(''' QTableWidget {border:10px solid white;background-color:white} QTableWidget:item:hover {background-color:rgb(230,230,230);}''') self.tableWidget.setRowCount(6) self.tableWidget.setColumnCount(12) self.tableWidget.setIconSize(QtCore.QSize(40, 40)) for i in range(6): self.tableWidget.setRowHeight(i, 40) for j in range(12): self.tableWidget.setColumnWidth(j, 40) head_pic = QTableWidgetItem() head_pic.setToolTip(expression_dic["10%d%d.png" % (i, j)]) icon = QtGui.QIcon("expression/fun/10%d%d.png" % (i, j)) head_pic.setIcon(QtGui.QIcon(icon)) self.tableWidget.setItem(i, j, head_pic)
def initUI(self): self.setWindowTitle(u'展示系统') self.resize(400, 300) #窗体居中 # self.move(desk.width()/2-self.width()/2,100) myframe = QFrame(self) lbltitle = QLabel('图像内容识别技术和对比挖掘在网站分析中的应用展示', myframe) lbl1 = QLabel('用户名:', myframe) lbl1.move(30, 30) lbl2 = QLabel('密 码:', myframe) lbl2.move(30, 60) self.leUsername = QLineEdit(myframe) self.lePassword = QLineEdit(myframe) self.leUsername.move(80, 30) self.lePassword.move(80, 60) self.lePassword.setEchoMode(QLineEdit.Password) btnLogin = QPushButton('登录', myframe) btnQuit = QPushButton('退出', myframe) btnLogin.move(30, 120) btnQuit.move(110, 120) btnLogin.clicked.connect(self.myBtnClick) btnQuit.clicked.connect(self.myBtnClick) myframe.move(50, 50) myframe.resize(300, 300) #隐藏放大缩小按钮 self.setWindowFlags(Qt.WindowCloseButtonHint) self.show()
class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): col = QColor(0, 0, 0) self.btn = QPushButton('Dialog', self) self.btn.move(60, 60) self.btn.clicked.connect(self.showDialog) self.frm = QFrame(self) self.frm.move(20, 20) print(col.name()) self.frm.setStyleSheet(f"QWidget {{background-color:{col.name()}}}") self.setGeometry(300, 300, 300, 300) self.setWindowTitle('input dialog') self.show() def showDialog(self): col = QColorDialog.getColor() if col.isValid(): self.frm.setStyleSheet( f"QWidget {{background-color:{col.name()}}}")
def initUI(self): self.setWindowTitle("下拉列表控件QComboBox") self.setGeometry(700, 300, 600, 500) myframe1 = QFrame(self) myframe1.move(50, 50) lbl_1 = QLabel("省", myframe1) lbl_1.move(0, 3) comBox1 = QComboBox(myframe1) comBox1.move(30, 0) # 传递字符串类型 comBox1.activated[str].connect(self.myActived) # 选择以后可以进行信号处理 # 省份 comBox1.addItem("选择省份") comBox1.addItem("广西") comBox1.addItem("广东") comBox1.addItem("福建") comBox1.addItem("北京") # 市级 lbl_2 = QLabel("市", myframe1) lbl_2.move(170, 3) self.comBox2 = QComboBox(myframe1) self.comBox2.move(200, 0) self.comBox2.activated[str].connect(self.myActived2) self.show()
class LeftFrame(QFrame): def __init__(self, father, top): super().__init__(father) self.setObjectName('api_frame') self.father, self.top = father, top self.setGeometry(0, 0, 150, 300) self.all_api = self.top.all_api[1:] self.now_api = self.all_api[0] self.inside_frame = QFrame(self) self.inside_frame.resize(self.width(), len(self.all_api)*55+5) self.inside_frame.move(0, 0) self.inside_frame.setObjectName('inside') for idx in range(len(self.all_api)): label = ApiLabel(self.all_api[idx], self, self.top) label.move(7, idx*55+5) def wheelEvent(self, e): if self.inside_frame.height() > self.height(): if e.angleDelta().y() > 0: self.inside_frame.move(0, self.inside_frame.y() + 60) if self.inside_frame.y() > 0: self.inside_frame.move(0, 0) else: self.inside_frame.move(0, self.inside_frame.y() - 60) if self.inside_frame.y() < self.height()-self.inside_frame.height(): self.inside_frame.move(0, self.height()-self.inside_frame.height()) self.father.list_scroll.bar.setValue(abs(self.inside_frame.y()))
def __init__(self, dispositivoCamara, parent=None): super(Widgets, self).__init__(parent) self.parent = parent self.estadoFoto = False self.byteArrayFoto = QByteArray() # ========================================================== frame = QFrame(self) frame.setFrameShape(QFrame.Box) frame.setFrameShadow(QFrame.Sunken) frame.setFixedWidth(505) frame.setFixedHeight(380) frame.move(10, 10) # Instancias self.paginaVisor = QVideoWidget() self.paginaVisor.resize(500, 375) self.visor = QCameraViewfinder(self.paginaVisor) self.visor.resize(500, 375) self.labelFoto = QLabel() self.labelFoto.setAlignment(Qt.AlignCenter) self.labelFoto.resize(500, 375) # QStackedWidget self.stackedWidget = QStackedWidget(frame) self.stackedWidget.addWidget(self.paginaVisor) self.stackedWidget.addWidget(self.labelFoto) self.stackedWidget.resize(500, 375) self.stackedWidget.move(2, 2) # ======================== BOTONES ========================= self.buttonTomarFoto = QPushButton("Tomar foto", self) self.buttonTomarFoto.resize(110, 26) self.buttonTomarFoto.move(525, 10) self.buttonEliminarFoto = QPushButton("Eliminar foto", self) self.buttonEliminarFoto.resize(110, 26) self.buttonEliminarFoto.move(525, 50) self.buttonGuardarFoto = QPushButton("Guardar foto", self) self.buttonGuardarFoto.resize(110, 26) self.buttonGuardarFoto.move(525, 82) # ======================== EVENTOS ========================= self.buttonTomarFoto.clicked.connect(self.tomarFoto) self.buttonEliminarFoto.clicked.connect(self.eliminarFoto) self.buttonGuardarFoto.clicked.connect(self.guardarFoto) # ================== FUNCIONES AUTOMÁTICAS ================= self.setCamara(dispositivoCamara)
def initUi(self): self.setWindowTitle("编程") self.resize(600, 800) myFrame = QFrame(self) self.cb1 = QCheckBox('dance', myFrame) self.cb1.stateChanged[int].connect(self.mychange) self.cb2 = QCheckBox('sing', myFrame) self.cb2.stateChanged[int].connect(self.mychange) self.cb2.move(0, 30) myFrame.move(100, 100) self.show()
def sign_up_window(self): self.sign_up_win.setWindowIcon(self.icon) self.sign_up_win.move(self.x() + 100, self.y() + 100) # 移动一下注册窗口,以免和之前的重复 frame = QFrame(self.sign_up_win) self.sign_up_win.setWindowFlag(Qt.Dialog) frame.resize(1000, 300) frame.setStyleSheet('background-image: url("./IMG/python.png"); background-repeat: no-repeat;') frame.move(40, 150) # 打开注册窗口时,清除原来的信息 self.password_edit.setText('') self.username_edit.setText('') self.sign_up_win.show()
def __init__(self, parent=None): super(Main_Ayuda, self).__init__(parent) self.setWindowTitle("EXADATA (AYUDA)") self.setFixedSize(800, 600) self.setWindowIcon(QIcon("icono.jpg")) # FRAME paleta = QPalette() paleta.setColor(QPalette.Background, QColor(51, 0, 102)) frame = QFrame(self) frame.setFrameShape(QFrame.NoFrame) frame.setFrameShadow(QFrame.Sunken) frame.setAutoFillBackground(True) frame.setPalette(paleta) frame.setFixedWidth(800) frame.setFixedHeight(100) frame.move(0, 0) labelIcono = QLabel(frame) labelIcono.setFixedWidth(65) labelIcono.setFixedHeight(65) labelIcono.setPixmap( QPixmap("icono.jpg").scaled(65, 65, Qt.KeepAspectRatio, Qt.SmoothTransformation)) labelIcono.move(10, 28) fuenteTitulo = QFont() fuenteTitulo.setPointSize(25) fuenteTitulo.setBold(True) labelTitulo = QLabel("<font color='white'>EXADATA</font>", frame) labelTitulo.setFont(fuenteTitulo) labelTitulo.move(85, 30) fuenteSubtitulo = QFont() fuenteSubtitulo.setPointSize(13) labelSubtitulo = QLabel("<font color='white'>Análisis de Tweets ", frame) labelSubtitulo.setFont(fuenteSubtitulo) labelSubtitulo.move(85, 68) # LOGO self.centralwidget = QtWidgets.QWidget(self) self.setCentralWidget(self.centralwidget) # CUADRO TEXTO self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget) self.textBrowser.setGeometry(QtCore.QRect(10, 110, 780, 480))
def initUI(self): self.setWindowTitle("liujnikjnyubainchedng") self.setGeometry(400, 100, 400, 300) myframe1 = QFrame(self) myframe1.move(30, 0) self.ck1 = QCheckBox("跳舞", myframe1) self.ck1.stateChanged[int].connect(self.myState) self.ck1.move(0, 50) self.ck2 = QCheckBox("唱歌", myframe1) self.ck2.stateChanged[int].connect(self.myState) self.ck2.move(0, 30) self.show()
def initUI(self): self.setWindowTitle("复选框QCheckBox") self.setGeometry(650, 300, 600, 500) myframe1 = QFrame(self) self.ck1 = QCheckBox("请点击我", myframe1) btn = QPushButton("退出", myframe1) btn.move(0, 100) # 信号与槽 self.ck1.stateChanged[int].connect(self.myState) # 定义一个变量,用来存储关闭窗口的判断条件 self.status = "" btn.clicked.connect(self.clickQuit) # 主窗口的退出按钮 myframe1.move(50, 50) self.show()
def initUI(self): self.setWindowTitle("复选框QCheckBox") self.setGeometry(650, 300, 600, 500) myframe1 = QFrame(self) self.ck1 = QCheckBox("唱歌", myframe1) self.ck2 = QCheckBox("跳舞", myframe1) btn = QPushButton("退出", myframe1) self.ck2.move(0, 50) btn.move(0, 100) self.ck1.stateChanged[int].connect(self.myState) self.ck2.stateChanged[int].connect(self.myState) btn.clicked.connect(self.close) # 退出按钮 myframe1.move(50, 50) self.show()
def initUI(self): frame = QFrame(self) frame.setFrameShape(QFrame.Box) frame.setFrameShadow(QFrame.Sunken) frame.setAutoFillBackground(True) frame.setFixedSize(450, 500) frame.move(0, 0) label = QLabel(frame) label.setPixmap(QPixmap("Imagenes/siacle.jpg").scaled(447, 447, Qt.KeepAspectRatio, Qt.SmoothTransformation)) label.move(1, 1) botonConfigurar = QPushButton("Информация", frame) botonConfigurar.setFixedSize(430, 32) botonConfigurar.move(10, 457) botonConfigurar.clicked.connect(self.Configuracion)
def findText(self): def Find(): flag = None if r1.isChecked(): self.form_widget.tab.currentWidget().findFirst( l.text(), True, cs.isChecked(), True, False, False) flag = self.form_widget.tab.currentWidget().findNext() elif r2.isChecked(): flag = self.form_widget.tab.currentWidget().findFirst( l.text(), True, cs.isChecked(), True, False) if not flag: QMessageBox.information(self, 'TextPad', 'Match not found', QMessageBox.Ok, QMessageBox.Ok) d = QDialog(self) d.setWindowTitle('Find') d.setWindowIcon(QIcon('icon.png')) d.setFixedSize(300, 130) label = QLabel("What to find", d) label.move(10, 5) l = QLineEdit(d) l.move(100, 5) b1 = QPushButton("Find Next", d) b1.move(210, 5) b1.clicked.connect(Find) b2 = QPushButton("Cancel", d) b2.move(210, 35) b2.clicked.connect(d.close) cs = QCheckBox("Case sensitive", d) cs.move(10, 62) f = QFrame(d) f.setFixedSize(120, 40) f.move(120, 59) f.setToolTip('Direction') r1 = QRadioButton("Up", f) r1.move(5, 5) r2 = QRadioButton("Down", f) r2.setChecked(True) r2.move(55, 5) d.show()
class ChooseRandom(QDialog): def __init__(self, father, top): super().__init__(father, Qt.WindowCloseButtonHint) self.father, self.top = father, top self.setWindowTitle('随机选项') self.setObjectName('choose_random') self.move(self.father.x()+self.father.width()//2-200, self.father.y()+self.father.height()//2-150) self.list = LeftFrame(self, top) self.list_scroll = ScrollFrame(self, self.list, 140) self.color_frame = QFrame(self) self.color_frame.setObjectName('choose_mid') self.color_frame.move(155, 0) self.tags = RightFrame(self, top) self.tags.move(186, 0) self.tags_scroll = ScrollFrame(self, self.tags, 165) self.resize(500, 300) self.setMinimumSize(500, 300) def showEvent(self, e): self.move(self.father.x()+self.father.width()//2-self.width()//2, self.father.y()+self.father.height()//2-self.height()//2) def resizeEvent(self, e): self.list.resize(self.list.width(), self.height()) self.color_frame.resize(3, self.height()) self.tags.resize(self.width() - 190, self.height()) for w in [self.list_scroll, self.tags_scroll]: w.resize(8, self.height()) def resize_(self): self.tags.resize_() for w in [self.list_scroll, self.tags_scroll]: w.resize_()
class Window(QWidget): def __init__(self): super().__init__() self.selected_color_old = QColor(0, 0, 255) self.initUI() def initUI(self): btn = QPushButton() btn.resize(btn.sizeHint()) btn.clicked.connect(self.showColorDialog) self.frame = QFrame(self) self.frame.resize(100, 100) self.frame.move(50, 50) self.frame.setStyleSheet("QWidget {background-color: %s}" % self.selected_color_old.name()) def showColorDialog(self): selected_color = QColorDialog.getColor() if selected_color != self.selected_color_old: self.selected_color_old
def setupUI(self, animarBotones): paleta = QPalette() paleta.setColor(QPalette.Background, QColor(0, 0, 93)) frame = QFrame(self) frame.setFrameShape(QFrame.NoFrame) frame.setFrameShadow(QFrame.Sunken) frame.setAutoFillBackground(True) frame.setPalette(paleta) frame.setFixedWidth(400) frame.setFixedHeight(84) frame.move(0, 0) labelIcono = QLabel(frame) labelIcono.setFixedWidth(40) labelIcono.setFixedHeight(40) labelIcono.setPixmap( QPixmap("mundo.png").scaled(40, 40, Qt.KeepAspectRatio, Qt.SmoothTransformation)) labelIcono.move(37, 22) fuenteTitulo = QFont() fuenteTitulo.setPointSize(16) fuenteTitulo.setBold(True) labelTitulo = QLabel("<font color='white'>BIENVENIDO</font>", frame) labelTitulo.setFont(fuenteTitulo) labelTitulo.move(83, 20) frameUsuario = QFrame(self) frameUsuario.setFrameShape(QFrame.StyledPanel) frameUsuario.setFixedWidth(100) frameUsuario.setFixedHeight(28) frameUsuario.move(90, 50) self.lineEditUsuario1 = QLineEdit(frameUsuario) self.lineEditUsuario1.setReadOnly(True) self.lineEditUsuario1.setFrame(False) self.lineEditUsuario1.setTextMargins(8, 0, 4, 1) self.lineEditUsuario1.setFixedWidth(100) self.lineEditUsuario1.setFixedHeight(26) self.lineEditUsuario1.move(0, 1) fuenteSubtitulo = QFont() fuenteSubtitulo.setPointSize(9) labelSubtitulo = QLabel("<font color='white'" "(Python).</font>", frame) labelSubtitulo.setFont(fuenteSubtitulo) labelSubtitulo.move(111, 46) self.button = ui_menu(self) self.button.setText("MIS CURSOS") self.button.setCursor(Qt.PointingHandCursor) self.button.setAutoDefault(False) self.button.setGeometry(40, 150, 160, 60) self.button.clicked.connect(self.abrirmenuuser) self.buttonDos = ui_menu(self) self.buttonDos.setText("UNIRSE A \nUN CURSO") self.buttonDos.setCursor(Qt.PointingHandCursor) self.buttonDos.setAutoDefault(False) self.buttonDos.setGeometry(220, 150, 160, 60) self.buttonDos.clicked.connect(self.openanadirclase)
def initui(self): palette = QPalette() palette.setColor(QPalette.Background, QColor(100, 100, 100)) # ************ Header ************ # ------------ Frame ---------- frame = QFrame(self) frame.setFrameShape(QFrame.NoFrame) frame.setFrameShadow(QFrame.Sunken) frame.setAutoFillBackground(True) frame.setPalette(palette) frame.setFixedWidth(800) frame.setFixedHeight(84) frame.move(0, 0) # ------------ Icon ---------- label_icon = QLabel(frame) label_icon.setFixedWidth(40) label_icon.setFixedHeight(40) label_icon.setPixmap( QPixmap("./images/LoginIcon.png").scaled(40, 40, Qt.KeepAspectRatio, Qt.SmoothTransformation)) label_icon.move(57, 22) # ------------ Tittle ---------- tittle_font = QFont() tittle_font.setPixelSize(16) tittle_font.setBold(True) tittle_label = QLabel("<font color='white'> Ariadna </rfont>", frame) tittle_label.setFont(tittle_font) tittle_label.move(103, 20) # ------------ Sub Tittle ---------- sub_tittle_font = QFont() sub_tittle_font.setPointSize(9) sub_tittle_label = QLabel( "<font color='white'> Labyrinth Solver </font>", frame) sub_tittle_label.setFont(sub_tittle_font) sub_tittle_label.move(111, 46) # ************ Body ************ # ------------ Frame ---------- instructions_frame = QFrame(self) instructions_frame.setFrameShape(QFrame.NoFrame) instructions_frame.setFrameShadow(QFrame.Sunken) instructions_frame.setAutoFillBackground(False) instructions_frame.setFixedWidth(300) instructions_frame.setFixedHeight(500) instructions_frame.move(0, 84) # ---------- Instructions ---------- instructions_font = QFont() instructions_font.setPointSize(9) instructions_label = QLabel( "<font style='font-family:times new roman;font-size:15px;' color='white'><b> " "<br/>Pre-resquisitos:" "<br/><br/>Para que la imagen pueda ser " "<br/>reconocida por el sistema, el " "<br/>laberinto debe ser dibujado en " "<br/>una hoja blanca con un marcador o" "<br/>esfero de color negro y debe tener" "<br/>una forma rectangular." "<br/><br/>Pasos:" "<br/><br/>1. Seleccionar la opcion " "<br/>'Nuevo Laberinto'." "<br/><br/>2. Seleccionar la opcion " "<br/>'Cargar laberinto', en esta opcion se." "<br/>soluciona el laberinto de manera " "<br/>automatica." "</b></font>", instructions_frame) instructions_label.setFont(instructions_font) instructions_label.move(20, 20) # ---------- Buttons ---------- back_main_menu_button = QPushButton("Volver al Menu Principal", self) back_main_menu_button.setFixedWidth(200) back_main_menu_button.setFixedHeight(28) back_main_menu_button.move(300, 660) # ---------- Button's Events ---------- back_main_menu_button.clicked.connect(self.back_main_menu)
def initUI(self): labelTitulo = QLabel("CAPTURA DE ", self) labelTitulo.setFont(QFont("MS Shell Dlg 2", 11)) labelTitulo.setStyleSheet('color:white') labelTitulo.move(300, 10) labelTitulo2 = QLabel("ALUMNOS", self) labelTitulo2.setFont(QFont("MS Shell Dlg 2", 11)) labelTitulo2.setStyleSheet('color:white') labelTitulo2.move(390, 10) buttonGuardar = QPushButton("Grabar", self) buttonGuardar.setFixedWidth(135) buttonGuardar.setFixedHeight(28) buttonGuardar.move(150, 500) buttonGuardar.setIcon(QIcon("save.png")) buttonGuardar.setIconSize(QtCore.QSize(30, 30)) buttonEscribir = QPushButton("Escribir", self) buttonEscribir.setFixedWidth(135) buttonEscribir.setFixedHeight(28) buttonEscribir.move(310, 500) buttonEscribir.setIcon(QIcon("excel.png")) buttonEscribir.setIconSize(QtCore.QSize(25, 25)) buttonLimpiar = QPushButton("Limpiar", self) buttonLimpiar.setFixedWidth(135) buttonLimpiar.setFixedHeight(28) buttonLimpiar.move(470, 500) buttonLimpiar.setIcon(QIcon("limpiar.png")) buttonLimpiar.setIconSize(QtCore.QSize(25, 25)) buttonGuardar.clicked.connect(self.guardar) buttonEscribir.clicked.connect(self.escribir) buttonLimpiar.clicked.connect(self.limpiar) labelNombre = QLabel("Nombre", self) labelNombre.setFont(QFont("MS Shell Dlg 2", 9)) labelNombre.setStyleSheet('color:white') labelNombre.move(7, 60) frameNombre = QFrame(self) frameNombre.setFixedWidth(285) frameNombre.setFixedHeight(28) frameNombre.move(60, 60) self.lineEditNombre = QLineEdit(frameNombre) self.lineEditNombre.setFrame(True) self.lineEditNombre.setTextMargins(7, 1, 6, 1) self.lineEditNombre.setFixedWidth(245) self.lineEditNombre.setFixedHeight(29) self.lineEditNombre.move(40, 1) labelApellido_Paterno = QLabel("Apellido Paterno", self) labelApellido_Paterno.setFont(QFont("MS Shell Dlg 2", 9)) labelApellido_Paterno.setStyleSheet('color:white') labelApellido_Paterno.setLineWidth(8) labelApellido_Paterno.move(7, 120) frameApellido_Paterno = QFrame(self) frameApellido_Paterno.setFixedWidth(290) frameApellido_Paterno.setFixedHeight(29) frameApellido_Paterno.move(60, 120) self.lineEditApellido_Paterno = QLineEdit(frameApellido_Paterno) self.lineEditApellido_Paterno.setFrame(True) self.lineEditApellido_Paterno.setTextMargins(7, 1, 6, 1) self.lineEditApellido_Paterno.setFixedWidth(245) self.lineEditApellido_Paterno.setFixedHeight(29) self.lineEditApellido_Paterno.move(40, 1) labelApellido_Materno = QLabel("Apellido Materno", self) labelApellido_Materno.setFont(QFont("MS Shell Dlg 2", 9)) labelApellido_Materno.setStyleSheet('color:white') labelApellido_Materno.move(7, 180) frameApellido_Materno = QFrame(self) frameApellido_Materno.setFixedWidth(290) frameApellido_Materno.setFixedHeight(29) frameApellido_Materno.move(60, 180) self.lineEditApellido_Materno = QLineEdit(frameApellido_Materno) self.lineEditApellido_Materno.setFrame(True) self.lineEditApellido_Materno.setTextMargins(7, 1, 6, 1) self.lineEditApellido_Materno.setFixedWidth(245) self.lineEditApellido_Materno.setFixedHeight(29) self.lineEditApellido_Materno.move(40, 1) labelMatricula = QLabel("Matrícula", self) labelMatricula.setFont(QFont("MS Shell Dlg 2", 9)) labelMatricula.setStyleSheet('color:white') labelMatricula.move(7, 240) frameMatricula = QFrame(self) frameMatricula.setFixedWidth(290) frameMatricula.setFixedHeight(29) frameMatricula.move(60, 240) self.lineEditMatricula = QLineEdit(frameMatricula) self.lineEditMatricula.setFrame(True) self.lineEditMatricula.setTextMargins(7, 1, 6, 1) self.lineEditMatricula.setFixedWidth(245) self.lineEditMatricula.setFixedHeight(29) self.lineEditMatricula.move(40, 1) self.lineEditMatricula.setValidator(QIntValidator()) labelEdad = QLabel("Edad", self) labelEdad.setFont(QFont("MS Shell Dlg 2", 9)) labelEdad.setStyleSheet('color:white') labelEdad.move(7, 300) frameEdad = QFrame(self) frameEdad.setFixedWidth(290) frameEdad.setFixedHeight(29) frameEdad.move(60, 300) self.lineEditEdad = QLineEdit(frameEdad) self.lineEditEdad.setFrame(True) self.lineEditEdad.setTextMargins(7, 1, 6, 1) self.lineEditEdad.setFixedWidth(245) self.lineEditEdad.setFixedHeight(29) self.lineEditEdad.move(40, 1) self.lineEditEdad.setValidator(QIntValidator()) labelCalle = QLabel("Calle y Numero", self) labelCalle.setFont(QFont("MS Shell Dlg 2", 9)) labelCalle.setStyleSheet('color:white') labelCalle.move(7, 360) frameCalle = QFrame(self) frameCalle.setFixedWidth(290) frameCalle.setFixedHeight(29) frameCalle.move(60, 360) self.lineEditCalle = QLineEdit(frameCalle) self.lineEditCalle.setFrame(True) self.lineEditCalle.setTextMargins(7, 1, 6, 1) self.lineEditCalle.setFixedWidth(245) self.lineEditCalle.setFixedHeight(29) self.lineEditCalle.move(40, 1) labelMunicipio = QLabel("Municipio", self) labelMunicipio.setFont(QFont("MS Shell Dlg 2", 9)) labelMunicipio.setStyleSheet('color:white') labelMunicipio.move(515, 60) self.comboBoxMunicipio = QComboBox(self) self.comboBoxMunicipio.addItems([ "Apodaca", "Cadereyta Jimenez", "Escobedo", "Garcia", "Guadalupe", "Juarez", "Monterrey", "Salinas Victoria", "San Nicolas de los Garza", "San Pedro Garza Garcia", "Santa Catarina", "Santiago", "Cienega de Flores", "General Zuazua", "Pesqueria" ]) self.comboBoxMunicipio.setCurrentIndex(-1) self.comboBoxMunicipio.setFixedWidth(290) self.comboBoxMunicipio.setFixedHeight(29) self.comboBoxMunicipio.move(400, 95) labelEstado = QLabel("Estado", self) labelEstado.setFont(QFont("MS Shell Dlg 2", 9)) labelEstado.setStyleSheet('color:white') labelEstado.move(515, 150) self.comboBoxEstado = QComboBox(self) self.comboBoxEstado.addItems(["Nuevo Leon"]) self.comboBoxEstado.setCurrentIndex(-1) self.comboBoxEstado.setFixedWidth(290) self.comboBoxEstado.setFixedHeight(29) self.comboBoxEstado.move(400, 175) labelBeca = QLabel("BECA %", self) labelBeca.setFont(QFont("MS Shell Dlg 2", 9)) labelBeca.setStyleSheet('color:white') labelBeca.move(515, 240) self.radio_cero = QRadioButton('0%', self) self.radio_cero.setStyleSheet('color:white') self.radio_cero.move(400, 270) self.radio_25 = QRadioButton('25%', self) self.radio_25.setStyleSheet('color:white') self.radio_25.move(470, 270) self.radio_50 = QRadioButton('50%', self) self.radio_50.setStyleSheet('color:white') self.radio_50.move(540, 270) self.radio_cien = QRadioButton('100%', self) self.radio_cien.setStyleSheet('color:white') self.radio_cien.move(610, 270) self.Programacionbox = QCheckBox('Progra', self) self.Programacionbox.move(380, 340) self.Programacionbox.setFont(QFont("MS Shell Dlg 2", 9)) self.Programacionbox.setStyleSheet('color:white') label_macion = QLabel("macion", self) label_macion.setFont(QFont("MS Shell Dlg 2", 9)) label_macion.setStyleSheet('color:white') label_macion.move(434, 340) self.Contabilidadbox = QCheckBox('Contabilidad', self) self.Contabilidadbox.move(500, 340) self.Contabilidadbox.setFont(QFont("MS Shell Dlg 2", 9)) self.Contabilidadbox.setStyleSheet('color:white') self.boxEstadistica = QCheckBox('Estadistica', self) self.boxEstadistica.move(610, 340) self.boxEstadistica.setFont(QFont("MS Shell Dlg 2", 9)) self.boxEstadistica.setStyleSheet('color:white') self.Basebox = QCheckBox('Base de Datos', self) self.Basebox.move(380, 370) self.Basebox.setFont(QFont("MS Shell Dlg 2", 9)) self.Basebox.setStyleSheet('color:white') self.Investigacionbox = QCheckBox('Investigación', self) self.Investigacionbox.move(500, 370) self.Investigacionbox.setFont(QFont("MS Shell Dlg 2", 9)) self.Investigacionbox.setStyleSheet('color:white') Investigacion_label = QLabel("de Operaciones", self) Investigacion_label.move(595, 370) Investigacion_label.setFont(QFont("MS Shell Dlg 2", 9)) Investigacion_label.setStyleSheet('color:white')
def initui(self): palette = QPalette() palette.setColor(QPalette.Background, QColor(100, 100, 100)) # ************ Header ************ # ------------ Frame ---------- frame = QFrame(self) frame.setFrameShape(QFrame.NoFrame) frame.setFrameShadow(QFrame.Sunken) frame.setAutoFillBackground(True) frame.setPalette(palette) frame.setFixedWidth(500) frame.setFixedHeight(84) frame.move(0, 0) # ------------ Icon ---------- label_icon = QLabel(frame) label_icon.setFixedWidth(40) label_icon.setFixedHeight(40) label_icon.setPixmap( QPixmap("./images/LoginIcon.png").scaled(40, 40, Qt.KeepAspectRatio, Qt.SmoothTransformation)) label_icon.move(57, 22) # ------------ Tittle ---------- tittle_font = QFont() tittle_font.setPixelSize(16) tittle_font.setBold(True) tittle_label = QLabel("<font color='white'> Ariadna Sign In </rfont>", frame) tittle_label.setFont(tittle_font) tittle_label.move(103, 20) # ------------ Sub Tittle ---------- sub_tittle_font = QFont() sub_tittle_font.setPointSize(9) sub_tittle_label = QLabel( "<font color='white'> Labyrinth Solver </font>", frame) sub_tittle_label.setFont(sub_tittle_font) sub_tittle_label.move(111, 46) # ************ Login ************ # ---------- User ---------- user_label = QLabel('Usuario', self) user_label.move(90, 110) user_frame = QFrame(self) user_frame.setFrameShape(QFrame.StyledPanel) user_frame.setFixedWidth(338) user_frame.setFixedHeight(28) user_frame.move(90, 136) user_icon = QLabel(user_frame) user_icon.setPixmap( QPixmap("./images/UserIcon.png").scaled(20, 20, Qt.KeepAspectRatio, Qt.SmoothTransformation)) user_icon.move(10, 4) self.line_edit_user = QLineEdit(user_frame) self.line_edit_user.setFrame(False) self.line_edit_user.setTextMargins(8, 0, 4, 1) self.line_edit_user.setFixedWidth(297) self.line_edit_user.setFixedHeight(26) self.line_edit_user.move(40, 1) # ---------- Password ---------- password_label = QLabel("Contraseña", self) password_label.move(90, 170) password_frame = QFrame(self) password_frame.setFrameShape(QFrame.StyledPanel) password_frame.setFixedWidth(338) password_frame.setFixedHeight(28) password_frame.move(90, 196) password_icon = QLabel(password_frame) password_icon.setPixmap( QPixmap("./images/PasswordIcon.png").scaled( 20, 20, Qt.KeepAspectRatio, Qt.SmoothTransformation)) password_icon.move(10, 4) self.line_edit_password = QLineEdit(password_frame) self.line_edit_password.setFrame(False) self.line_edit_password.setEchoMode(QLineEdit.Password) self.line_edit_password.setTextMargins(8, 0, 4, 1) self.line_edit_password.setFixedWidth(297) self.line_edit_password.setFixedHeight(26) self.line_edit_password.move(40, 1) # ---------- Confirm Password ---------- confirm_password_label = QLabel("Confirmar Contraseña", self) confirm_password_label.move(90, 224) confirm_password_frame = QFrame(self) confirm_password_frame.setFrameShape(QFrame.StyledPanel) confirm_password_frame.setFixedWidth(338) confirm_password_frame.setFixedHeight(28) confirm_password_frame.move(90, 250) confirm_password_icon = QLabel(confirm_password_frame) confirm_password_icon.setPixmap( QPixmap("./images/PasswordIcon.png").scaled( 20, 20, Qt.KeepAspectRatio, Qt.SmoothTransformation)) confirm_password_icon.move(10, 4) self.line_edit_confirm_password = QLineEdit(confirm_password_frame) self.line_edit_confirm_password.setFrame(False) self.line_edit_confirm_password.setEchoMode(QLineEdit.Password) self.line_edit_confirm_password.setTextMargins(8, 0, 4, 1) self.line_edit_confirm_password.setFixedWidth(297) self.line_edit_confirm_password.setFixedHeight(26) self.line_edit_confirm_password.move(40, 1) # ---------- Buttons ---------- sign_in_button = QPushButton("Registrarse", self) sign_in_button.setFixedWidth(175) sign_in_button.setFixedHeight(28) sign_in_button.move(170, 300) login_button = QPushButton("Volver a Login", self) login_button.setFixedWidth(175) login_button.setFixedHeight(28) login_button.move(170, 334) cancel_button = QPushButton("Cancelar", self) cancel_button.setFixedWidth(135) cancel_button.setFixedHeight(28) cancel_button.move(192, 368) # ---------- Button's Events ---------- sign_in_button.clicked.connect(self.sign_in) login_button.clicked.connect(self.login) cancel_button.clicked.connect(self.close)
def initUI(self): # ==================== FRAME ENCABEZADO ==================== paleta = QPalette() paleta.setColor(QPalette.Background, QColor(51, 0, 102)) frame = QFrame(self) frame.setFrameShape(QFrame.NoFrame) frame.setFrameShadow(QFrame.Sunken) frame.setAutoFillBackground(True) frame.setPalette(paleta) frame.setFixedWidth(400) frame.setFixedHeight(84) frame.move(0, 0) labelIcono = QLabel(frame) labelIcono.setFixedWidth(40) labelIcono.setFixedHeight(40) labelIcono.setPixmap( QPixmap("icono.png").scaled(40, 40, Qt.KeepAspectRatio, Qt.SmoothTransformation)) labelIcono.move(37, 22) fuenteTitulo = QFont() fuenteTitulo.setPointSize(16) fuenteTitulo.setBold(True) labelTitulo = QLabel("<font color='white'>Login</font>", frame) labelTitulo.setFont(fuenteTitulo) labelTitulo.move(83, 20) # ===================== WIDGETS LOGIN ====================== # ======================================================== labelUsuario = QLabel("Usuario", self) labelUsuario.move(60, 120) frameUsuario = QFrame(self) frameUsuario.setFrameShape(QFrame.StyledPanel) frameUsuario.setFixedWidth(280) frameUsuario.setFixedHeight(28) frameUsuario.move(60, 146) self.lineEditUsuario = QLineEdit(frameUsuario) self.lineEditUsuario.setFrame(False) self.lineEditUsuario.setTextMargins(8, 0, 4, 1) self.lineEditUsuario.setFixedWidth(238) self.lineEditUsuario.setFixedHeight(26) self.lineEditUsuario.move(40, 1) # ======================================================== labelContrasenia = QLabel("Contraseña", self) labelContrasenia.move(60, 174) frameContrasenia = QFrame(self) frameContrasenia.setFrameShape(QFrame.StyledPanel) frameContrasenia.setFixedWidth(280) frameContrasenia.setFixedHeight(28) frameContrasenia.move(60, 200) self.lineEditContrasenia = QLineEdit(frameContrasenia) self.lineEditContrasenia.setFrame(False) self.lineEditContrasenia.setEchoMode(QLineEdit.Password) self.lineEditContrasenia.setTextMargins(8, 0, 4, 1) self.lineEditContrasenia.setFixedWidth(238) self.lineEditContrasenia.setFixedHeight(26) self.lineEditContrasenia.move(40, 1) labelToken = QLabel("Token", self) labelToken.move(60, 224) frameToken = QFrame(self) frameToken.setFrameShape(QFrame.StyledPanel) frameToken.setFixedWidth(280) frameToken.setFixedHeight(28) frameToken.move(60, 250) self.lineEditToken = QLineEdit(frameToken) self.lineEditToken.setFrame(False) self.lineEditToken.setEchoMode(QLineEdit.Password) self.lineEditToken.setTextMargins(8, 0, 4, 1) self.lineEditToken.setFixedWidth(238) self.lineEditToken.setFixedHeight(26) self.lineEditToken.move(40, 1) # ================== WIDGETS QPUSHBUTTON =================== buttonLogin = QPushButton("Iniciar sesión", self) buttonLogin.setFixedWidth(135) buttonLogin.setFixedHeight(28) buttonLogin.move(60, 286) buttonCancelar = QPushButton("Cancelar", self) buttonCancelar.setFixedWidth(135) buttonCancelar.setFixedHeight(28) buttonCancelar.move(205, 286) # ==================== MÁS INFORMACIÓN ===================== # ==================== SEÑALES BOTONES ===================== buttonLogin.clicked.connect(self.Login) buttonCancelar.clicked.connect(self.close)
class mainWindow(QMainWindow): def __init__(self, parent=None): QMainWindow.__init__(self) self.setFixedSize(900, 600) self.setWindowTitle("RecoveryContable") self.setStyleSheet(backgroundMain) self.initModel() def initModel(self): # Status Bar ------------------------------------- self.statusBar = QFrame(self) self.statusBar.setGeometry(QRect(0, 0, 200, 600)) self.statusBar.setStyleSheet(statusBarFrame) self.statusBar.move(0, 0) self.title = QLabel(self.statusBar) self.title.setGeometry(QRect(0, 0, 150, 100)) self.title.setText("RecoveryLoid") self.title.setStyleSheet(titleStyle) self.title.setFont(QtGui.QFont("Roboto", 17, QtGui.QFont.Bold)) self.title.move(30, 0) self.buttonArrow = QPushButton(self) self.buttonArrow.setGeometry(QRect(0, 0, 30, 45)) self.buttonArrow.move(200, 100) self.buttonArrow.setStyleSheet(buttonArrowStatusBar) self.buttonArrow.setIcon(QIcon("arrow white-1.svg")) self.buttonArrow.clicked.connect(self.slide) self.buttonArrowDown = QPushButton(self.statusBar) self.buttonArrowDown.setGeometry(QRect(0, 0, 30, 45)) self.buttonArrowDown.move(170, 100) self.buttonArrowDown.setStyleSheet(buttonArrowStatusBarDown) self.buttonArrowDown.setIcon(QIcon("arrow-white.png")) self.buttonArrowDown.clicked.connect(self.slideDown) self.buttonPago = QPushButton(self.statusBar) self.buttonPago.setGeometry(QRect(0, 0, 200, 40)) self.buttonPago.move(0, 200) self.buttonPago.setText("PAGO") self.buttonPago.setStyleSheet(buttonStatusBar) self.buttonPago.setFont(QtGui.QFont("Roboto", 14, QtGui.QFont.Bold)) self.buttonRetiro = QPushButton(self.statusBar) self.buttonRetiro.setGeometry(QRect(0, 0, 200, 40)) self.buttonRetiro.move(0, 245) self.buttonRetiro.setText("RETIRO") self.buttonRetiro.setStyleSheet(buttonStatusBar) self.buttonRetiro.setFont(QtGui.QFont("Roboto", 14, QtGui.QFont.Bold)) self.buttonAcerca = QPushButton(self.statusBar) self.buttonAcerca.setGeometry(QRect(0, 0, 100, 40)) self.buttonAcerca.move(50, 500) self.buttonAcerca.setText("Acerca de") self.buttonAcerca.setStyleSheet(buttonAcercade) self.buttonAcerca.setFont( QtGui.QFont("Roboto", 11, QtGui.QFont.Condensed)) # Frame Estadisticas self.statisticFrame = QFrame(self) self.statisticFrame.setGeometry(QRect(0, 0, 500, 400)) self.statisticFrame.move(300, 100) self.statisticFrame.setStyleSheet(statisticStatusFrame) self.statisticTitle = QLabel(self) self.statisticTitle.setText("ESTADÍSTICAS") self.statisticTitle.setFont(QtGui.QFont("Roboto", 25, QtGui.QFont.Bold)) self.statisticTitle.setGeometry(QRect(0, 0, 500, 100)) self.statisticTitle.move(450, 0) self.statisticTitle.setStyleSheet(titleStyle) self.buttonEstadoArrow = QPushButton(self) self.buttonEstadoArrow.setGeometry(QRect(0, 0, 40, 40)) self.buttonEstadoArrow.move(260, 50) self.buttonEstadoArrow.setIcon(QIcon("arrow white-1.svg")) self.buttonEstadoArrow.setStyleSheet(universalArrowSlide) self.buttonEstadoArrow.clicked.connect(self.slideToState) self.buttonLibroArrow = QPushButton(self) self.buttonLibroArrow.setGeometry(QRect(0, 0, 40, 40)) self.buttonLibroArrow.move(800, 50) self.buttonLibroArrow.setIcon(QIcon("arrow-white.png")) self.buttonLibroArrow.setStyleSheet(universalArrowSlide) self.buttonLibroArrow.clicked.connect(self.slideToBook) self.statisticTotal = QLabel(self.statisticFrame) self.statisticTotal.setText("Total") self.statisticTotal.setFont(QtGui.QFont("Roboto", 15, QtGui.QFont.Bold)) self.statisticTotal.setGeometry(QRect(0, 0, 100, 100)) self.statisticTotal.move(350, 0) self.statisticTotal.setStyleSheet(statisticLetter) self.statisticRecovery = QLabel(self.statisticFrame) self.statisticRecovery.setText("RecoveryLoid") self.statisticRecovery.setFont( QtGui.QFont("Roboto", 15, QtGui.QFont.Bold)) self.statisticRecovery.setGeometry(QRect(0, 0, 150, 100)) self.statisticRecovery.move(100, 0) self.statisticRecovery.setStyleSheet(statisticLetter) self.statisticLine = QLabel(self.statisticFrame) self.statisticLine.setText("---------------->") self.statisticLine.setFont(QtGui.QFont("Roboto", 15, QtGui.QFont.Bold)) self.statisticLine.setGeometry(QRect(0, 0, 150, 100)) self.statisticLine.move(100, 50) self.statisticLine.setStyleSheet(statisticLetter) self.statisticMount = QLabel(self.statisticFrame) self.statisticMount.setText("0.00" + "$") self.statisticMount.setFont(QtGui.QFont("Roboto", 15, QtGui.QFont.Thin)) self.statisticMount.setGeometry(QRect(0, 0, 100, 100)) self.statisticMount.move(350, 50) self.statisticMount.setStyleSheet(statisticLetter) self.statisticMount = QLabel(self.statisticFrame) self.statisticMount.setGeometry(QRect(0, 0, 100, 2)) self.statisticMount.move(325, 70) self.statisticMount.setStyleSheet(statisticSeparata) # Frame Libro self.bookFrame = QFrame(self) self.bookFrame.setGeometry(QRect(0, 0, 700, 400)) self.bookFrame.move(5000, 100) self.bookFrame.setStyleSheet(statisticStatusFrame) self.buttonArrowInBook = QPushButton(self) self.buttonArrowInBook.setGeometry(QRect(0, 0, 40, 40)) self.buttonArrowInBook.move(260, 5000) self.buttonArrowInBook.setIcon(QIcon("arrow white-1.svg")) self.buttonArrowInBook.setStyleSheet(universalArrowSlide) self.buttonArrowInBook.clicked.connect(self.fromBookToStatistic) nameColumns = ("Ref", "Fecha", "Descripción", "Ingreso/Egreso", "Monto Actual") self.bookTable = QTableWidget(self.bookFrame) self.bookTable.setToolTip("Transacción") self.bookTable.setGeometry(QRect(0, 0, 600, 400)) self.bookTable.setStyleSheet(bookQTable) self.bookTable.setEditTriggers(QAbstractItemView.NoEditTriggers) self.bookTable.setDragDropOverwriteMode(False) self.bookTable.setSelectionBehavior(QAbstractItemView.SelectRows) self.bookTable.setSelectionMode(QAbstractItemView.SingleSelection) self.bookTable.setTextElideMode(Qt.ElideRight) self.bookTable.setWordWrap(False) self.bookTable.setSortingEnabled(False) self.bookTable.setColumnCount(5) self.bookTable.setRowCount(0) self.bookTable.horizontalHeader().setDefaultAlignment(Qt.AlignHCenter | Qt.AlignVCenter | Qt.AlignCenter) self.bookTable.horizontalHeader().setHighlightSections(False) self.bookTable.horizontalHeader().setStretchLastSection(True) self.bookTable.verticalHeader().setVisible(False) self.bookTable.setAlternatingRowColors(False) self.bookTable.verticalHeader().setDefaultSectionSize(20) self.bookTable.setHorizontalHeaderLabels(nameColumns) for index, large in enumerate((110, 110, 110, 110, 130), start=0): self.bookTable.setColumnWidth(index, large) # Frame State self.stateFrame = QFrame(self) self.stateFrame.setGeometry(QRect(0, 0, 500, 400)) self.stateFrame.move(5000, 100) self.stateFrame.setStyleSheet(statisticStatusFrame) self.buttonArrowInState = QPushButton(self) self.buttonArrowInState.setGeometry(QRect(0, 0, 40, 40)) self.buttonArrowInState.move(800, 5000) self.buttonArrowInState.setIcon(QIcon("arrow-white.png")) self.buttonArrowInState.setStyleSheet(universalArrowSlide) self.buttonArrowInState.clicked.connect(self.fromStateToStatistic) # Slide de libro a estadisticas def fromBookToStatistic(self): self.statisticTitle.setText("ESTADÍSTICAS") # Previous Frame self.animationSlidePreviousFrame = QPropertyAnimation( self.bookFrame, b"geometry") self.animationSlidePreviousFrame.finished.connect(lambda: (self.bookFrame)) self.animationSlidePreviousFrame.setDuration(900) self.animationSlidePreviousFrame.setStartValue( QRect(300, 100, 500, 400)) self.animationSlidePreviousFrame.setEndValue(QRect( 5000, 100, 500, 400)) self.animationSlidePreviousFrame.start( QAbstractAnimation.DeleteWhenStopped) # ArrowInState self.animationSlideArrowInState = QPropertyAnimation( self.buttonArrowInBook, b"geometry") self.animationSlideArrowInState.finished.connect( lambda: (self.buttonArrowInBook)) self.animationSlideArrowInState.setDuration(900) self.animationSlideArrowInState.setStartValue(QRect(250, 50, 40, 40)) self.animationSlideArrowInState.setEndValue(QRect(5000, 50, 40, 40)) self.animationSlideArrowInState.start( QAbstractAnimation.DeleteWhenStopped) # Next Frame self.animationSlideFrame = QPropertyAnimation(self.statisticFrame, b"geometry") self.animationSlideFrame.finished.connect(lambda: (self.statisticFrame)) self.animationSlideFrame.setDuration(900) self.animationSlideFrame.setStartValue(QRect(-5000, 100, 500, 400)) self.animationSlideFrame.setEndValue(QRect(300, 100, 500, 400)) self.animationSlideFrame.start(QAbstractAnimation.DeleteWhenStopped) # Arrows self.animationSlideArrow = QPropertyAnimation(self.buttonEstadoArrow, b"geometry") self.animationSlideArrow.finished.connect(lambda: (self.buttonEstadoArrow)) self.animationSlideArrow.setDuration(900) self.animationSlideArrow.setStartValue(QRect(-5000, 50, 40, 40)) self.animationSlideArrow.setEndValue(QRect(260, 50, 40, 40)) self.animationSlideArrow.start(QAbstractAnimation.DeleteWhenStopped) self.animationSlideArrow2 = QPropertyAnimation(self.buttonLibroArrow, b"geometry") self.animationSlideArrow2.finished.connect(lambda: (self.buttonLibroArrow)) self.animationSlideArrow2.setDuration(900) self.animationSlideArrow2.setStartValue(QRect(-5000, 50, 40, 40)) self.animationSlideArrow2.setEndValue(QRect(800, 50, 40, 40)) self.animationSlideArrow2.start(QAbstractAnimation.DeleteWhenStopped) return True # Slide de Stado a estadisticas def fromStateToStatistic(self): self.statisticTitle.setText("ESTADÍSTICAS") self.statisticTitle.move(450, 0) # Previous Frame self.animationSlidePreviousFrame = QPropertyAnimation( self.stateFrame, b"geometry") self.animationSlidePreviousFrame.finished.connect(lambda: (self.stateFrame)) self.animationSlidePreviousFrame.setDuration(900) self.animationSlidePreviousFrame.setStartValue( QRect(300, 100, 500, 400)) self.animationSlidePreviousFrame.setEndValue( QRect(-5000, 100, 500, 400)) self.animationSlidePreviousFrame.start( QAbstractAnimation.DeleteWhenStopped) self.animationSlideArrowState = QPropertyAnimation( self.buttonArrowInState, b"geometry") self.animationSlideArrowState.finished.connect( lambda: (self.buttonArrowInState)) self.animationSlideArrowState.setDuration(900) self.animationSlideArrowState.setStartValue(QRect(800, 50, 40, 40)) self.animationSlideArrowState.setEndValue(QRect(-5000, 50, 40, 40)) self.animationSlideArrowState.start( QAbstractAnimation.DeleteWhenStopped) # Next Frame self.animationSlideFrame = QPropertyAnimation(self.statisticFrame, b"geometry") self.animationSlideFrame.finished.connect(lambda: (self.statisticFrame)) self.animationSlideFrame.setDuration(900) self.animationSlideFrame.setStartValue(QRect(5000, 100, 500, 400)) self.animationSlideFrame.setEndValue(QRect(300, 100, 500, 400)) self.animationSlideFrame.start(QAbstractAnimation.DeleteWhenStopped) # Arrows self.animationSlideArrow = QPropertyAnimation(self.buttonEstadoArrow, b"geometry") self.animationSlideArrow.finished.connect(lambda: (self.buttonEstadoArrow)) self.animationSlideArrow.setDuration(900) self.animationSlideArrow.setStartValue(QRect(5000, 50, 40, 40)) self.animationSlideArrow.setEndValue(QRect(260, 50, 40, 40)) self.animationSlideArrow.start(QAbstractAnimation.DeleteWhenStopped) self.animationSlideArrow2 = QPropertyAnimation(self.buttonLibroArrow, b"geometry") self.animationSlideArrow2.finished.connect(lambda: (self.buttonLibroArrow)) self.animationSlideArrow2.setDuration(900) self.animationSlideArrow2.setStartValue(QRect(5000, 50, 40, 40)) self.animationSlideArrow2.setEndValue(QRect(800, 50, 40, 40)) self.animationSlideArrow2.start(QAbstractAnimation.DeleteWhenStopped) return True # Slide a libro def slideToBook(self): self.statisticTitle.setText("Libro de Registro") self.statisticTitle.move(400, 0) # Previous Frame self.animationSlidePreviousFrame = QPropertyAnimation( self.statisticFrame, b"geometry") self.animationSlidePreviousFrame.finished.connect( lambda: (self.statisticFrame)) self.animationSlidePreviousFrame.setDuration(900) self.animationSlidePreviousFrame.setStartValue( QRect(300, 100, 500, 400)) self.animationSlidePreviousFrame.setEndValue( QRect(-5000, 100, 500, 400)) self.animationSlidePreviousFrame.start( QAbstractAnimation.DeleteWhenStopped) # Arrows self.animationSlideArrow = QPropertyAnimation(self.buttonEstadoArrow, b"geometry") self.animationSlideArrow.finished.connect(lambda: (self.buttonEstadoArrow)) self.animationSlideArrow.setDuration(900) self.animationSlideArrow.setStartValue(QRect(260, 50, 40, 40)) self.animationSlideArrow.setEndValue(QRect(-5000, 100, 40, 40)) self.animationSlideArrow.start(QAbstractAnimation.DeleteWhenStopped) self.animationSlideArrow2 = QPropertyAnimation(self.buttonLibroArrow, b"geometry") self.animationSlideArrow2.finished.connect(lambda: (self.buttonLibroArrow)) self.animationSlideArrow2.setDuration(900) self.animationSlideArrow2.setStartValue(QRect(800, 50, 40, 40)) self.animationSlideArrow2.setEndValue(QRect(-5000, 50, 40, 40)) self.animationSlideArrow2.start(QAbstractAnimation.DeleteWhenStopped) # Next Frame self.animationSlideFrame = QPropertyAnimation(self.bookFrame, b"geometry") self.animationSlideFrame.finished.connect(lambda: (self.bookFrame)) self.animationSlideFrame.setDuration(900) self.animationSlideFrame.setStartValue(QRect(5000, 100, 500, 400)) self.animationSlideFrame.setEndValue(QRect(200, 100, 600, 400)) self.animationSlideFrame.start(QAbstractAnimation.DeleteWhenStopped) self.animationSlideArrowInState = QPropertyAnimation( self.buttonArrowInBook, b"geometry") self.animationSlideArrowInState.finished.connect( lambda: (self.buttonArrowInBook)) self.animationSlideArrowInState.setDuration(900) self.animationSlideArrowInState.setStartValue(QRect(5000, 50, 40, 40)) self.animationSlideArrowInState.setEndValue(QRect(250, 50, 40, 40)) self.animationSlideArrowInState.start( QAbstractAnimation.DeleteWhenStopped) return True # Slide a Estado def slideToState(self): self.statisticTitle.setText("ESTADO") self.statisticTitle.move(500, 0) # Previous Frame self.animationSlidePreviousFrame = QPropertyAnimation( self.statisticFrame, b"geometry") self.animationSlidePreviousFrame.finished.connect( lambda: (self.statisticFrame)) self.animationSlidePreviousFrame.setDuration(900) self.animationSlidePreviousFrame.setStartValue( QRect(300, 100, 500, 400)) self.animationSlidePreviousFrame.setEndValue(QRect( 5000, 100, 500, 400)) self.animationSlidePreviousFrame.start( QAbstractAnimation.DeleteWhenStopped) # Arrows self.animationSlideArrow = QPropertyAnimation(self.buttonEstadoArrow, b"geometry") self.animationSlideArrow.finished.connect(lambda: (self.buttonEstadoArrow)) self.animationSlideArrow.setDuration(900) self.animationSlideArrow.setStartValue(QRect(260, 50, 40, 40)) self.animationSlideArrow.setEndValue(QRect(5000, 100, 40, 40)) self.animationSlideArrow.start(QAbstractAnimation.DeleteWhenStopped) self.animationSlideArrow2 = QPropertyAnimation(self.buttonLibroArrow, b"geometry") self.animationSlideArrow2.finished.connect(lambda: (self.buttonLibroArrow)) self.animationSlideArrow2.setDuration(900) self.animationSlideArrow2.setStartValue(QRect(800, 50, 40, 40)) self.animationSlideArrow2.setEndValue(QRect(5000, 50, 40, 40)) self.animationSlideArrow2.start(QAbstractAnimation.DeleteWhenStopped) # Next Frame self.animationSlideFrame = QPropertyAnimation(self.stateFrame, b"geometry") self.animationSlideFrame.finished.connect(lambda: (self.stateFrame)) self.animationSlideFrame.setDuration(900) self.animationSlideFrame.setStartValue(QRect(-5000, 100, 500, 400)) self.animationSlideFrame.setEndValue(QRect(300, 100, 500, 400)) self.animationSlideFrame.start(QAbstractAnimation.DeleteWhenStopped) self.animationSlideArrowState = QPropertyAnimation( self.buttonArrowInState, b"geometry") self.animationSlideArrowState.finished.connect( lambda: (self.buttonArrowInState)) self.animationSlideArrowState.setDuration(900) self.animationSlideArrowState.setStartValue(QRect(-5000, 50, 40, 40)) self.animationSlideArrowState.setEndValue(QRect(800, 50, 40, 40)) self.animationSlideArrowState.start( QAbstractAnimation.DeleteWhenStopped) return True # Slides Status bar def slide(self): # Titulo self.title.setText("RC") self.title.move(10, 0) # statusBar self.animationSlide = QPropertyAnimation(self.statusBar, b"geometry") self.animationSlide.finished.connect(lambda: (self.statusBar)) self.animationSlide.setDuration(900) self.animationSlide.setStartValue(QRect(0, 0, 200, 600)) self.animationSlide.setEndValue(QRect(0, 0, 50, 600)) self.animationSlide.start(QAbstractAnimation.DeleteWhenStopped) # Flecha self.animationSlideArrow = QPropertyAnimation(self.buttonArrow, b"geometry") self.animationSlideArrow.finished.connect(lambda: (self.buttonArrow)) self.animationSlideArrow.setDuration(900) self.animationSlideArrow.setStartValue(QRect(200, 100, 30, 45)) self.animationSlideArrow.setEndValue(QRect(50, 100, 30, 45)) self.animationSlideArrow.start(QAbstractAnimation.DeleteWhenStopped) # FlechaDown self.animationSlideArrowDown = QPropertyAnimation( self.buttonArrowDown, b"geometry") self.animationSlideArrowDown.finished.connect(lambda: (self.buttonArrowDown)) self.animationSlideArrowDown.setDuration(900) self.animationSlideArrowDown.setStartValue(QRect(170, 100, 30, 45)) self.animationSlideArrowDown.setEndValue(QRect(20, 100, 30, 45)) self.animationSlideArrowDown.start( QAbstractAnimation.DeleteWhenStopped) # Pago self.animationSlidePago = QPropertyAnimation(self.buttonPago, b"geometry") self.animationSlidePago.finished.connect(lambda: (self.buttonPago)) self.animationSlidePago.setDuration(900) self.animationSlidePago.setStartValue(QRect(0, 200, 200, 40)) self.animationSlidePago.setEndValue(QRect(0, 200, 50, 40)) self.animationSlidePago.start(QAbstractAnimation.DeleteWhenStopped) self.buttonPago.setText("P") # Retiro self.animationSlideRetiro = QPropertyAnimation(self.buttonRetiro, b"geometry") self.animationSlideRetiro.finished.connect(lambda: (self.buttonRetiro)) self.animationSlideRetiro.setDuration(900) self.animationSlideRetiro.setStartValue(QRect(0, 245, 200, 40)) self.animationSlideRetiro.setEndValue(QRect(0, 245, 50, 40)) self.animationSlideRetiro.start(QAbstractAnimation.DeleteWhenStopped) self.buttonRetiro.setText("R") # Acerca self.animationSlideAcerca = QPropertyAnimation(self.buttonAcerca, b"geometry") self.animationSlideAcerca.finished.connect(lambda: (self.buttonAcerca)) self.animationSlideAcerca.setDuration(900) self.animationSlideAcerca.setStartValue(QRect(50, 500, 100, 40)) self.animationSlideAcerca.setEndValue(QRect(0, 500, 50, 40)) self.animationSlideAcerca.start(QAbstractAnimation.DeleteWhenStopped) self.buttonAcerca.setText("Ac") def slideDown(self): # Titulo self.title.setText("RecoveryLoid") self.title.move(30, 0) # statusBar self.animationSlide = QPropertyAnimation(self.statusBar, b"geometry") self.animationSlide.finished.connect(lambda: (self.statusBar)) self.animationSlide.setDuration(900) self.animationSlide.setStartValue(QRect(0, 0, 50, 600)) self.animationSlide.setEndValue(QRect(0, 0, 200, 600)) self.animationSlide.start(QAbstractAnimation.DeleteWhenStopped) # Flecha self.animationSlideArrow = QPropertyAnimation(self.buttonArrow, b"geometry") self.animationSlideArrow.finished.connect(lambda: (self.buttonArrow)) self.animationSlideArrow.setDuration(900) self.animationSlideArrow.setStartValue(QRect(50, 100, 30, 45)) self.animationSlideArrow.setEndValue(QRect(200, 100, 30, 45)) self.animationSlideArrow.start(QAbstractAnimation.DeleteWhenStopped) # FlechaDown self.animationSlideArrowDown = QPropertyAnimation( self.buttonArrowDown, b"geometry") self.animationSlideArrowDown.finished.connect(lambda: (self.buttonArrowDown)) self.animationSlideArrowDown.setDuration(900) self.animationSlideArrowDown.setStartValue(QRect(30, 100, 30, 45)) self.animationSlideArrowDown.setEndValue(QRect(170, 100, 30, 45)) self.animationSlideArrowDown.start( QAbstractAnimation.DeleteWhenStopped) # Pago self.animationSlidePago = QPropertyAnimation(self.buttonPago, b"geometry") self.animationSlidePago.finished.connect(lambda: (self.buttonPago)) self.animationSlidePago.setDuration(900) self.animationSlidePago.setStartValue(QRect(0, 200, 50, 40)) self.animationSlidePago.setEndValue(QRect(0, 200, 200, 40)) self.animationSlidePago.start(QAbstractAnimation.DeleteWhenStopped) self.buttonPago.setText("PAGO") # Retiro self.animationSlideRetiro = QPropertyAnimation(self.buttonRetiro, b"geometry") self.animationSlideRetiro.finished.connect(lambda: (self.buttonRetiro)) self.animationSlideRetiro.setDuration(900) self.animationSlideRetiro.setStartValue(QRect(0, 245, 50, 40)) self.animationSlideRetiro.setEndValue(QRect(0, 245, 200, 40)) self.animationSlideRetiro.start(QAbstractAnimation.DeleteWhenStopped) self.buttonRetiro.setText("RETIRO") # Acerca self.animationSlideAcerca = QPropertyAnimation(self.buttonAcerca, b"geometry") self.animationSlideAcerca.finished.connect(lambda: (self.buttonAcerca)) self.animationSlideAcerca.setDuration(900) self.animationSlideAcerca.setStartValue(QRect(0, 500, 50, 40)) self.animationSlideAcerca.setEndValue(QRect(50, 500, 100, 40)) self.animationSlideAcerca.start(QAbstractAnimation.DeleteWhenStopped) self.buttonAcerca.setText("Acerca de") return True
class window(QWidget): def __init__(self, parent=None): super(window, self).__init__() self.worker = predict_worker(parent=self) self.init_ui() def init_ui(self): self.setFixedHeight(600) self.setFixedWidth(450) self.setWindowTitle("MNIST Digit Prediction") self.hasDrawing = False self.mouseHeld = False self.path = drawing_path() self.rect = QRect(0, 50, 400, 400) self.label = QLabel("Click and hold the left mouse button to draw.", self) self.label.move(25, 10) self.label.setFixedWidth(300) self.label2 = QLabel("Classifications include numerals (0-9).", self) self.label2.move(25, 35) self.label2.setFixedWidth(300) self.results = QLabel("Results will appear here", self) self.results.move(25, 540) self.results.setFixedWidth(300) self.result_label = QLabel("", self) self.result_label.move(330, 490) self.clear_button = QPushButton("Clear", self) self.clear_button.move(330, 535) self.clear_button.clicked.connect(self.clear) self.upper_line = QFrame(self) self.upper_line.setFrameShape(QFrame.HLine) self.upper_line.move(25, 85) self.upper_line.setFixedWidth(400) self.lower_line = QFrame(self) self.lower_line.setFrameShape(QFrame.HLine) self.lower_line.move(25, 485) self.lower_line.setFixedWidth(400) self.left_line = QFrame(self) self.left_line.setFrameShape(QFrame.VLine) self.left_line.move(-25, 100) self.left_line.setFixedHeight(400) self.right_line = QFrame(self) self.right_line.setFrameShape(QFrame.VLine) self.right_line.move(375, 100) self.right_line.setFixedHeight(400) self.show() def clear(self): self.path.clear_path() self.update() def mousePressEvent(self, event): x = event.x() y = event.y() self.path.clear_path() if 100 < y < 500: if 25 < x < 425: if self.hasDrawing == True: self.path.clear() self.mouseHeld = True position = event.pos() self.path.add_point(x, y) self.results.setText("Position = " + str(position)) return else: self.results.setText("Position out of range") self.mouseHeld = False return self.mouseHeld = False self.results.setText("Position out of range") return def mouseMoveEvent(self, event): x = event.x() y = event.y() if 100 < y < 500: if 25 < x < 425: if self.mouseHeld == True: position = event.pos() self.path.add_point(x, y) self.results.setText("Position = " + str(position)) self.update() return else: self.results.setText("Position out of range") else: self.results.setText("Position out of range") def paintEvent(self, event): painter = QPainter() painter.begin(self) last_x = 0 last_y = 0 for x, y in list(zip(self.path.x_pos, self.path.y_pos)): if last_x == 0: last_x = x last_y = y else: painter.drawLine(last_x, last_y, x, y) last_x = x last_y = y # painter.drawLine(self.last_x, self.last_y, self.cur_x, self.cur_y) painter.end() def mouseReleaseEvent(self, event): self.mouseHeld = False if len(self.path.x_pos) < 4: return self.results.setText("Processing Data...") self.worker.process_data(self.path) def update_label(self, text): self.results.setText(text)
class Example(QWidget): trigger = QtCore.pyqtSignal() def __init__(self, parent=None): super().__init__(parent, QtCore.Qt.Window) self.top_warehouse = QFrame(self) self.top_warehouse.setFrameShape(QFrame.StyledPanel) self.top_warehouse.resize(584, 75) self.top_warehouse.move(8, 10) self.top_route = QFrame(self) self.top_route.setFrameShape(QFrame.StyledPanel) self.top_route.resize(584, 170) self.top_route.move(8, 88) self.top_supply = QFrame(self) self.top_supply.setFrameShape(QFrame.StyledPanel) self.top_supply.resize(285, 110) self.top_supply.move(10, 92) self.top_consumption = QFrame(self) self.top_consumption.setFrameShape(QFrame.StyledPanel) self.top_consumption.resize(286, 110) self.top_consumption.move(304, 92) self.combo_route = QComboBox(self) self.combo_route.addItems(['1', '2', '3']) self.combo_route.move(150, 220) self.combo_route.resize(self.combo_route.sizeHint()) """ Data entry for supply """ pars = parsing_tuple() self.combo_supply = QComboBox(self) self.combo_supply.addItems(pars) self.combo_weight_party = QComboBox(self) self.combo_weight_party.addItems(['20', '30', '40']) self.date_supply = QDateTimeEdit() vbox = QVBoxLayout() layout = QHBoxLayout(self) layout.addLayout(vbox) layout.addWidget(self.combo_supply) layout.addWidget(self.combo_weight_party) layout.addWidget(self.date_supply) layout.addStretch(1) """ Data entry for warehouse """ self.combo_warehouse = QComboBox(self) self.combo_warehouse.addItems(pars) self.combo_warehouse.move(150, 30) self.combo_warehouse.resize(self.combo_warehouse.sizeHint()) self.lbl_warehouse = QLabel("Склады", self) self.lbl_warehouse.move(300, 30) """ Data entry for consumption """ self.combo_consumption = QComboBox(self) self.combo_consumption.addItems(pars) self.date_consumption = QDateTimeEdit() layout.addWidget(self.combo_consumption) layout.addWidget(self.date_consumption) self.check_route() self.check_warehouse() self.initUI() def initUI(self): btn_input = QPushButton('Ввести значения', self) btn_input.resize(btn_input.sizeHint()) btn_input.move(420, 220) btn_input.clicked.connect(self.get_supply_consumption) btn_delete_route = QPushButton('Удалить маршруты', self) btn_delete_route.resize(btn_delete_route.sizeHint()) btn_delete_route.move(310, 220) btn_delete_route.clicked.connect(self.delete_route) btn_delete_warehouse = QPushButton('Удалить склады', self) btn_delete_warehouse.resize(btn_delete_warehouse.sizeHint()) btn_delete_warehouse.move(490, 55) btn_delete_warehouse.clicked.connect(self.delete_warehouse) btn_add_warehouse = QPushButton('Добавить склад', self) btn_add_warehouse.resize(btn_delete_route.sizeHint()) btn_add_warehouse.move(40, 30) btn_add_warehouse.clicked.connect(self.update_warehouse) lbl_route = QLabel("Маршрут:", self) lbl_route.resize(lbl_route.sizeHint()) lbl_route.move(100, 220) lbl_supply = QLabel("Точка поставки", self) lbl_supply.resize((lbl_supply.sizeHint())) lbl_supply.move(90, 93) lbl_consupmtion = QLabel("Точка потребления", self) lbl_consupmtion.resize(lbl_consupmtion.sizeHint()) lbl_consupmtion.move(450, 93) lbl_supply_point = QLabel("Пункт", self) lbl_supply_point.resize(lbl_supply_point.sizeHint()) lbl_supply_point.move(25, 115) lbl_weight_party = QLabel("Вес партии", self) lbl_weight_party.resize(lbl_weight_party.sizeHint()) lbl_weight_party.move(70, 115) lbl_date_departure = QLabel("Дата отправления", self) lbl_date_departure.resize(lbl_date_departure.sizeHint()) lbl_date_departure.move(145, 115) lbl_consumption_point = QLabel("Пункт", self) lbl_consumption_point.resize(lbl_consumption_point.sizeHint()) lbl_consumption_point.move(420, 115) lbl_date_arrival = QLabel("Дата прибытия", self) lbl_date_arrival.resize(lbl_date_arrival.sizeHint()) lbl_date_arrival.move(490, 115) self.setGeometry(300, 300, 600, 300) self.setWindowTitle('Выбрать параметры поставки груза') def check_route(self): routs, session = session_getting_route() before_route = 0 for route in routs: if before_route != route.num_route: self.combo_route.removeItem(route.num_route - 1) before_route = route.num_route session.close() def delete_warehouse(self): session_delete_warehouse() self.check_warehouse() pars = parsing_tuple() self.combo_warehouse.clear() self.combo_supply.clear() self.combo_consumption.clear() self.combo_warehouse.addItems(pars) self.combo_supply.addItems(pars) self.combo_consumption.addItems(pars) def delete_route(self): """ delete data before use program :return: nothing """ session_clear_field() self.trigger.emit() pars = parsing_tuple() self.combo_warehouse.clear() self.combo_supply.clear() self.combo_consumption.clear() self.combo_route.clear() self.combo_warehouse.addItems(pars) self.combo_supply.addItems(pars) self.combo_consumption.addItems(pars) main() self.combo_route.addItems(['1', '2', '3']) def check_warehouse(self): str_warehouse = 'Склады:' name_warehouse = session_get_warehouse() for warehouse in name_warehouse: str_warehouse = str_warehouse + warehouse.name_point + ',' self.lbl_warehouse.setText(str_warehouse) self.lbl_warehouse.adjustSize() def update_warehouse(self): warehouse = self.combo_warehouse.currentText() session_add_warehouse(warehouse) self.check_warehouse() pars = parsing_tuple() self.combo_warehouse.clear() self.combo_supply.clear() self.combo_consumption.clear() self.combo_warehouse.addItems(pars) self.combo_supply.addItems(pars) self.combo_consumption.addItems(pars) def get_supply_consumption(self): """ Data collection from forms :return: nothing """ supply = self.combo_supply.currentText() consumption = self.combo_consumption.currentText() route = self.combo_route.currentText() date_arrival = datetime.datetime( int(self.date_consumption.dateTime().toString("yyyy")), int(self.date_consumption.dateTime().toString("MM")), int(self.date_consumption.dateTime().toString("dd")), int(self.date_consumption.dateTime().toString("hh"))) date_departure = datetime.datetime( int(self.date_supply.dateTime().toString("yyyy")), int(self.date_supply.dateTime().toString("MM")), int(self.date_supply.dateTime().toString("dd")), int(self.date_supply.dateTime().toString("hh"))) weight = int(self.combo_weight_party.currentText()) loading = loading_party(weight) id_supply, num_party, empty_truck = session_create2( weight=weight, supply=supply, date=date_departure, loading=loading) unloading = unloading_party(weight) travel_time = date_arrival - date_departure id_consumption = session_add_consumption(consumption=consumption, date=date_arrival, unloading=unloading, party=num_party, travel_time=travel_time.days, weight=weight) agent = session_get_next_point() parsing(agent) if travel_time.days > 1: optimal_route, warehouse_point = search_route_warehouse( id_supply, id_consumption) session_add_warehouse_party(optimal_route, warehouse_point, num_party, loading, unloading) else: optimal_route = dijkstra(id_supply, id_consumption) lst_pars = lst_optimal(optimal_route) session_add_route(lst_pars, route, id_supply, empty_truck) update_graphic() self.trigger.emit() self.check_route()
class LineFrame(QFrame): def __init__(self, father, top, name, space=1, text=''): super().__init__(father) self.setProperty('cate', 'line_frame') self.father, self.top, self.index = father, top, name self.width_ = self.top.size_[0] self.setObjectName(str(name)) self.space = 1 self.origin_text = text self.origin_space = space - 1 self.color_index = name % len(self.father.color_list) self.hide_list = [] self.edit_lock = False self.init() def init(self): self.left_frame = QFrame(self) left_layout = QVBoxLayout(self.left_frame) self.time_label = QLabel( '<b>%s:%s0</b>' % (self.index // 2, (self.index % 2) * 3), self.left_frame) self.color_button = QPushButton(' ', self.left_frame) self.color_button.setFixedSize(30, 20) self.color_button.clicked.connect(self.change_color) self.color_button.setProperty('cate', 'palette') if (self.index % 2) == 0: self.time_label.setProperty('cate', 'hour') else: self.time_label.setProperty('cate', 'minute') self.time_label.setFixedSize(45, 20) left_layout.addWidget(self.time_label, alignment=Qt.AlignTop) left_layout.addWidget(self.color_button, alignment=Qt.AlignCenter) self.left_frame.setLayout(left_layout) self.left_frame.move(0, 0) self.edit = QTextEdit(self) self.edit.selectionChanged.connect(self.align_) self.edit.move(60, 0) self.right_frame = QFrame(self) btn_layout = QVBoxLayout(self.right_frame) self.add_button = QPushButton('', self.right_frame) self.del_button = QPushButton('', self.right_frame) self.add_button.setProperty('cate', 'add') self.del_button.setProperty('cate', 'del') self.add_button.clicked.connect(lambda: self.add_del('a')) self.del_button.clicked.connect(lambda: self.add_del('d')) self.add_button.setFixedSize(30, 30) self.del_button.setFixedSize(30, 30) btn_layout.addWidget(self.add_button, alignment=Qt.AlignCenter) btn_layout.addWidget(self.del_button, alignment=Qt.AlignCenter) self.right_frame.setLayout(btn_layout) self.right_frame.move(self.top.size_[0] - 60, 0) self.refresh() self.change_color() # 初始化edit内容和行占位 def init_height(self): self.edit.setText(self.origin_text) self.edit.setTextColor(QColor(0, 0, 0)) while self.origin_space > 0: self.origin_space -= 1 self.add_del('a') self.edit.setAlignment(Qt.AlignHCenter) # 随时改变居中 def align_(self): if not self.edit_lock: self.edit_lock = True self.edit.setAlignment(Qt.AlignHCenter) self.edit_lock = False # 打开/关闭编辑 def alter(self, do, old_space=None): if do: self.right_frame.show() self.edit.verticalScrollBar().show() self.color_button.show() self.add_button.show() self.edit.setEnabled(True) width = 0.72 if self.space > 1: self.del_button.show() else: self.del_button.hide() else: self.right_frame.hide() self.edit.verticalScrollBar().hide() self.color_button.hide() self.edit.setEnabled(False) width = 0.83 if old_space: self.size_animal(self.edit, old_space, self.space, self.top.size_[0] * width, (60, 0), (60, 0)) else: self.edit.setGeometry(60, 0, self.top.size_[0] * width, 50 * self.space) self.edit.setAlignment(Qt.AlignHCenter) # 增减行占位 def add_del(self, what): old_space = self.space if what == 'a' and self.space < 22: c = self.father.update_line(self.index + self.space, True) self.space += c elif what == 'd' and self.space > 1: self.space -= 1 self.father.update_line(self.index + self.space, False) self.refresh(old_space=old_space, active=True) # 隐藏行 def hide_(self): old_space = self.space self.space = 0 self.refresh(old_space=old_space) return old_space # 显示行 def show_(self): self.space = 1 self.refresh(old_space=0, active=True) # 更新行大小 def refresh(self, old_space=None, active=False): if not old_space and old_space != 0: self.setGeometry(0, self.index * 50, self.width_, self.space * 50) self.left_frame.setGeometry(0, 0, 60, self.space * 50) self.right_frame.setGeometry(self.width_ - 60, 0, 60, 50 * self.space) else: if not active: new_y = (self.index + abs(old_space - self.space)) * 50 elif old_space == 0: self.move(0, self.index * 50 + 50) new_y = self.index * 50 else: new_y = self.index * 50 self.size_animal(self, old_space, self.space, self.width_, [self.pos().x(), self.pos().y()], [0, new_y]) self.size_animal(self.left_frame, old_space, self.space, 60, (0, 0), (0, 0)) self.size_animal(self.right_frame, old_space, self.space, 60, (self.width_ - 60, 0), (self.width_ - 60, 0)) self.alter(True, old_space=old_space) # 调色板 def change_color(self): self.color_index = (self.color_index + 1) % len(self.father.color_list) color = self.father.color_list[self.color_index] self.edit.setStyleSheet('QTextEdit{background-color: %s;}' % color) # 到点提醒 def clock(self, time): if self.edit.toPlainText(): self.top.tray.show_a_message(time, self.edit.toPlainText()) # 动画效果 def size_animal(self, obj, old_space, new_space, width, old_position, new_position): # 动画效果 animal = QPropertyAnimation(obj, b'geometry', self) animal.setDuration(200) animal.setStartValue(QRect(*old_position, width, 50 * old_space)) animal.setEndValue(QRect(*new_position, width, 50 * new_space)) animal.start()
def __init__(self, parent=None): super(Main_MUESTRA, self).__init__(parent) self.setWindowTitle("EXADATA") self.setFixedSize(900, 600) self.centralwidget = QtWidgets.QWidget(self) self.centralwidget.setObjectName("centralwidget") # FRAME paleta = QPalette() paleta.setColor(QPalette.Background, QColor(51, 0, 102)) frame = QFrame(self) frame.setFrameShape(QFrame.NoFrame) frame.setFrameShadow(QFrame.Sunken) frame.setAutoFillBackground(True) frame.setPalette(paleta) frame.setFixedWidth(950) frame.setFixedHeight(100) frame.move(0, 0) labelIcono = QLabel(frame) labelIcono.setFixedWidth(65) labelIcono.setFixedHeight(65) labelIcono.setPixmap(QPixmap("icono.jpg").scaled(65, 65, Qt.KeepAspectRatio, Qt.SmoothTransformation)) labelIcono.move(10, 28) fuenteTitulo = QFont() fuenteTitulo.setPointSize(25) fuenteTitulo.setBold(True) labelTitulo = QLabel("<font color='white'>EXADATA</font>", frame) labelTitulo.setFont(fuenteTitulo) labelTitulo.move(85, 30) fuenteSubtitulo = QFont() fuenteSubtitulo.setPointSize(13) labelSubtitulo = QLabel("<font color='white'>Análisis de Tweets " , frame) labelSubtitulo.setFont(fuenteSubtitulo) labelSubtitulo.move(85, 68) # BARRA self.progressBar = QtWidgets.QProgressBar(self.centralwidget) self.progressBar.setGeometry(QtCore.QRect(10, 480, 510, 23)) self.progressBar.setProperty("value", 24) self.progressBar.setTextVisible(False) self.progressBar.setObjectName("progressBar") #inicio tabla self.tabla = QtWidgets.QTableWidget(self.centralwidget) # formato tabla posx,posy,tamx,tamy self.tabla.setGeometry(QtCore.QRect(10, 120, 510, 400)) self.tabla.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.tabla.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents) self.tabla.setColumnCount(4) self.tabla.setObjectName("tabla") self.tabla.setRowCount(0) item = QtWidgets.QTableWidgetItem() self.tabla.setHorizontalHeaderItem(0, item) item = QtWidgets.QTableWidgetItem() self.tabla.setHorizontalHeaderItem(1, item) item = QtWidgets.QTableWidgetItem() self.tabla.setHorizontalHeaderItem(2, item) item = QtWidgets.QTableWidgetItem() self.tabla.setHorizontalHeaderItem(3, item) self.tabla.horizontalHeader().setDefaultSectionSize(120) self.tabla.horizontalHeader().setStretchLastSection(True) self.tabla.verticalHeader().setStretchLastSection(False) self.tabla.cellClicked.connect(self.ConsultarFecha) #fin tabla # BOTONES # boton exportar_bd self.bt_exportar_bd = QtWidgets.QPushButton(self.centralwidget) self.bt_exportar_bd.setGeometry(QtCore.QRect(550, 400, 100, 20)) self.bt_exportar_bd.setObjectName("bt_exportar_bd") self.bt_exportar_bd.clicked.connect(self.Exportar_Fecha) # boton exportar_bd2 self.bt_exportar_bd2 = QtWidgets.QPushButton(self.centralwidget) self.bt_exportar_bd2.setGeometry(QtCore.QRect(635, 460, 100, 20)) self.bt_exportar_bd2.setObjectName("bt_exportar_bd2") self.bt_exportar_bd2.clicked.connect(self.Exportar_Cantidad) # CUADRO TEXTO self.muestra_cantidad = QtWidgets.QLineEdit(self.centralwidget) self.muestra_cantidad.setGeometry(QtCore.QRect(550, 460, 50, 20)) self.muestra_cantidad.setObjectName("muestra_cantidad") #================================================================================= self.setCentralWidget(self.centralwidget) #CALENDARIO # formato tabla posx,posy,tamx,tamy self.calendario = QtWidgets.QCalendarWidget(self.centralwidget) self.calendario.setGeometry(QtCore.QRect(550, 120, 312, 183)) self.calendario.setStyleSheet("") self.calendario.setStyleSheet("alternate-background-color: rgb(118, 148, 255);") self.calendario.setObjectName("calendario") #LABEL MUESTRA POR FECHA self.label_muestraFecha = QtWidgets.QLabel(self.centralwidget) self.label_muestraFecha.setGeometry(QtCore.QRect(550, 330, 121, 16)) self.label_muestraFecha.setObjectName("label_muestraFecha") #LABEL MUESTRA DE TODA LA BASE self.label_muestraToda = QtWidgets.QLabel(self.centralwidget) self.label_muestraToda.setGeometry(QtCore.QRect(550, 440, 200, 16)) self.label_muestraToda.setObjectName("label_muestraToda") self.fechaInicio = QtWidgets.QDateEdit(self.centralwidget) self.fechaInicio.setGeometry(QtCore.QRect(550, 370, 110, 22)) self.fechaInicio.setObjectName("fechaInicio") self.fechaInicio.setCalendarPopup(True) self.fechaTermino = QtWidgets.QDateEdit(self.centralwidget) self.fechaTermino.setGeometry(QtCore.QRect(720, 370, 110, 22)) self.fechaTermino.setObjectName("fechaTermino") self.fechaTermino.setCalendarPopup(True) self.fechaInicio.setDate(QtCore.QDate.currentDate()) self.fechaTermino.setDate(QtCore.QDate.currentDate()) self.incioLetra = QtWidgets.QLabel(self.centralwidget) self.incioLetra.setGeometry(QtCore.QRect(550, 350, 111, 16)) self.incioLetra.setObjectName("incioLetra") self.terminoLetra = QtWidgets.QLabel(self.centralwidget) self.terminoLetra.setGeometry(QtCore.QRect(720, 350, 111, 16)) self.terminoLetra.setObjectName("terminoLetra") #BARRA MENU self.menubar = QtWidgets.QMenuBar(self) self.menubar.setGeometry(QtCore.QRect(0, 0, 1000, 21)) self.menubar.setObjectName("menubar") self.Programas = QtWidgets.QMenu(self.menubar) self.BaseDeDatos = QtWidgets.QAction(self) self.menubar.addAction(self.Programas.menuAction()) self.Programas.addAction(self.BaseDeDatos) self.BaseDeDatos.triggered.connect(self.close) self.Ayuda = QtWidgets.QMenu(self.menubar) self.SobreQue = QtWidgets.QAction(self) self.menubar.addAction(self.Ayuda.menuAction()) self.Ayuda.addAction(self.SobreQue) self.SobreQue.triggered.connect(self.AYUDA) # boton recarga_bd self.bt_recarga_bd = QtWidgets.QPushButton(self.centralwidget) self.bt_recarga_bd.setGeometry(QtCore.QRect(10, 530, 510, 20)) self.bt_recarga_bd.setObjectName("bt_recarga_bd") self.bt_recarga_bd.clicked.connect(self.CargarTabla) self.retranslateUi(self) QtCore.QMetaObject.connectSlotsByName(self) #new table self.tabla_master() self.CargarTabla() self.progressBar.hide()
class UserInterface(QMainWindow): def __init__(self, parent): super().__init__(parent) self._gameBoard = GameBoard() self._parent = parent self._gameover = False self._isTowerSelected = False self._isTowerHovered = False self._towerBeingHovered = None self._selectedTower = None self._waveFinishTime = 0 self._gameSpeed = self._parent.speed self._timePassed = 0 self.timer = QBasicTimer() self._gameBoard.readMapData(os.path.join('./Maps/', self._parent.map)) self.timer.start(self._gameSpeed, self) self.initUI() def initUI(self): centralWidget = QWidget() self.setCentralWidget(centralWidget) self.setWindowTitle(self._gameBoard.name) self.setWindowIcon(QIcon(os.path.join('./Pictures/', 'berserker_icon.png'))) #Apparently this doens't work the same way on a mac. self.statusBar().showMessage('Ready!') vbox = QVBoxLayout() centralWidget.setLayout(vbox) self.gameStats = GameStats(self) self.mapView = MapView(self) self.bottomButtons = BottomButtons(self) vbox.addWidget(self.gameStats) vbox.addWidget(self.mapView) vbox.addWidget(self.bottomButtons) screen = QDesktopWidget().screenGeometry() self.setGeometry((screen.width() - (self.gameboard.width - 1) * 20) / 2, (screen.height() - self.gameboard.height * 20 - 200) / 2, 500, 400) self.show() def getGameboard(self): return self._gameBoard def getIsTowerSelected(self): return self._isTowerSelected def setIsTowerSelected(self, boolean): self._isTowerSelected = boolean def getSelectedTower(self): return self._selectedTower def setSelectedTower(self, towerType): self._selectedTower = towerType def getIsTowerBeingHovered(self): return self._isTowerHovered def setIsTowerBeingHovered(self, boolean, tower): self._isTowerHovered = boolean self._towerBeingHovered = tower def getTowerBeingHovered(self): return self._towerBeingHovered def getGameStats(self): return self.gameStats def getTimePassed(self): return self._timePassed def setWaveFinishTime(self, value): self._waveFinishTime = value def getGameOver(self): return self._gameover def timerEvent(self, event): # The time passed attribute helps with setting the enemy appearance interval and tower firerate. self._timePassed += 1 self.mapView.summonEnemy() self.mapView.moveEnemies() self.mapView.checkShooting() self.mapView.moveProjectiles() self.mapView.update() def loseGame(self): self.bottomButtons.clockTimer.stop() self.timer.stop() self.statusBar().showMessage('Game has ended. You lost.') self._gameover = True self.popUp = QFrame() self.popUp.setGeometry(500, 500, 100, 100) vbox = QVBoxLayout() youLost = QLabel() youLost.setPixmap(QPixmap(os.path.join('./Pictures/', "game_over.png"))) vbox.addWidget(youLost) done = QPushButton("Done") vbox.addWidget(done) self.popUp.setLayout(vbox) self.popUp.move(self.mapToGlobal(QPoint(0,0)).x() + self.gameboard.width*blockSize / 2 - 130, self.mapToGlobal(QPoint(0,0)).y() + self.gameboard.height*blockSize / 2) self.popUp.show() done.clicked.connect(self.backToMainMenu) def winGame(self): self.bottomButtons.clockTimer.stop() self.timer.stop() self.statusBar().showMessage('Game has ended. You won.') self._gameover = True self.popUp = QFrame() self.popUp.setGeometry(500, 500, 100, 100) vbox = QVBoxLayout() youLost = QLabel() youLost.setPixmap(QPixmap(os.path.join('./Pictures/', "victory.png"))) vbox.addWidget(youLost) done = QPushButton("Done") vbox.addWidget(done) self.popUp.setLayout(vbox) self.popUp.move(self.mapToGlobal(QPoint(0,0)).x() + self.gameboard.width*blockSize / 2 - 130, self.mapToGlobal(QPoint(0,0)).y() + self.gameboard.height*blockSize / 2) self.popUp.show() done.clicked.connect(self.backToMainMenu) def backToMainMenu(self): self._parent.show() self.popUp.deleteLater() self.deleteLater() def getGameSpeed(self): return self._gameSpeed def setGameSpeed(self, value): self._gameSpeed = value def getWaveFinishTime(self): return self._waveFinishTime def getTimer(self): return self.timer isTowerSelected = property(getIsTowerSelected, setIsTowerSelected) selectedTower = property(getSelectedTower, setSelectedTower) isTowerHovered = property(getIsTowerBeingHovered) towerBeingHovered = property(getTowerBeingHovered) gamestats = property(getGameStats) gameboard = property(getGameboard) timePassed = property(getTimePassed) gameover = property(getGameOver) gameSpeed = property(getGameSpeed, setGameSpeed) waveFinishTime = property(getWaveFinishTime, setWaveFinishTime)
class Chat(QWidget): msg_signal = pyqtSignal(dict) after_close = None chats = [] cur_chat = None def __init__(self, parent=None): super().__init__(parent) self.msg_signal.connect(self.fill_msg) MsgWorker().do_recv_msg = self.do_recv_msg self.setWindowTitle('') self.op_bar = QFrame(self) self.op_bar.setStyleSheet('background-color:rgb(255, 255, 255);') self.send_bar = QFrame(self) self.send_bar.setStyleSheet('background-color:rgb(255, 255, 255);') self.rcTxt = QTextBrowser(self) self.rcTxt.setStyleSheet('background-color:rgb(255, 255, 255);') self.sdTxt = QTextEdit(self) self.sdTxt.setStyleSheet('background-color:rgb(255, 255, 255);') self.btn = QPushButton("发送", self.send_bar) self.btn.clicked.connect(self.send) self.lv = QListView(self) self.lv.setViewMode(QListView.ListMode) self.lv.setIconSize(QSize(30, 30)) self.lv.setEditTriggers(QAbstractItemView.NoEditTriggers) self.lv.setResizeMode(QListView.Adjust) self.lv_model = QStandardItemModel() self.lv.setModel(self.lv_model) self.lv.clicked.connect(self.lv_clicked) self.lv.move(0, 0) w, h = 600, 400 self.resize(800, 600) def resizeEvent(self, evt): self.after_resize(evt.size().width(), evt.size().height()) def after_resize(self, w, h): lv_width = 200 sdTxt_height = 120 bar_height = 30 self.op_bar.move(200, h - sdTxt_height - bar_height * 2) self.op_bar.resize(w - lv_width, bar_height) self.send_bar.move(200, h - bar_height) self.send_bar.resize(w - lv_width, bar_height) self.lv.resize(lv_width, h) self.rcTxt.move(lv_width, 0) self.rcTxt.resize(w - lv_width, h - sdTxt_height - bar_height * 2) self.sdTxt.move(lv_width, h - sdTxt_height - bar_height) self.sdTxt.resize(w - lv_width, sdTxt_height) def lv_clicked(self, model_index): cur_chat = self.chats[model_index.row()] if cur_chat['mode'] == 'user': self.setWindowTitle(cur_chat['data'].nick_name) def refresh_cur_chat(self): if self.cur_chat['mode'] == 'user': self.setWindowTitle(self.cur_chat['data'].nick_name) def get_in_chat_index(self, chat): if chat['mode'] == 'user': name = chat['data'].name match = lambda x: x['mode'] == 'user' and x['data'].name == name for i in range(len(self.chats)): if match(self.chats[i]): return i return -1 def chat_to(self, chat): i = self.get_in_chat_index(chat) if i == -1: if chat['mode'] == 'user': self.lv_model.appendRow( QStandardItem(QIcon("./client/image/man.png"), chat['data'].nick_name)) self.chats.append(chat) self.cur_chat = chat i = len(self.chats) - 1 else: self.cur_chat = self.chats[i] self.refresh_cur_chat() self.lv.setCurrentIndex(self.lv_model.index(i, 0)) def fill_msg(self, data): ufrom = data['from'] uto = data['to'] val = data['val'] ufrom_nickname = ufrom try: self.rcTxt.setPlainText(self.rcTxt.toPlainText() + '%s:%s\n' % (ufrom_nickname, val)) except Exception as ex: print(ex) def do_recv_msg(self, data): self.msg_signal.emit(data) def send(self): # val = self.sdTxt.toHtml() val = self.sdTxt.toPlainText() if self.cur_chat['mode'] == 'user': MsgWorker().send_msg( msg_lib.build_chat_msg(MsgWorker().user_info.name, self.cur_chat['data'].name, val)) # self.rcTxt.setHtml(self.rcTxt.toHtml()+'\n我:%s'%val) self.rcTxt.setPlainText(self.rcTxt.toPlainText() + '我:%s\n' % val) self.sdTxt.setPlainText('') def closeEvent(self, event): self.chats.clear() if self.after_close: self.after_close()
def _setWindowObjects(self): #ComboBox in the home page #Window size 500,600 self.styleChoise = QLabel("January", self) self.styleChoise.setStyleSheet("background-color: red") self.resize(20, 40) self.styleChoise.move(280, 40) #Position ComboBox = QComboBox(self) ComboBox.addItem('January') ComboBox.addItem('February') ComboBox.addItem('March') ComboBox.addItem('April') ComboBox.addItem('May') ComboBox.addItem('June') ComboBox.addItem('July') ComboBox.addItem('August') ComboBox.addItem('September') ComboBox.addItem('October') ComboBox.addItem('November') ComboBox.addItem('December') ComboBox.move(20, 40) #size ComboBox.activated[str].connect(self.style_Choise) #Frame for the box frame = QFrame(self) frame.setFrameShape(QFrame.StyledPanel) frame.setLineWidth(10) frame.setMidLineWidth(10) frame.resize(200, 400) frame.move(280, 90) frame.setStyleSheet(".QFrame { background-color : white } ") formLayout = QFormLayout() formLayout.addWidget(frame) self.setLayout(formLayout) #Buttons btn1 = QPushButton('AddNew', self) btn1.resize(75, 50) btn1.move(20, 90) btn1.setStatusTip('AddNew') btn2 = QPushButton('Edit', self) btn2.resize(75, 50) btn2.move(100, 90) btn2.setStatusTip('Edit') btn3 = QPushButton('View', self) btn3.resize(75, 50) btn3.move(175, 90) btn3.setStatusTip('View') ### btn4 = QPushButton('Delete', self) btn4.resize(75, 50) btn4.move(20, 150) btn4.setStatusTip('Delete') btn5 = QPushButton('ShowAll', self) btn5.resize(75, 50) btn5.move(100, 150) btn5.setStatusTip('ShowAll') btn6 = QPushButton('RemoveDups', self) btn6.resize(75, 50) btn6.move(175, 150) btn6.setStatusTip('Removes Duplicate') #### btn7 = QPushButton('Upload', self) btn7.resize(75, 50) btn7.move(20, 210) btn7.setStatusTip('Uploads online') btn8 = QPushButton('Backup', self) btn8.resize(75, 50) btn8.move(100, 210) btn8.setStatusTip('Backup Contacts') btn9 = QPushButton('Share', self) btn9.resize(75, 50) btn9.move(175, 210) btn9.setStatusTip('Share Contact') #### btn10 = QPushButton('SendText', self) btn10.resize(75, 50) btn10.move(20, 270) btn10.setStatusTip('Send Text') btn11 = QPushButton('CallContact', self) btn11.resize(75, 50) btn11.move(100, 270) btn11.setStatusTip('Call Selected Contact') btn12 = QPushButton('CopyContact', self) btn12.resize(75, 50) btn12.move(175, 270) btn12.setStatusTip('Copy contact') ### btn13 = QPushButton('Quit', self) btn13.resize(75, 50) btn13.move(400, 500) btn13.setStatusTip('Quit Application') #Click activities on the buttons btn13.clicked.connect(self.closeApplication) btn5.clicked.connect(self.showAllContacts)
class MapView(QFrame): def __init__(self, parent): super(MapView, self).__init__(parent) self.parent = parent self.initUI(self.parent.gameboard) self.mouse_x = 0 self.mouse_y = 0 self.clickedTower = None def initUI(self, gameboard): self.setFixedSize((gameboard.width - 1)*blockSize, gameboard.height*blockSize) self.setMouseTracking(True) self.show() def paintEvent(self, event): qp = QPainter() qp.begin(self) self.drawMap(qp) if self.underMouse() and self.parent.isTowerSelected: # Draws the tower outline and range of the tower being build self.drawTowerRange(self.mouse_x, self.mouse_y, self.parent.selectedTower.range, qp) self.drawTowerOutline(self.mouse_x, self.mouse_y, qp) if not self.parent.isTowerSelected and self.parent.isTowerHovered: # Draws tower range when a tower is being hovered self.drawTowerRange(self.parent.towerBeingHovered.posX, self.parent.towerBeingHovered.posY, self.parent.towerBeingHovered.range, qp) self.drawPorjectiles(qp) qp.end() def drawMap(self, qp): self.drawMapBlocks(qp, self.parent.gameboard.river, riverColor) self.drawMapBlocks(qp, self.parent.gameboard.road, roadColor) self.drawMapBlocks(qp, self.parent.gameboard.unoccupied, grassColor) self.drawMapBlocks(qp, self.parent.gameboard.cave, caveColor) self.drawMapBlocks(qp, self.parent.gameboard.mountain, mountainColor) self.drawMapBlocks(qp, self.parent.gameboard.bridge, woodColor) def drawMapBlocks(self, qp, coordinateList, color): # Draws map blocks according to the coordinate list qp.setPen(gridColor) qp.setBrush(color) for i in coordinateList: qp.drawRect(i[0]*blockSize, i[1]*blockSize, blockSize, blockSize) def drawTowerRange(self, x, y, towerRange, painter): painter.setPen(rangePenColor) painter.setBrush(rangeBrushColor) painter.drawEllipse(QPoint(x, y), towerRange, towerRange) def drawTowerOutline(self, x, y, painter): painter.setPen(rangePenColor) painter.setBrush(rangeBrushColor) painter.drawRect(x - 20, y - 20, 40, 40) def drawPorjectiles(self, qp): qp.setPen(projectileColor) qp.setBrush(projectileColor) for projectile in self.parent.gameboard.projectiles: if not projectile.isFinished: if projectile.name == "Bullet": qp.drawEllipse(projectile.posX, projectile.posY, 3, 3) elif projectile.name == "Cannonball": qp.drawEllipse(projectile.posX, projectile.posY, 8, 8) def mouseMoveEvent(self, event): # This method makes sure that towers are build according to the grid and that the tower outline and range are displayed properly if self.underMouse() and self.parent.isTowerSelected == True: self.mouse_x, self.mouse_y = self.calculateClosestCorner(event.pos().x(), event.pos().y()) def calculateClosestCorner(self, mouse_x, mouse_y): # Calculates the closest grid corner from mouse location closest_corner_x = 0 closest_corner_y = 0 if mouse_x % blockSize < blockSize / 2: closest_corner_x = mouse_x - (mouse_x % blockSize) else: closest_corner_x = mouse_x + (blockSize - mouse_x % blockSize) if mouse_y % blockSize < blockSize / 2: closest_corner_y = mouse_y - (mouse_y % blockSize) else: closest_corner_y = mouse_y + (blockSize - mouse_y % blockSize) return closest_corner_x, closest_corner_y def mousePressEvent(self, e): # Method for building towers and checking that their location is ok if e.button() == Qt.LeftButton: if self.parent.gameover == False: if self.parent.isTowerSelected == True: # We calculate the bottom right block for the tower block1 = [int(self.mouse_x / blockSize), int(self.mouse_y / blockSize)] # We need to make sure that the tower doesn't go over the borders of the gameboard if block1[0] > 0 and block1[1] > 0 and block1[0] < self.parent.gameboard.width and block1[1] < self.parent.gameboard.height: #Then we calculate the other blocks block2 = [block1[0] - 1, block1[1]] block3 = [block1[0] - 1, block1[1] - 1] block4 = [block1[0], block1[1] - 1] blocks = [block1, block2, block3, block4] occupied = self.parent.gameboard.occupied canPlaceTower = True # We check that none of the tower blocks are occupied for block in blocks: if block in occupied: canPlaceTower = False if canPlaceTower == True: # We places the tower on the map tower = self.parent.selectedTower tower.setPosition(self.mouse_x, self.mouse_y) placedTower = ClickableTower(tower, self) placedTower.move(block3[0] * blockSize, block3[1] * blockSize) placedTower.show() # Then we add the tower blocks to the list of occupied tiles for block in blocks: self.parent.gameboard.addToOccupied(block) self.parent.gameboard.addBuildTower(tower) self.parent.gameboard.buy(tower.price) self.parent.gamestats.update() self.statusBarMessage('Tower build') self.parent.selectedTower = None self.parent.isTowerSelected = False else: self.statusBarMessage("Can't place it there!") else: self.statusBarMessage("Can't place it there!") else: self.statusBarMessage("The game has ended. You can't build towers.") else: # If we click the right mouse button we cancel the tower selection self.parent.selectedTower = None self.parent.isTowerSelected = False self.statusBarMessage('') self.update() def getParent(self): # Not sure if I'm using this anywhere return self.parent def statusBarMessage(self, message): # Just a shorter way to write statusbar messages self.parent.statusBar().showMessage(message) def towerClick(self, tower): # Opens a popup to see tower stats and to upgrade tower if self.parent.gameover == False: if self.parent.isTowerSelected == False: self.clickedTower = tower # self.statusBarMessage("Tower clicked") self.towerPopUp = QFrame() self.towerPopUp.setGeometry(500, 500, 100, 100) grid = QGridLayout() self.towerPopUp.setLayout(grid) vbox = QVBoxLayout() pixmap = QLabel() vbox.addStretch() if tower.level == 2: pixmap.setPixmap(tower.upgradedPicture) else: pixmap.setPixmap(tower.picture) vbox.addWidget(pixmap) vbox.addStretch() grid.addLayout(vbox, 0, 0) towerStats = QLabel(tower.name + " Tower Stats", self) power = QLabel("Power: {:.0f}".format(tower.power), self) towerRange = QLabel("Range: {:.0f}".format(tower.range), self) fireRate = QLabel("Rate of Fire: " + str(tower.fireRate), self) level = QLabel("Level: " + str(tower.level), self) vbox2 = QVBoxLayout() vbox2.addWidget(towerStats) vbox2.addWidget(power) vbox2.addWidget(towerRange) vbox2.addWidget(fireRate) vbox2.addWidget(level) grid.addLayout(vbox2, 0, 1) vbox3 = QVBoxLayout() if self.clickedTower.maxLevel > self.clickedTower.level: upgradeButton = QPushButton("Upgrade for " + str(tower.upgradePrice)) vbox3.addWidget(upgradeButton) upgradeButton.clicked.connect(self.upgrade) else: maxLevel = QLabel("Tower at maximum level.") vbox3.addWidget(maxLevel) doneButton = QPushButton("Done") vbox3.addWidget(doneButton) grid.addLayout(vbox3, 0, 2) location = QPoint(QCursor.pos()) self.towerPopUp.move(location.x() - 180, location.y()) self.towerPopUp.show() doneButton.clicked.connect(self.towerPopUp.hide) else: self.statusBarMessage("The game has ended. Stop doing stuff.") def upgrade(self): if self.clickedTower.level < self.clickedTower.maxLevel: if self.parent.gameboard.money >= self.clickedTower.upgradePrice: self.clickedTower.upgrade() self.parent.gameboard.buy(self.clickedTower.upgradePrice) self.statusBarMessage("Tower upgraded") self.parent.gamestats.update() self.towerPopUp.hide() else: self.statusBarMessage("Not enough money to upgrade.") else: self.statusBarMessage("Tower already at maximum level.") def summonEnemy(self): # Summons an enemy at given intervals waveIndex = self.parent.gameboard.currentWave - 1 if self.parent.gameboard.currentWave <= len(self.parent.gameboard.waves): # self.parent.gameboard.waves[waveIndex][0] gives the enemy interval for that wave if self.parent.gameboard.currentEnemy == 1: # This makes sure that there's a break between enemy waves, the length of the break can be defined in globals if self.parent.timePassed - self.parent.waveFinishTime >= breakBetweenWaves: if self.checkNextEnemy("e1", Barbarian(self.parent.gameboard.enemyPath, self)): self.checkIsWaveDone() elif self.checkNextEnemy("e2", Berserker(self.parent.gameboard.enemyPath, self)): self.checkIsWaveDone() elif self.parent.timePassed % self.parent.gameboard.waves[waveIndex][0] == 0: if self.checkNextEnemy("e1", Barbarian(self.parent.gameboard.enemyPath, self)): self.checkIsWaveDone() elif self.checkNextEnemy("e2", Berserker(self.parent.gameboard.enemyPath, self)): self.checkIsWaveDone() def checkIsWaveDone(self): waveIndex = self.parent.gameboard.currentWave - 1 if self.parent.gameboard.currentEnemy > len(self.parent.gameboard.waves[waveIndex][1]): self.parent.gameboard.currentEnemy = 1 self.parent.gameboard.currentWave += 1 self.parent.waveFinishTime = self.parent.timePassed self.parent.gamestats.update() return True else: return False def checkNextEnemy(self, name, enemyType): # This method could probably be changed a bit, but it does it's job. I'll update it if I have time. enemyIndex = self.parent.gameboard.currentEnemy - 1 waveIndex = self.parent.gameboard.currentWave - 1 if self.parent.gameboard.waves[waveIndex][1][enemyIndex] == name: enemy = enemyType enemy.move(enemy.posX, enemy.posY) enemy.show() self.parent.gameboard.addSummonedEnemy(enemy) self.parent.gameboard.currentEnemy += 1 return True else: return False def moveEnemies(self): noOfSummonedEnemies = len(self.parent.gameboard.enemiesSummoned) if noOfSummonedEnemies > 0: i = 0 while i < noOfSummonedEnemies: enemy = self.parent.gameboard.enemiesSummoned[i] if not enemy.isFinished and not enemy.isDead: enemy.moveEnemy() if enemy.checkIfFinished(): self.parent.gameboard.currentLives -= 1 self.parent.update() if self.parent.gameboard.currentLives <= 0: self.parent.loseGame() else: self.checkIfGameEnded() i += 1 def enemyClick(self, enemy): # Opens an info screen on the enemy if self.parent.gameover == False and enemy.isDead == False: if self.parent.isTowerSelected == False: # self.statusBarMessage("Enemy clicked") self.enemyPopUp = QFrame() self.enemyPopUp.setGeometry(500, 500, 100, 100) grid = QGridLayout() self.enemyPopUp.setLayout(grid) enemyStats = QLabel("Enemy Stats") name = QLabel("Name: " + str(enemy.name)) speed = QLabel("Speed: " + str(enemy.speed)) health = QLabel("Health: {:.0f}".format(enemy.health)) pixmap = QLabel() pixmap.setPixmap(enemy.picture) vbox = QVBoxLayout() vbox.addWidget(enemyStats) vbox.addWidget(name) vbox.addWidget(speed) vbox.addWidget(health) grid.addLayout(vbox, 0, 0) vbox2 = QVBoxLayout() vbox2.addWidget(pixmap) vbox2.addStretch() doneButton = QPushButton("Done") vbox2.addWidget(doneButton) grid.addLayout(vbox2, 0, 1) location = QPoint(QCursor.pos()) self.enemyPopUp.move(location.x() - 100, location.y()) self.enemyPopUp.show() doneButton.clicked.connect(self.enemyPopUp.hide) elif self.parent.gameover == True: self.statusBarMessage("The game has ended. Stop doing stuff.") def checkShooting(self): # We go trough the towers we have build and check if they have enemies in range for tower in self.parent.gameboard.towersBuild: # This is kind of a simple method of checking the firerate # We firs check when the tower has fired it's last shot to see if it's time to shoot again if tower.lastShot == 0 or self.parent.timePassed - tower.lastShot >= tower.fireRate: # We always shoot the enemy that has moved to the furthest block. If there's more than one enemy in the same block we select the one that's first in the list. # Again, this method could be improved. We could check which enemy is actually furthest down the path in actual pixels. i = 0 maxBlocks = -1 targetEnemy = None while i < len(self.parent.gameboard.enemiesSummoned): enemy = self.parent.gameboard.enemiesSummoned[i] # We shouldn't shoot enemies that are dead or have already reached the end of the path. if enemy.isFinished == False and enemy.isDead == False: if tower.inRange(enemy): if enemy.blocksMoved > maxBlocks: maxBlocks = enemy.blocksMoved targetEnemy = enemy i += 1 if targetEnemy != None: projectile = tower.shoot(targetEnemy) tower.lastShot = self.parent.timePassed self.parent.gameboard.addProjectile(projectile) # self.statusBarMessage(tower.name + " shoots " + targetEnemy.name + " with " + projectile.name) def moveProjectiles(self): for projectile in self.parent.gameboard.projectiles: if not projectile.isFinished: projectile.move() if projectile.checkIfHit(): # self.statusBarMessage(projectile.destination.name + " takes a hit of " + str(projectile.damage) + " damage.") if projectile.name == "Cannonball": # Cannonballs damage all enemies in the same block. # This method could also be improved. We should probably hit enemies that are within a certain range from the target enemy instead of being in the same block. for enemy in self.parent.gameboard.enemiesSummoned: if enemy != projectile.destination and enemy.currentBlock == projectile.destination.currentBlock: if enemy.getHit(projectile.damage): enemy.checkIfDead() if projectile.destination.checkIfDead(): # self.statusBarMessage(projectile.destination.name + " is dead. You get " + str(projectile.destination.reward) + " coins.") self.parent.gameboard.addMoney(projectile.destination.reward) self.parent.gamestats.update() self.checkIfGameEnded() def checkIfGameEnded(self): # This method checks if all waves have been sent and all summoned enemies have either reached their destination or died. allDone = False if self.parent.gameboard.currentWave >= len(self.parent.gameboard.waves): # self.statusBarMessage("Last wave!") # Check how many enemies the map has in total. This should probably be an attribute that's calculated already when the GameBoard-object is made. totalEnemies = 0 for wave in self.parent.gameboard.waves: totalEnemies += len(wave[1]) # Then we compare that number to the number of summoned enemies if len(self.parent.gameboard.enemiesSummoned) == totalEnemies: # self.statusBarMessage("All enemies summoned!") allDone = True # Then we check if they are all dead or finished for enemy in self.parent.gameboard.enemiesSummoned: if enemy.isFinished == False and enemy.isDead == False: allDone = False # If so the game has ended and the player is victorious if allDone: self.parent.winGame()