def __init__(self, text_off: str, text_on: str, parent_instance: QPushButton): super().__init__(parent_instance.icon(), parent_instance.text(), parent_instance.parent()) self.setCheckable(self._is_toggleable) self.setSizePolicy(parent_instance.sizePolicy()) self.state: bool = parent_instance.isChecked() self.text_on: str = text_on self.text_off: str = text_off self._update_text_for_button_state() self.toggled.connect(self._toggle_button)
class DatePicker(QWidget): selectionChanged = Signal() def __init__(self, parent=None): super(DatePicker, self).__init__(parent) self.button = QPushButton(self) icon = QIcon("logo.svg") self.button.setIcon(icon) self.setFixedSize(32, 32) self.button.setFixedSize(32, 32) self.button.setIconSize(QSize(22, 22)) self.__margin__ = 5 self.dialog = QDialog() self.dialog.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.Popup) self.dialog.setFixedSize(480, 240) self.dialog.setLayout(QHBoxLayout()) self.calender = QCalendarWidget(self) self.dialog.layout().addWidget(self.calender) self.dialog.layout().setContentsMargins(0, 0, 0, 0) self.dialog.layout().setSpacing(0) self.button.clicked.connect(self, SLOT("showCalender()")) self.calender.selectionChanged.connect(self.__emitSelectionChanged__) @Slot() def showCalender(self): print('in show') p = self.mapToGlobal(QPoint(0, self.height() + self.__margin__)) self.dialog.setGeometry(p.x(), p.y(), 0, 0) self.dialog.show() def setIcon(self, icon): if type(icon) is QIcon: self.button.setIcon(icon) elif type(icon) is str: self.button.setIcon(QIcon(icon)) else: raise Exception( 'Wrong argument type, icon should be either PySide2.QtGui.QIcon or str "string"' ) def icon(self): return self.button.icon() def setIconSize(self, iconsize): if type(iconsize) is QSize: self.button.setIconSize(iconsize) elif type(iconsize) is int: self.button.setIcon(QSize(iconsize, iconsize)) elif type(type) is iter: import collections if isinstance(iconsize, collections.Iterable): if len(iconsize) == 1: self.setIconSize(iconsize[0]) elif len(iconsize) == 2: self.setIconSize(QSize(iconsize[0], iconsize[1])) else: raise Exception() else: raise Exception( "Wrong argument type, iconSize should be either PySide2.QtCore.QSize or int value or width and height " "or iterable contains one QSize, one int or two int values for width and height respectively" ) def iconSize(self): return self.button.iconSize() def setFirstDayOfWeek(self, dayOfWeek): if type(dayOfWeek) is Qt.DayOfWeek: self.calender.setFirstDayOfWeek(dayOfWeek) elif type(dayOfWeek) is int: if dayOfWeek < 1 or dayOfWeek > 7: raise Exception( "Wrong argument, dayOfWeek should be from 1 to 7 (Monday --> Sunday)" ) self.calender.setFirstDayOfWeek(Qt.DayOfWeek(dayOfWeek)) else: raise Exception( "Wrong type, dayOfWeek should be either PySide2.QtCore.Qt.DayOf or int (1 --> 7) (Monday --> Sunday)" ) def firstDayOfWeek(self): self.calender.firstDayOfWeek() def selectedDate(self): self.calender.selectedDate() def setSelectedDate(self, args, kwargs): self.calender.setSelectedDate(args, kwargs) def minimumDate(self): self.calender.minimumDate() def setMinimumDate(self): self.calender.setMinimumDate() def selectedDate(self): return self.calender.selectedDate() def __emitSelectionChanged__(self): self.selectionChanged.emit()
class installAir(confStack): def __init_stack__(self): self.dbg = False self._debug("installer load") self.description = (_("Air Apps Installer")) self.menu_description = (_("Install air apps")) self.icon = ('air-installer') self.tooltip = (_( "From here you can manage the air apps installed on your system")) self.index = 2 self.enabled = True self.level = 'system' # self.hideControlButtons() self.airinstaller = installer.AirManager() self.setStyleSheet(self._setCss()) #def __init__ def _load_screen(self): def _fileChooser(): fdia = QFileDialog() fdia.setNameFilter("air apps(*.air)") if (fdia.exec_()): fchoosed = fdia.selectedFiles()[0] self.inp_file.setText(fchoosed) self.updateScreen() box = QGridLayout() box.addWidget(QLabel(_("Air file")), 0, 0, 1, 1, Qt.AlignBottom) self.inp_file = QLineEdit() self.inp_file.setPlaceholderText(_("Choose file for install")) box.addWidget(self.inp_file, 1, 0, 1, 1, Qt.AlignTop) btn_file = QPushButton("...") btn_file.setObjectName("fileButton") btn_file.clicked.connect(_fileChooser) box.addWidget(btn_file, 1, 1, 1, 1, Qt.AlignLeft | Qt.AlignTop) self.frame = QFrame() box.addWidget(self.frame, 2, 0, 1, 1, Qt.AlignTop) framebox = QGridLayout() self.frame.setLayout(framebox) framebox.addWidget(QLabel(_("App name")), 0, 0, 1, 1, Qt.AlignBottom) self.btn_icon = QPushButton() self.btn_icon.setToolTip(_("Push for icon change")) framebox.addWidget(self.btn_icon, 0, 1, 2, 1, Qt.AlignLeft) self.inp_name = QLineEdit() self.inp_name.setObjectName("fileInput") self.inp_name.setPlaceholderText(_("Application name")) framebox.addWidget(self.inp_name, 1, 0, 1, 1, Qt.AlignTop) framebox.addWidget(QLabel(_("App description")), 2, 0, 1, 1, Qt.AlignBottom) self.inp_desc = QLineEdit() self.inp_desc.setPlaceholderText(_("Application description")) framebox.addWidget(self.inp_desc, 3, 0, 1, 2, Qt.AlignTop) self.setLayout(box) self.updateScreen() return (self) #def _load_screen def _loadAppData(self, air=""): if air: air_info = installer.AirManager().get_air_info(air) pb = air_info.get('pb', '') if pb: #Convert GDK pixbuf to QPixmap img = QtGui.QImage(GdkPixbuf.Pixbuf.get_pixels(pb), GdkPixbuf.Pixbuf.get_width(pb), GdkPixbuf.Pixbuf.get_height(pb), QtGui.QImage.Format_ARGB32 ) #,GdkPixbuf.Pixbuf.get_rowstride(pb)) icon = QtGui.QIcon(QtGui.QPixmap(img)) self.btn_icon.setIcon(icon) self.btn_icon.setIconSize(QSize(64, 64)) name = air_info.get('name', os.path.basename(self.inp_file.text())) self.inp_name.setText(name) else: self.inp_name.setText("") self.inp_desc.setText("") icon = QtGui.QIcon.fromTheme("application-x-air-installer") self.btn_icon.setIcon(icon) self.btn_icon.setIconSize(QSize(64, 64)) self.frame.setEnabled(False) #def _loadAppData def updateScreen(self): self.frame.setEnabled(True) air = self.inp_file.text() self._loadAppData(air) return True #def _udpate_screen def writeConfig(self): tmp_icon = tempfile.mkstemp()[1] self.btn_icon.icon().pixmap(QSize(64, 64)).save(tmp_icon, "PNG") subprocess.check_call(['/usr/bin/xhost', '+']) air = self.inp_file.text() try: ins = subprocess.check_call([ 'pkexec', '/usr/bin/air-helper-installer.py', 'install', air, tmp_icon ]) self.install_err = False except Exception as e: self._debug(e) subprocess.check_output([ "xdg-mime", "install", "/usr/share/mime/packages/x-air-installer.xml" ]) subprocess.check_output([ "xdg-mime", "default", "/usr/share/applications/air-installer.desktop", "/usr/share/mime/packages/x-air-installer.xml" ], input=b"") subprocess.check_call(['/usr/bin/xhost', '-']) self.showMsg(_("App %s installed succesfully" % os.path.basename(air))) #def writeConfig def _setCss(self): css = """ #fileButton{ margin:0px; padding:1px; } #fileInput{ margin:0px; } #imgButton{ margin:0px; padding:0px; }""" return (css)