Last active
February 2, 2021 14:06
-
-
Save CoutinhoElias/51c7b9bf51b3e0b96226dac1304f1178 to your computer and use it in GitHub Desktop.
Margins PySide5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5.QtWidgets import * | |
from PyQt5.QtCore import Qt | |
import sys | |
''' | |
============================================================================================================= | |
Cada classe herdando QWidget equivale a uma tela disponível para exibir. | |
''' | |
# Classe para capturar o caminho dos arquivos e apontar onse será salvo. | |
class WidgetConvert(QWidget): | |
def __init__(self): | |
super().__init__() | |
layout = QVBoxLayout() | |
layout.setContentsMargins(0, 0, 0, 0) | |
self.frm_converter = QFrame(self) | |
self.frm_converter.setGeometry(150, 0, 830, 700) | |
self.frm_converter.setStyleSheet('background-color: rgb(255, 255, 255)') | |
#self.frm_converter.setVisible(True) | |
self.txt_caminho = QLineEdit(self.frm_converter) | |
self.txt_caminho.setPlaceholderText("Escolha o diretório do PLANO DE CONTAS clicando no botão ao lado ===>>") | |
self.txt_caminho.setGeometry(20, 10, 560, 22) | |
self.btn_localizar = QPushButton('Plano de Contas', self.frm_converter) | |
self.btn_localizar.setGeometry(590, 10, 130, 22) | |
self.btn_localizar.setStyleSheet('background-color:rgb(7, 105, 114); color:white') | |
self.btn_localizar.clicked.connect(self.file_dir_pcontas) | |
self.txt_movimento = QLineEdit(self.frm_converter) | |
self.txt_movimento.setPlaceholderText("Escolha o diretório do MOVIMENTO clicando no botão ao lado ===>>") | |
self.txt_movimento.setGeometry(20, 50, 560, 22) | |
self.btn_movimento = QPushButton('Movimento', self.frm_converter) | |
self.btn_movimento.setGeometry(590, 50, 130, 22) | |
self.btn_movimento.setStyleSheet('background-color:rgb(7, 105, 114); color:white') | |
self.btn_movimento.clicked.connect(self.file_dir_movimento) | |
layout.addWidget(self.frm_converter) | |
self.setLayout(layout) | |
def file_dir_pcontas(self): | |
filedir = easygui.fileopenbox(msg='Mensagem', | |
title='Título', | |
default='ARQUIVO.csv', | |
filetypes = ["*.csv" ],) | |
self.txt_caminho.setText(filedir) | |
print(filedir) | |
# def file_dir_pcontas(self): | |
# | |
# filedir = easygui.filesavebox(msg='Mensagem', | |
# title='Título', | |
# default='ARQUIVO.csv', | |
# filetypes = ["*.css", ["*.htm", "*.html", "HTML files"], "*.csv" ],) | |
# | |
# self.txt_caminho.setText(filedir) | |
# print(filedir) | |
def file_dir_movimento(self): | |
filedir = easygui.fileopenbox(msg='Mensagem', | |
title='Título', | |
default='ARQUIVO.csv', | |
filetypes = ["*.csv" ],) | |
self.txt_movimento.setText(filedir) | |
print(filedir) | |
class WidgetLineEdits(QWidget): | |
def __init__(self): | |
super().__init__() | |
#layout = QVBoxLayout() | |
# | |
#for i in range(4): | |
# layout.addWidget(QLineEdit(f'LineEdit #{i}')) | |
# | |
#self.setLayout(layout) | |
layout = QVBoxLayout() | |
layout.setContentsMargins(0, 0, 0, 0) | |
self.frm_converter = QFrame(self) | |
self.frm_converter.setGeometry(150, 0, 830, 700) | |
self.frm_converter.setStyleSheet('background-color: purple') | |
#self.frm_converter.setVisible(True) | |
layout.addWidget(self.frm_converter) | |
self.setLayout(layout) | |
class WidgetRadioButtons(QWidget): | |
def __init__(self): | |
super().__init__() | |
#layout = QVBoxLayout() | |
# | |
#for i in range(4): | |
# layout.addWidget(QRadioButton(f'RaidoButton #{i}')) | |
# | |
#self.setLayout(layout) | |
layout = QVBoxLayout() | |
layout.setContentsMargins(0, 0, 0, 0) | |
self.frm_converter = QFrame(self) | |
self.frm_converter.setGeometry(150, 0, 830, 700) | |
self.frm_converter.setStyleSheet('background-color: gray') | |
#self.frm_converter.setVisible(True) | |
layout.addWidget(self.frm_converter) | |
self.setLayout(layout) | |
class WidgetFrame(QWidget): | |
def __init__(self): | |
super().__init__() | |
#layout = QVBoxLayout() | |
# | |
#for i in range(4): | |
# layout.addWidget(QRadioButton(f'RaidoButton #{i}')) | |
# | |
#self.setLayout(layout) | |
layout = QVBoxLayout() | |
layout.setContentsMargins(0, 0, 0, 0) | |
self.frm_converter = QFrame(self) | |
self.frm_converter.setGeometry(150, 0, 830, 700) | |
self.frm_converter.setStyleSheet('background-color: red') | |
#self.frm_converter.setVisible(True) | |
layout.addWidget(self.frm_converter) | |
self.setLayout(layout) | |
''' | |
Classe principal | |
''' | |
class Window(QMainWindow): | |
def __init__(self): | |
super().__init__() | |
# set the title of main window | |
self.setWindowTitle('Conversor.') | |
# set the size of window | |
#self.Width = 800 | |
#self.height = int(0.618 * self.Width) | |
#self.resize(self.Width, self.height) | |
self.setGeometry(300, 100, 920, 600) # x, y, w, h -> esquerda, topo, largura, altura | |
self.setStyleSheet('background-color: rgb(0, 0, 0)') # Cor do App (Preto), anterior (7, 104, 114) | |
css_button = ''' | |
QPushButton:hover { | |
background-color: rgb(35, 170, 255); | |
} | |
QPushButton { | |
color: rgb(255, 255, 255); | |
background-color: rgb(35, 35, 35); | |
border: 0px solid; | |
height: 41px; | |
width: 100 | |
} | |
''' | |
# add all widgets (Criam os botões laterais) | |
self.btn_1 = QPushButton('Importar', self) | |
self.btn_2 = QPushButton('Menu 2', self) | |
self.btn_3 = QPushButton('Menu 3', self) | |
self.btn_4 = QPushButton('Menu 4', self) | |
self.btn_1.setStyleSheet(css_button) | |
self.btn_2.setStyleSheet(css_button) | |
self.btn_3.setStyleSheet(css_button) | |
self.btn_4.setStyleSheet(css_button) | |
# Chama a função que carrega a tela | |
self.btn_1.clicked.connect(self.button1) | |
self.btn_2.clicked.connect(self.button2) | |
self.btn_3.clicked.connect(self.button3) | |
self.btn_4.clicked.connect(self.button4) | |
self.initUI() | |
def initUI(self): | |
'''Layout que recebe os botões''' | |
left_layout = QVBoxLayout() | |
left_layout.setContentsMargins(0, 0, 0, 0) | |
left_layout.setAlignment(Qt.AlignTop) | |
left_layout.addWidget(self.btn_1) | |
left_layout.addWidget(self.btn_2) | |
left_layout.addWidget(self.btn_3) | |
left_layout.addWidget(self.btn_4) | |
left_layout.setSpacing(1) | |
'''Layout que contem o left_layout''' | |
left_widget = QWidget() | |
left_widget.setLayout(left_layout) | |
left_widget.setStyleSheet('background-color: yellow') | |
left_widget.setFixedWidth(90) | |
#largura = left_widget.height() | |
#altura = left_widget.width() | |
#print('largura {}, altura {}'.format(altura, largura)) | |
""" | |
Preenche o lado direito com os Widgets | |
""" | |
self.right_widget = QStackedWidget() | |
#self.right_widget.setStyleSheet('background-color: blue') | |
self.right_widget.addWidget(WidgetConvert()) # index 0 | |
self.right_widget.addWidget(WidgetLineEdits()) # index 1 | |
self.right_widget.addWidget(WidgetRadioButtons()) # index 2 | |
self.right_widget.addWidget(WidgetFrame()) # index 3 | |
""" | |
Define o Widget que abre primeiro. | |
""" | |
self.right_widget.setCurrentIndex(0) | |
'''Crio o Layout principal''' | |
main_layout = QHBoxLayout() | |
main_layout.setContentsMargins(0, 0, 0, 0) | |
main_layout.addWidget(left_widget) | |
main_layout.addWidget(self.right_widget) | |
main_layout.setSpacing(0) | |
'''Crio o Wdget principal''' | |
main_widget = QWidget() | |
main_widget.setLayout(main_layout) | |
self.setCentralWidget(main_widget) | |
'''Garante a aplicação sempre no centro da tela.''' | |
qr = self.frameGeometry() | |
cp = QDesktopWidget().availableGeometry().center() | |
qr.moveCenter(cp) | |
self.move(qr.topLeft()) | |
# ----------------- | |
# buttons | |
def button1(self): | |
self.right_widget.setCurrentIndex(0) | |
print('Pressionou 1') | |
def button2(self): | |
self.right_widget.setCurrentIndex(1) | |
print('Pressionou 2') | |
def button3(self): | |
self.right_widget.setCurrentIndex(2) | |
print('Pressionou 3') | |
def button4(self): | |
self.right_widget.setCurrentIndex(3) | |
print('Pressionou 4') | |
if __name__ == '__main__': | |
app = QApplication(sys.argv) | |
ex = Window() | |
ex.show() | |
sys.exit(app.exec_()) | |
# main_widget | |
# | | |
# |__==> main_layout | |
# | | |
# |__==> left_widget | |
# | | | |
# | |__==> Botões lateral esquerda | |
# | | |
# |__==> self.right_widget | |
# | | |
# |__==> Frames |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment