SHARE
TWEET

Untitled

a guest Dec 9th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2.  
  3. import menu as menu
  4. from PyQt5.QtWidgets import *
  5. from PyQt5.QtGui import *
  6. from PyQt5.QtCore import *
  7.  
  8. from modul1 import DateDialog
  9.  
  10.  
  11. class MainWnd(QMainWindow,QObject):
  12.     def __init__(self):
  13.         super().__init__()
  14.         self.initUI()
  15.  
  16.     def initUI(self):
  17.  
  18.         self.setWindowTitle("Kolo")
  19.         self.titleDialog1 = ModelessInput(self)
  20.         self.titleDialog1.changed.connect(self.changeTitle)
  21.  
  22.         self.titleDialog2 = DateDialog(self)
  23.  
  24.         menu = QMenuBar()
  25.         dialogMenu = menu.addMenu('Dialog')
  26.  
  27.         self.actionOpen = QAction('Kolor backgroundu', self, checkable = True)
  28.         self.actionOpen.triggered.connect(self.toggleTitleDialog1)
  29.         dialogMenu.addAction(self.actionOpen)
  30.  
  31.         self.actionOpen2 = QAction('Wielkosc kola', self, checkable=True)
  32.         self.actionOpen2.triggered.connect(self.toggleTitleDialog2)
  33.         dialogMenu.addAction(self.actionOpen2)
  34.  
  35.         self.setCentralWidget(Example())
  36.         self.setMenuBar(menu)
  37.         self.show()
  38.  
  39.     def toggleTitleDialog1(self):  # funkcja obsługi elementu menu /pokaż – schowaj dialog
  40.         if self.actionOpen.isChecked():
  41.             self.titleDialog1.show()
  42.             self.titleDialog1.text = self.windowTitle()
  43.         else:
  44.             self.setWindowTitle(self.titleDialog1.text)
  45.             self.titleDialog1.hide()
  46.     def toggleTitleDialog2(self):  # funkcja obsługi elementu menu /pokaż – schowaj dialog
  47.         if self.actionOpen.isChecked():
  48.             self.titleDialog2.show()
  49.             self.titleDialog2.text = self.windowTitle()
  50.         else:
  51.             self.setWindowTitle(self.titleDialog2.text)
  52.             self.titleDialog2.hide()
  53.  
  54.  
  55.     def changeTitle(self, title):  # slot obsługi zmiany tytułu
  56.         self.setWindowTitle(title)
  57.  
  58.     def closeEvent(self, event):  # przedef. funkcji zamknięcia – zamykamy dialog
  59.         self.titleDialog.done(0)
  60.         event.accept()
  61.  
  62. class ModelessInput(QDialog):
  63.     changed = pyqtSignal(str)  # sygnal do zmiany tytułu okna
  64.  
  65.     @property
  66.     def text(self):
  67.         return str(self.lineEdit.text())  # właśwość text – wpisany tytuł
  68.  
  69.     @text.setter
  70.     def text(self, newText):
  71.         self.lineEdit.setText(newText)
  72.  
  73.     def keyPressEvent(self, event):  # obsługa Enter/Return -zatwierdzenie
  74.         if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
  75.             self.changed.emit(self.text)
  76.  
  77.     def closeEvent(self, event):  # zablokowanie możliwości zamkniecia
  78.         event.ignore()
  79.  
  80.     def __init__(self, parent=None, title=""):
  81.         super(ModelessInput, self).__init__(parent)
  82.         mainLayout = QVBoxLayout(self)
  83.         self.lineEdit = QLineEdit(title)
  84.         mainLayout.addWidget(self.lineEdit)
  85.         self.setWindowTitle('Zmiana koloru tła')
  86.         self.resize(350, 100)
  87.  
  88.  
  89.  
  90. class Example(QWidget):
  91.  
  92.     def __init__(self):
  93.         super().__init__()
  94.  
  95.     def zmien(self, newR1, newR2):
  96.         self.R1 = newR1
  97.         self.R2 = newR2
  98.  
  99.     def paintEvent(self, event):
  100.         self.R1 = 90
  101.         self.R2 = 40
  102.         x = self.size().width()/2
  103.         y = self.size().height()/2
  104.         R = (self.R1 - self.R2)/2
  105.         qp = QPainter()
  106.         qp.begin(self)
  107.         qp.setPen(QPen(Qt.green, 8, Qt.SolidLine))
  108.         qp.drawEllipse(x-R/2, y-R/2, R, R)
  109.         qp.end()
  110.  
  111.  
  112. def main():
  113.   app = QApplication(sys.argv)
  114.   ex = MainWnd()
  115.   sys.exit(app.exec_())
  116.  
  117. if __name__ == '__main__':
  118.  main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top