def show_calorie_calc(self, row_count=0): ''' show calorie calculator :return: ''' if row_count > 0: row_count += 1 self.clear_table(None, None) self.stuff_table.clearContents() self.stuff_table.setColumnCount(3) self.stuff_table.setRowCount(row_count) self.stuff_table.setHorizontalHeaderLabels(['Amount', 'Unit', 'Name']) if row_count > 0: stuff_widget = QWidget() stuff_pixmap = QPixmap('icons/add.png') stuff_icon = QIcon() stuff_add_bt = QToolButton() stuff_icon.addPixmap(stuff_pixmap) stuff_add_bt.setIcon(stuff_icon) stuff_add_bt.setIconSize(QSize(8, 8)) stuff_add_bt.clicked.connect( lambda: self.stuff_table.insertRow(row_count - 1)) stuff_layout = QHBoxLayout() stuff_layout.addWidget(stuff_add_bt) stuff_widget.setLayout(stuff_layout) self.stuff_table.setCellWidget(row_count - 1, 2, stuff_widget)
def apply_status_to_icon(icon, index_status, work_tree_status): result = QIcon() overlay = status_icon[index_status, work_tree_status] for size in icon.availableSizes(): pixmap = icon.pixmap(size).copy() x, y = (size - overlay.size()).toTuple() QPainter(pixmap).drawPixmap(x, y, overlay) result.addPixmap(pixmap) return result
def __init__(self, parent=None): super(About, self).__init__(parent) icon = QIcon() icon.addPixmap( QPixmap(":/Images/aktools_48x48.png"), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.setWindowTitle("Tietoja") label = QLabel("Tehnyt: Aleksi Kauppila 2014") layout = QVBoxLayout() layout.addWidget(label) self.setLayout(layout)
def __init__(self, amount_files, parent=None): super(Progressbar, self).__init__(parent) self.amount_files = amount_files self.setWindowTitle("Mitataan...") icon = QIcon() icon.addPixmap( QPixmap(":/Images/aktools_48x48.png"), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.setMinimum(0) self.setMaximum(self.amount_files) self.setValue(0)
def __getitem__(self, path): icon = QIcon() has_images = False with disposable_hicon(get_file_icon(path)) as hicon: pixmap = pixmap_from_hicon(hicon) if pixmap: icon.addPixmap(pixmap) has_images = True with disposable_hicon(get_file_icon(path, large=True)) as hicon: pixmap = pixmap_from_hicon(hicon) if pixmap: icon.addPixmap(pixmap) has_images = True if has_images: return icon return self.qt_provider.icon(QFileIconProvider.File)
def __init__(self, files_not_processed, parent=None): super(ErrorDialog, self).__init__(parent) self.files_not_processed = files_not_processed self.setMinimumWidth(600) self.setWindowTitle(u'Kaikkia tiedostoja ei pystytty mittaamaan') icon = QIcon() icon.addPixmap( QPixmap(":/Images/aktools_48x48.png"), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.text_browser = QTextBrowser() self.label = QLabel(u'Seuraavissa tiedostoissa havaittiin virheitä:') self.layout = QVBoxLayout() self.layout.addWidget(self.label) self.layout.addWidget(self.text_browser) self.setLayout(self.layout) self.list_files_not_processed()
class UsbResetter(QWidget): def __init__(self): super(UsbResetter, self).__init__() self.P = UR_thread() self.thr_counter = 0 self.Looping = None self.Hidden = None self.Fhidden = None self.s_error = "QStatusBar{color:red;font-weight:1000;}" self.s_loop = "QStatusBar{color:black;font-weight:1000;}" self.s_norm = "QStatusBar{color:blue;font-style:italic;" self.s_norm += "font-weight:500;}" favicon = r_path("images/favicon.png") logo = r_path("images/logo.png") if name == 'nt': favicon = r_path("images\\favicon.png") logo = r_path("images\\logo.png") self.favicon = QIcon(favicon) self.plogo = logo self.logo = QIcon(logo) self.setStyle() mlayout = QVBoxLayout() self.setAbout(mlayout) self.setUlist(mlayout) self.setCboxs(mlayout) self.setReset(mlayout) self.setLoop(mlayout) self.setSb(mlayout) # functionalities self.set_list() self.rootWarn() # initiation self.activateWindow() self.setLayout(mlayout) self.show() def setSb(self, m): self.statusbar = QStatusBar() m.addWidget(self.statusbar) def setStyle(self): self.setMaximumWidth(350) self.setMinimumWidth(350) self.setMaximumHeight(340) self.setMinimumHeight(340) self.setWindowTitle("usb-resetter 1.0") self.setWindowIcon(self.favicon) self.show() def setAbout(self, m): self.pushButton = QPushButton() self.icon1 = QIcon() self.icon1.addPixmap(QPixmap(self.plogo), QIcon.Normal, QIcon.Off) self.pushButton.setIcon(self.icon1) self.pushButton.setIconSize(QSize(300, 100)) self.pushButton.clicked.connect(self.show_about) m.addWidget(self.pushButton) def setUlist(self, m): self.comboBox = QComboBox() m.addWidget(self.comboBox) def setCboxs(self, m): ml = QVBoxLayout() fl = QHBoxLayout() self.checkBox_2 = QCheckBox("Audio") self.checkBox_3 = QCheckBox("Mass storage") self.checkBox_2.setToolTip("Filter by audio devices") self.checkBox_3.setToolTip("Filter by mass storage devices") fl.addWidget(self.checkBox_2) fl.addWidget(self.checkBox_3) ml.addLayout(fl) sl = QHBoxLayout() self.checkBox_4 = QCheckBox("Network") self.checkBox_4.setToolTip("Filter by network devices") self.checkBox_5 = QCheckBox("Human interface") self.checkBox_5.setToolTip("Filter by Keyboard, mouse, joystick ..etc") sl.addWidget(self.checkBox_4) sl.addWidget(self.checkBox_5) ml.addLayout(sl) self.checkBox_2.clicked.connect(self.set_list) self.checkBox_3.clicked.connect(self.set_list) self.checkBox_4.clicked.connect(self.set_list) self.checkBox_5.clicked.connect(self.set_list) m.addLayout(ml) def setReset(self, m): self.pushButton_2 = QPushButton("Reset it") font = QFont() font.setPointSize(17) font.setWeight(75) font.setBold(True) self.pushButton_2.setFont(font) self.pushButton_2.clicked.connect(self.setbut_reset) m.addWidget(self.pushButton_2) def setLoop(self, m): ml = QHBoxLayout() self.checkBox = QCheckBox("Looping") self.checkBox.setToolTip("To repeat resetting for specified duration") self.lineEdit = QLineEdit() self.lineEdit.setToolTip("Duration in-which the resetting is done") self.pushButton_3 = QPushButton("Stop") self.pushButton_3.setToolTip("Stop looping") ml.addWidget(self.checkBox) ml.addWidget(self.lineEdit) ml.addWidget(self.pushButton_3) self.pushButton_3.setEnabled(False) self.lineEdit.setEnabled(False) self.lineEdit.setPlaceholderText("duration in seconds") self.checkBox.clicked.connect(self.loop_status) self.pushButton_3.clicked.connect(self.in_loop) m.addLayout(ml) # Functionalities def show_about(self): Amsg = "<center>All credit reserved to the author of " Amsg += "usb-resetter version 1.0" Amsg += ", This work is a free, open-source project licensed " Amsg += " under Mozilla Public License version 2.0 . <br><br>" Amsg += " visit us for more infos and how-tos :<br> " Amsg += "<b><a href='https://usb-resetter.github.io/'> " Amsg += "https://usb-resetter.github.io/ </a> </b></center>" Amsgb = "About usb-resetter" v = QMessageBox.about(self, Amsgb, Amsg) v = str(v) return v def closeEvent(self, event=None): if self.Hidden is None: response = QMessageBox.question( self, "Hide or close", "Do you want to hide the application ?", QMessageBox.Yes, QMessageBox.No) if response == QMessageBox.Yes: if event is not None: event.ignore() self.Hidden = True self.hide() elif response == QMessageBox.No: if event is not None: event.accept() return self.exitEvent() else: return False else: return self.exitEvent() def exitEvent(self): if self.P.isRunning(): response = QMessageBox.question( self, "Making sure", "Sure, you want to exit while looping ?", QMessageBox.Yes, QMessageBox.No) if response == QMessageBox.Yes: self.P.stop() exit(0) else: return False else: exit(0) def get_list(self): ol = [] if self.checkBox_2.isChecked(): ol.append(1) if self.checkBox_3.isChecked(): ol.append(8) if self.checkBox_4.isChecked(): ol.append(2) if self.checkBox_5.isChecked(): ol.append(3) if len(ol) >= 1: return listd(ol, True) else: return listd(None, True) def set_list(self): self.comboBox.clear() its = self.get_list() if len(its) >= 1: self.comboBox.addItems(its) self.pushButton_2.setEnabled(True) self.checkBox.setEnabled(True) else: self.pushButton_2.setEnabled(False) self.checkBox.setEnabled(False) self.lineEdit.setEnabled(False) self.pushButton_3.setEnabled(False) def setbut_reset(self): t = self.comboBox.currentText() if self.Looping is None: if resetit(t): self.statusbar.setStyleSheet(self.s_norm) self.statusbar.showMessage( "# Done: usb device got reset") return True self.statusbar.setStyleSheet(self.s_error) if name != 'nt': self.statusbar.showMessage( "# Error: maybe you need sudo permissions") else: self.statusbar.showMessage( "# Error: maybe you need to add device to libusb") return False else: tl = self.lineEdit.text() self.statusbar.setStyleSheet(self.s_error) if len(tl) == 0: self.statusbar.showMessage( "# Error: you must enter duration for looping") return False try: self.thr_counter += 1 tl = int(tl) if tl < 2: self.statusbar.showMessage( "# Error: the least allowed value is 2") return False self.P = UR_thread(t, tl, self.thr_counter) self.P.start() self.P.somesignal.connect(self.handleStatusMessage) self.P.setTerminationEnabled(True) self.in_loop(False) except: self.statusbar.showMessage( "# Error: only valid integers allowed") return False def loop_status(self): if self.Looping: self.Looping = None self.lineEdit.setEnabled(False) self.pushButton_3.setEnabled(False) else: self.Looping = True self.lineEdit.setEnabled(True) return True def in_loop(self, stop=True): if stop: if self.P.isRunning(): self.P.stop() self.pushButton_3.setEnabled(False) self.pushButton_2.setEnabled(True) self.checkBox.setEnabled(True) if self.checkBox.isChecked(): self.lineEdit.setEnabled(True) self.checkBox_2.setEnabled(True) self.checkBox_3.setEnabled(True) self.checkBox_4.setEnabled(True) self.checkBox_5.setEnabled(True) self.comboBox.setEnabled(True) else: self.pushButton_3.setEnabled(True) self.pushButton_2.setEnabled(False) self.checkBox.setEnabled(False) self.lineEdit.setEnabled(False) self.checkBox_2.setEnabled(False) self.checkBox_3.setEnabled(False) self.checkBox_4.setEnabled(False) self.checkBox_5.setEnabled(False) self.comboBox.setEnabled(False) return True def rootWarn(self): if platform[:len(platform) - 1] == "linux": from os import getuid if getuid() != 0: self.statusbar.setStyleSheet(self.s_error) self.statusbar.showMessage( "# Error: you must use sudo on Linux") @Slot(object) def handleStatusMessage(self, message): self.statusbar.setStyleSheet(self.s_loop) if message[:7] == '# Error': self.in_loop() self.statusbar.setStyleSheet(self.s_error) self.statusbar.showMessage(message)
def ChangeButton(self, buttonChosen, imageOpen): icon = QIcon() icon.addPixmap(QPixmap(":/icons/assets/drawable/" + imageOpen + ".png"), QIcon.Normal, QIcon.Off) buttonChosen.setIcon(icon)
def setupUi(self): #The superclass sets up most of the UI. super(MainWindow, self).setupUi(self) #self.setUnifiedTitleAndToolBarOnMac(True) webview = self.webViewController().webView() self.setCentralWidget(webview) #Connect all the actions. #File actions self.connect(self.actionNew, SIGNAL("triggered()"), self.doActionNew) self.connect(self.actionOpen, SIGNAL("triggered()"), self.doActionOpen) self.connect(self.actionSave, SIGNAL("triggered()"), self.doActionSave) self.connect(self.actionSaveAs, SIGNAL("triggered()"), self.doActionSaveAs) self.connect(self.actionSaveAll, SIGNAL("triggered()"), self.doActionSaveAll) self.connect(self.actionPrint, SIGNAL("triggered()"), self.doActionPrint) self.connect(self.actionQuit, SIGNAL("triggered()"), self.doActionQuit) #Edit actions #These actions are provided by the WebView instance. self.actionCopy = webview.pageAction(QWebPage.Copy) iconCopy = QIcon() iconCopy.addPixmap(QPixmap(":/images/images/copy-item.png"), QIcon.Normal, QIcon.Off) self.actionCopy.setIcon(iconCopy) self.actionCopy.setObjectName("actionCopy") self.actionCut = webview.pageAction(QWebPage.Cut) iconCut = QIcon() iconCut.addPixmap(QPixmap(":/images/images/Scissors.png"), QIcon.Normal, QIcon.Off) self.actionCut.setIcon(iconCut) self.actionCut.setObjectName("actionCut") self.actionPaste = webview.pageAction(QWebPage.Paste) iconPaste = QIcon() iconPaste.addPixmap(QPixmap(":/images/images/paste2_30.png"), QIcon.Normal, QIcon.Off) self.actionPaste.setIcon(iconPaste) self.actionPaste.setObjectName("actionPaste") self.actionUndo = webview.pageAction(QWebPage.Undo) self.actionUndo.setObjectName("actionUndo") self.actionRedo = webview.pageAction(QWebPage.Redo) self.actionRedo.setObjectName("actionRedo") self.menuEdit.addAction(self.actionCopy) self.menuEdit.addAction(self.actionCut) self.menuEdit.addAction(self.actionPaste) self.menuEdit.addAction(self.actionUndo) self.menuEdit.addAction(self.actionRedo) self.toolBar.insertAction(self.actionEvaluateWorksheet, self.actionCopy) self.toolBar.insertAction(self.actionEvaluateWorksheet, self.actionCut) self.toolBar.insertAction(self.actionEvaluateWorksheet, self.actionPaste) self.toolBar.insertSeparator(self.actionEvaluateWorksheet) #This is normally done in retranslateUi, but that method has already been called. self.retranslateEditMenuUi() #Worksheet actions self.connect(self.actionWorksheetProperties, SIGNAL("triggered()"), self.doActionWorksheetProperties) self.connect(self.actionEvaluateWorksheet, SIGNAL("triggered()"), self.doActionEvaluateWorksheet) self.connect(self.actionInterrupt, SIGNAL("triggered()"), self.doActionInterrupt) self.connect(self.actionRestartWorksheet, SIGNAL("triggered()"), self.doActionRestartWorksheet) self.connect(self.actionHideAllOutput, SIGNAL("triggered()"), self.doActionHideAllOutput) self.connect(self.actionShowAllOutput, SIGNAL("triggered()"), self.doActionShowAllOutput) self.connect(self.actionDeleteAllOutput, SIGNAL("triggered()"), self.doActionDeleteAllOutput) #Miscellaneous actions self.connect(self.actionAbout, SIGNAL("triggered()"), self.doActionAbout) self.connect(self.actionOnlineDocumentation, SIGNAL("triggered()"), self.doActionOnlineDocumentation) self.connect(self.actionSageServer, SIGNAL("triggered()"), self.doActionSageServer) if self.isWelcome: #Display the welcome screen. self.showWelcome()
def ChangeButton(self, buttonChosen, imageOpen): icon = QIcon() icon.addPixmap( QPixmap(":/icons/assets/drawable/" + imageOpen + ".png"), QIcon.Normal, QIcon.Off) buttonChosen.setIcon(icon)
def add_tabs(self): """ adds new tabs """ global logger if ('Inventory', True) in self.access: logger.info('initiating Inventory') icon = QIcon() icon.addPixmap(QPixmap(":/images/inventory.png"), QIcon.Normal, QIcon.Off) from inventory.inventory import Inventory inventory = Inventory() # inventory.inventory_tab_1.setToolTip("Inventory Section") self.main_tabWidget.addTab(inventory.inventory_tab_1, icon, "") inventory.inventory_detail_tabWidget.setCurrentIndex(0) else: self.inventory_frame_1.setVisible(False) self.progress.setLabelText('Inventory Done....') self.progress.setValue(2) if ('Billing', True) in self.access: logger.info('initiating Billing') icon1 = QIcon() icon1.addPixmap(QPixmap(":/images/billing.png"), QIcon.Normal, QIcon.Off) from billing.billing import Billing bill = Billing() # bill.billing_tab_2.setToolTip("Billing Section") self.main_tabWidget.addTab(bill.billing_tab_2, icon1, "") bill.billing_detail_tabWidget.setCurrentIndex(0) else: self.billing_frame_2.setVisible(False) self.progress.setLabelText('Billing Done...') self.progress.setValue(3) if ('Employee', True) in self.access: logger.info('initiating Employee') icon2 = QIcon() icon2.addPixmap(QPixmap(":/images/employee.png"), QIcon.Normal, QIcon.Off) from employee.employee import Employee employee = Employee() # employee.employee_tab_3.setToolTip("Employee Section") self.main_tabWidget.addTab(employee.employee_tab_3, icon2, "") employee.employee_detail_tabWidget.setCurrentIndex(0) else: self.employee_frame_3.setVisible(False) self.progress.setLabelText('Employee Done...') self.progress.setValue(4) if ('Menu', True) in self.access: logger.info('initiating Menu') icon3 = QIcon() icon3.addPixmap(QPixmap(":/images/menu.png"), QIcon.Normal, QIcon.Off) from menu.menu import Menu menu = Menu() # menu.menu_tab_4.setToolTip("Menu Section") self.main_tabWidget.addTab(menu.menu_tab_4, icon3, "") menu.menu_detail_tabWidget.setCurrentIndex(0) else: self.menu_frame_4.setVisible(False) self.progress.setLabelText('Menu Done....') self.progress.setValue(5) if ('Report', True) in self.access: logger.info('initiating Report') icon4 = QIcon() icon4.addPixmap(QPixmap(":/images/report.png"), QIcon.Normal, QIcon.Off) from report.report import Report report = Report() # report.report_tab_5.setToolTip("Report Section") self.main_tabWidget.addTab(report.report_tab_5, icon4, "") report.report_detail_tabWidget.setCurrentIndex(0) else: self.report_frame_5.setVisible(False) self.progress.setLabelText('Report Done....') self.progress.setValue(6) if ('Waste', True) in self.access: logger.info('initiating Waste') icon5 = QIcon() icon5.addPixmap(QPixmap(":/images/waste.png"), QIcon.Normal, QIcon.Off) from waste.waste import Waste waste = Waste() # waste.waste_tab_6.setToolTip("Waste Section") self.main_tabWidget.addTab(waste.waste_tab_6, icon5, "") waste.waste_detail_tabWidget.setCurrentIndex(0) else: self.waste_frame_6.setVisible(False) self.progress.setLabelText('Waste Done....') self.progress.setValue(7)
class Kitchen(QMainWindow, kitchen.Ui_Kitchen): def __init__(self, start, hive_connection): super(Kitchen, self).__init__() self.setupUi(self) # Hive database self.database_connector = hive_connection self.recipe_reader = RecipeReader(self.database_connector) self.recipe_reader.load_recipes() # Recipe List self.recipes = self.recipe_reader.get_recipes() item = QListWidgetItem('< None >') self.recipe_list.addItem(item) for recipe in self.recipes: item = QListWidgetItem(recipe) self.recipe_list.addItem(item) self.recipe_list.itemClicked.connect(self.set_ingredients) self.recipe_list.currentItemChanged.connect(self.clear_table) self.regex = re.compile('([0-9,.]+)([a-zA-Z]*)') self.start = start self.cancel_bt.clicked.connect(self.show_start) # name widget chooser self.mid = MealInputDialog('Title', 'Message', 'Name', 'Links', ('Cancel', 'Accept'), lambda x, y: print(x)) # language tag self.lang_tag = 'de' # language dicts self.stuff_hor_header_labels = { 'en': ['Amount', 'Unit', 'Name'], 'de': ['Menge', 'Einheit', 'Name'] } self.weekly_hor_header_labels = {'en': 'Meal', 'de': 'Gericht'} self.weekly_vert_header_labels = { 'en': [ 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday' ], 'de': [ 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag' ] } self.set_language_label_text = { 'en': 'set Language:', 'de': 'Sprache wechseln:' } self.rad_buttons_text = { 'en': [ 'Calories Summation', 'Show stock (empty things)', 'Show stock (existing things)', 'Bought goods' ], 'de': [ 'Kalorienrechner', 'Leere Nahrungsmittel', 'Vorhandene Nahrungsmittel', 'Einkaufsinventur' ] } self.tab_text = { 'en': ['Recipes', 'Weekly Rota', 'Playlist'], 'de': ['Rezepte', 'Wochenplan', 'Playlist'] } self.buttons_text = { 'en': [('Calculate calories', 'Push to Database'), 'Cancel'], 'de': [('Kalorien berechnen', 'Übernehmen'), 'Zurück'] } self.button_bought_calc_val = True # Tables self.stuff_table.setColumnCount(3) if not pyside_import: self.stuff_table.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) else: self.stuff_table.horizontalHeader().setResizeMode( QHeaderView.Stretch) self.weekly_tw.setColumnCount(1) self.weekly_tw.setRowCount(7) self.toggle_language() if not pyside_import: self.weekly_tw.verticalHeader().setSectionResizeMode( QHeaderView.Stretch) self.weekly_tw.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) else: self.weekly_tw.verticalHeader().setResizeMode(QHeaderView.Stretch) self.weekly_tw.horizontalHeader().setResizeMode( QHeaderView.Stretch) # Time self.time_lcd.setDigitCount(8) timer = QTimer(self) timer.timeout.connect(self.show_time) timer.start(1000) self.show_time() # Timer self.timer_lcd.setDigitCount(8) self.timer_dial.setMaximum(3600) if pyside_import: self.timer_dial.dialMoved.connect(self.set_timer) else: self.timer_dial.valueChanged.connect(self.set_timer) self.timer_timer = QTimer(self) self.timer_timer.timeout.connect(self.count_downwards) self.timer_bt.clicked.connect(self.timer_start) self.timer_time = 0 self.timer_running = False bl_pixmap = QPixmap('icons/aperture.png') red_pixmap = QPixmap('icons/aperture_red.png') self.icon_bl = QIcon() self.icon_bl.addPixmap(bl_pixmap) self.icon_red = QIcon() self.icon_red.addPixmap(red_pixmap) # Music buttons # prev prev_icon = QIcon() prev_pixmap = QPixmap('icons/prev.png') prev_icon.addPixmap(prev_pixmap) self.prev_bt.setIcon(prev_icon) # next next_icon = QIcon() next_pixmap = QPixmap('icons/next.png') next_icon.addPixmap(next_pixmap) self.next_bt.setIcon(next_icon) # play self.play_icon = QIcon() play_pixmap = QPixmap('icons/play.png') self.play_icon.addPixmap(play_pixmap) self.pause_icon = QIcon() pause_pixmap = QPixmap('icons/pause.png') self.pause_icon.addPixmap(pause_pixmap) self.play_pause_bt.setIcon(self.play_icon) # stop stop_icon = QIcon() stop_pixmap = QPixmap('icons/stop.png') stop_icon.addPixmap(stop_pixmap) self.stop_bt.setIcon(stop_icon) # search search_icon = QIcon() search_pixmap = QPixmap('icons/search2.png') search_icon.addPixmap(search_pixmap) self.go_bt.setIcon(search_icon) # table self.weekly_meals = {} self.stuff_table.cellClicked.connect(self.item_clicked) self.weekly_tw.cellClicked.connect(self.weekly_cell_clicked) # button calc self.calculate_bt.clicked.connect(self.calculate_cal) self.lcd_palette = self.calorie_lcd.palette() self.lcd_palette.setColor(self.lcd_palette.WindowText, QColor(102, 255, 102)) self.calorie_lcd.setPalette(self.lcd_palette) # radio buttons self.show_emp_rad.clicked.connect( lambda: self.radio_button_clicked(True, True)) self.show_rad.clicked.connect( lambda: self.radio_button_clicked(True, False)) self.cal_rad.clicked.connect( lambda: self.radio_button_clicked(True, None)) self.bought_rb.clicked.connect( lambda: self.radio_button_clicked(False, None)) # video stand_by_image = cv2.imread('src/default.png') self.update_frame(stand_by_image) #self.queue = queue.Queue() #self.capture_thread = threading.Thread(target=self.grab, args=(0, self.queue, stand_by_image)) #self.timer = QTimer(self) #self.timer.timeout.connect(self.update_frame) #self.timer.start(1) #global running #running = True #self.capture_thread.start() # language button self.language_bt.clicked.connect(self.toggle_language) # Barcode queue and thread # TODO: use different way, not input. maybe get serial to work or make an input window, or start a new program #self.bar_thread = multiprocessing.Process(target=Kitchen.read_barcodes, # args=(self.update_invent_table_barcode, )) #self.bar_thread.start() def update_invent_table_barcode(self, bar): ''' update the inventory table via barcode :param bar: recieved barcode :return: ''' row_count = self.stuff_table.rowCount() self.stuff_table.insertRow(row_count - 1) pass def radio_button_clicked(self, up_cal, empty_full): ''' change button behavior if radio buttons are clicked :param up_cal: if calorien should be :param empty_full: :return: ''' self.calorie_lcd.display('0') if up_cal: if empty_full is None: self.show_calorie_calc() else: self.show_empty_full_items(empty=empty_full) if self.button_bought_calc_val: self.calculate_bt.setText( self.buttons_text[self.lang_tag][0][0]) self.toggle_signal_event(self.calculate_bt.clicked, self.calculate_cal, self.update_database) self.button_bought_calc_val = False else: self.show_calorie_calc(row_count=2) if not self.button_bought_calc_val: self.calculate_bt.setText( self.buttons_text[self.lang_tag][0][1]) self.toggle_signal_event(self.calculate_bt.clicked, self.update_database, self.calculate_cal) self.button_bought_calc_val = True def update_database(self): ''' update the database :return: ''' for i in range(self.stuff_table.rowCount()): vol = '' unit = '' name = '' if self.stuff_table.item(i, 0) is not None and self.stuff_table.item(i, 1) is not None and \ self.stuff_table.item(i, 2) is not None: vol = self.stuff_table.item(i, 0).text() unit = self.stuff_table.item(i, 1).text() name = self.stuff_table.item(i, 2).text() else: return self.recipe_reader.get_hive_connection().set_volume_of_item( name, '%s%s' % (vol, unit)) def toggle_language(self): ''' set the language of the gui :return: ''' self.lang_tag = 'de' if self.lang_tag == 'en' else 'en' self.language_bt.setText(self.lang_tag) self.label_2.setText(self.set_language_label_text[self.lang_tag]) # weekly table self.weekly_tw.setHorizontalHeaderLabels( [self.weekly_hor_header_labels[self.lang_tag]]) self.weekly_tw.setVerticalHeaderLabels( self.weekly_vert_header_labels[self.lang_tag]) # stuff table self.stuff_table.setHorizontalHeaderLabels( self.stuff_hor_header_labels[self.lang_tag]) # buttons button_text_i = 0 if self.button_bought_calc_val else 1 self.cancel_bt.setText(self.buttons_text[self.lang_tag][1]) self.calculate_bt.setText( self.buttons_text[self.lang_tag][0][button_text_i]) self.button_bought_calc_val = False # radio buttons self.cal_rad.setText(self.rad_buttons_text[self.lang_tag][0]) self.show_emp_rad.setText(self.rad_buttons_text[self.lang_tag][1]) self.show_rad.setText(self.rad_buttons_text[self.lang_tag][2]) self.bought_rb.setText(self.rad_buttons_text[self.lang_tag][3]) # tabs self.gloabal_tab.setTabText(0, self.tab_text[self.lang_tag][0]) self.gloabal_tab.setTabText(1, self.tab_text[self.lang_tag][1]) self.gloabal_tab.setTabText(2, self.tab_text[self.lang_tag][2]) def weekly_cell_clicked(self, row, col): ''' weekly play cell clicked :param row: :param col: :return: ''' item = self.weekly_tw.item(row, col) if item is None or item.text() == '': day = self.weekly_vert_header_labels[self.lang_tag][row] title = {'en': 'Enter new Meal', 'de': 'Neue Mahlzeit hinzufügen'} message = { 'en': 'Please enter the meal and link for %s' % day, 'de': 'Bitte geben sie ein Gericht und entsprechenden Link für den %s ein' % day } buttons = { 'en': ('Cancel', 'Accept'), 'de': ('Abbrechen', 'Annehmen') } # TODO: handle links self.mid.change_settings( title[self.lang_tag], message[self.lang_tag], "Name", "Links", (buttons[self.lang_tag][0], buttons[self.lang_tag][1]), lambda x, y: self.weekly_tw.setItem(row, col, QTableWidgetItem(x))) self.mid.show() def closeEvent(self, event): ''' override closing event :param event: :return: ''' global running running = False self.bar_thread.terminate() self.bar_thread.join() def update_frame(self, img): ''' update the image :return: ''' #if not self.queue.empty(): # frame = self.queue.get() #img = frame['img'] img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) size = self.video_view.size() img = cv2.resize(img, (size.width() - 10, size.height() - 10)) height, width, bpc = img.shape bpl = bpc * width image = QImage(img.data, width, height, bpl, QImage.Format_RGB888) pitem = QGraphicsPixmapItem(QPixmap.fromImage(image)) scene = QGraphicsScene() scene.addItem(pitem) self.video_view.setScene(scene) def calculate_cal(self): ''' calculate calories out of table :return: ''' all_there = True names = [] for i in range(self.stuff_table.rowCount() - 1): if self.stuff_table.item(i, 2) is None: # if item is empty continue continue names.append(self.stuff_table.item(i, 2).text()) if not self.recipe_reader.get_hive_connection().check_if_in_stock( self.stuff_table.item(i, 2).text()): # if the item is not in the stock mark it as red self.stuff_table.item(i, 0).setBackground(QColor(255, 128, 128)) self.stuff_table.item(i, 1).setBackground(QColor(255, 128, 128)) self.stuff_table.item(i, 2).setBackground(QColor(255, 128, 128)) all_there = False elif self.stuff_table.item(i, 0).background() == QColor( 255, 128, 128): all_there = False if all_there: # if all cals are there calculate everything and post it cals = 0 for name in names: if not name == '': cals += int(self.recipe_reader.get_hive_connection(). get_cal_for_name(name)) self.calorie_lcd.display(cals) self.calorie_lcd.setSegmentStyle(QLCDNumber.Flat) def show_empty_full_items(self, empty): ''' show empty items :return: ''' self.clear_table(None, None) self.stuff_table.setColumnCount(3) self.stuff_table.setHorizontalHeaderLabels(['Volume', 'State', 'Name']) items = self.recipe_reader.get_hive_connection().get_empty_stock_items( empty) self.stuff_table.setRowCount(len(items)) for i, item in enumerate(items): self.stuff_table.setItem(i, 0, QTableWidgetItem(str(item.vol))) self.stuff_table.setItem(i, 1, QTableWidgetItem(item.state)) self.stuff_table.setItem(i, 2, QTableWidgetItem(item.name)) if empty: self.stuff_table.item(i, 0).setBackground(QColor(255, 128, 128)) def show_calorie_calc(self, row_count=0): ''' show calorie calculator :return: ''' if row_count > 0: row_count += 1 self.clear_table(None, None) self.stuff_table.clearContents() self.stuff_table.setColumnCount(3) self.stuff_table.setRowCount(row_count) self.stuff_table.setHorizontalHeaderLabels(['Amount', 'Unit', 'Name']) if row_count > 0: stuff_widget = QWidget() stuff_pixmap = QPixmap('icons/add.png') stuff_icon = QIcon() stuff_add_bt = QToolButton() stuff_icon.addPixmap(stuff_pixmap) stuff_add_bt.setIcon(stuff_icon) stuff_add_bt.setIconSize(QSize(8, 8)) stuff_add_bt.clicked.connect( lambda: self.stuff_table.insertRow(row_count - 1)) stuff_layout = QHBoxLayout() stuff_layout.addWidget(stuff_add_bt) stuff_widget.setLayout(stuff_layout) self.stuff_table.setCellWidget(row_count - 1, 2, stuff_widget) def item_clicked(self, row, col): ''' action to perform when one item is clicked :param row: item row :param col: item col :return: ''' item = self.stuff_table.item(row, col) if item is None: # if Item is none ignore return bg = item.background() if bg == QColor(255, 128, 128): # if item is colorful ask the user to add cals name = self.stuff_table.item(row, 2).text() text, ok = QInputDialog.getText( self, 'Calorie Input Dialog', 'Enter the calories per 100g for %s:' % name) reg = re.compile('([0-9,.]+)') cif = reg.match(text) if cif is None or len(cif.group(1)) == 0: return # if cal is added reprint the item self.recipe_reader.get_hive_connection().set_calorie_for_name( name, int(cif.group(1))) self.stuff_table.item(row, 0).setBackground(QColor(0, 0, 0)) self.stuff_table.item(row, 1).setBackground(QColor(0, 0, 0)) self.stuff_table.item(row, 2).setBackground(QColor(0, 0, 0)) def clear_table(self, old, new): ''' clear the table :param old: not used :param new: not used :return: ''' for i in range(self.stuff_table.rowCount()): self.stuff_table.removeRow(i) def set_ingredients(self, item): ''' action for recipe choosed :param item: choosen item :return: ''' if item.text() == '< None >': # if None is choosen set up empty table self.show_calorie_calc(20) else: ing = self.recipe_reader.get_ingredients(item.text()) ing_dic = {} self.stuff_table.setRowCount(len(ing)) # set Row count to current list length for i, (vol, name, cal) in enumerate(ing): vol_gr = self.regex.match(str(vol)) # regex the amount volume = self.recipe_reader.get_hive_connection( ).get_volume_of_item(name) volume = self.regex.match(volume) if vol_gr is not None: vol = float(vol_gr.group(1)) unit = vol_gr.group(2) else: vol = 1.0 unit = 'Priese' if name in ing_dic.keys(): i, vol_o, unit_o = ing_dic[name] vol += vol_o else: self.stuff_table.setItem(i, 2, QTableWidgetItem(name)) # fill table ing_dic[name] = (i, vol, unit) self.stuff_table.setItem(i, 0, QTableWidgetItem(str(vol))) self.stuff_table.setItem(i, 1, QTableWidgetItem(unit)) volume = volume.group(1) if int(volume) == 0: self.stuff_table.item(i, 0).setBackground(QColor(247, 188, 7)) if cal is None: self.stuff_table.item(i, 2).setBackground( QColor(255, 128, 128)) def set_timer(self, value): ''' set the timer :param value: value to set to :return: ''' self.timer_time = int(value) self.timer_lcd.display(Kitchen.format_time(value)) def timer_start(self): ''' start/stop the timer :return: ''' if self.timer_running: self.timer_running = not self.timer_running self.timer_bt.setIcon(self.icon_bl) self.set_timer(0) self.timer_dial.setValue(0) self.timer_time = 0 self.timer_dial.setDisabled(False) self.timer_timer.stop() else: if not self.timer_time == 0: self.timer_dial.setDisabled(True) self.timer_timer.start(1000) self.timer_running = not self.timer_running self.timer_bt.setIcon(self.icon_red) def count_downwards(self): ''' timer count down :return: ''' value = self.timer_time - 1 self.timer_time = value if value == 0: self.timer_dial.setDisabled(False) self.timer_timer.stop() self.timer_lcd.display(Kitchen.format_time(value)) def show_time(self): ''' clock :return: ''' time = QTime.currentTime() text = time.toString('hh:mm:ss') self.time_lcd.display(text) def show_start(self): ''' show start window :return: ''' self.hide() self.start.show() @staticmethod def format_time(number): ''' format a number to time :param number: number to format :return: ''' sek = number % 60 minutes = int(number / 60) % 60 hours = int(number / 3600) if sek < 10: sek = '0%i' % sek else: sek = str(sek) if minutes < 10: minutes = '0%i' % minutes else: minutes = str(minutes) if hours < 10: hours = '0%i' % hours else: hours = str(hours) return '%s:%s:%s' % (hours, minutes, sek) # currently ignore this method @staticmethod def grab(cam, grab_queue, standby_img): ''' grabbing the next image and check if the camera is still connected :param cam: camera number :param grab_queue: queue :param standby_img: standby_img that has to be shown if no camera is found :return: ''' global running capture = cv2.VideoCapture(cam) while running: frame = {} if capture.isOpened(): retval, img = capture.read() if not retval: frame['img'] = standby_img #capture.release() #capture = cv2.VideoCapture(cam) else: frame['img'] = img else: frame['img'] = standby_img capture.open() if grab_queue.qsize() < 10: grab_queue.put(frame) @staticmethod def toggle_signal_event(signal, new_event, old_event): ''' change the event of an signal slot :param signal: signal of an item :param new_event: new event method :param old_event: old event method :return: ''' if new_event is None: return signal.disconnect() signal.connect(new_event) @staticmethod def read_barcodes(update): ''' barcode reader :param bar_queue: queue for data :return: ''' while True: bar = input() if len(bar) > 0: if bar == '000000000': break update(bar) return
class WarningsDialog(QDialog, Ui_WarningsDialog): """ This is the Controller (more in the line of a code-behind file) for the small Warnings Dialog. The UI is handled separately by QT Designer 4 with the *.ui file. @since: 2011-05-20 """ __author__ = "Moritz Wade" __contact__ = "*****@*****.**" __copyright__ = "Zuse Institute Berlin 2011" def __init__(self, parent=None, warningAction=None, warningService=None): """ Constructor @param parent: Qt widget parent of this dialog window @type parent: QWidget @param warningAction: The action to connect to. @type warningAction: QAction """ super(WarningsDialog, self).__init__(parent) self.setupUi(self) self.setWarningAction(warningAction) self.setWarningService(warningService) self.statusBarService = StatusBarService() self.errorString = "" self.errorMsgTextEdit.setPlainText(self.errorString) self.iconWarning = QIcon() self.iconWarning.addPixmap(QPixmap(":/tango-status-32px/images/tango-icon-theme/32x32/status/weather-severe-alert.png"), QIcon.Normal, QIcon.Off) self.iconNoWarning = QIcon() self.iconNoWarning.addPixmap(QPixmap(":/tango-status-32px/images/tango-icon-theme/32x32/status/weather-clear.png"), QIcon.Normal, QIcon.Off) def setWarningAction(self, warningAction): """ Sets the warning QAction (for setting icons and to connect to its triggered SIGNAL to show self). """ self.warningAction = warningAction self._connectToWarningAction() def setWarningService(self, warningService): """ Sets the WarningService (to whose SIGNALs to listen to). """ self.warningService = warningService self._connectToWarningService() def updateWarnings(self, errorString, desc): """ Having updated the errorString elsewhere, this method updates the error string in the UI and sets the correct warning icon. """ self.errorString = errorString self.errorMsgTextEdit.setPlainText(self.errorString) if self.warningAction: # todo: figure out how to use the tooltip to show desc # self.warningAction.setToolTip(desc) self.warningAction.setIcon(self.iconWarning) if not desc: desc = "There are new warnings. Open the Warnings Window to see them." logging.info(desc) @Slot(str, str) def appendWarning(self, msg, desc): """ Public slot to append a warning to the list of warnings. Usually, this is called by the WarningsService. """ errorString = "%s\n%s" % (self.errorString,msg) self.updateWarnings(errorString, desc) @Slot(str, str) def setWarning(self, msg, desc): """ Public slot to clear all warnings and send this one as the only one. Usually, this is called by the WarningsService. """ errorString = msg self.updateWarnings(errorString, desc) def _connectToWarningAction(self): if self.warningAction: self.warningAction.triggered.connect(self._showDialog) def _showDialog(self): self.show() scrollBar = self.errorMsgTextEdit.verticalScrollBar() scrollBar.setValue(scrollBar.maximum()) if self.warningAction: # set no warning icon self.warningAction.setIcon(self.iconNoWarning) def _connectToWarningService(self): if self.warningService: self.warningService.appendWarningSignal.connect(self.appendWarning) self.warningService.setWarningSignal.connect(self.setWarning)
class WarningsDialog(QDialog, Ui_WarningsDialog): """ This is the Controller (more in the line of a code-behind file) for the small Warnings Dialog. The UI is handled separately by QT Designer 4 with the *.ui file. @since: 2011-05-20 """ __author__ = "Moritz Wade" __contact__ = "*****@*****.**" __copyright__ = "Zuse Institute Berlin 2011" def __init__(self, parent=None, warningAction=None, warningService=None): """ Constructor @param parent: Qt widget parent of this dialog window @type parent: QWidget @param warningAction: The action to connect to. @type warningAction: QAction """ super(WarningsDialog, self).__init__(parent) self.setupUi(self) self.setWarningAction(warningAction) self.setWarningService(warningService) self.statusBarService = StatusBarService() self.errorString = "" self.errorMsgTextEdit.setPlainText(self.errorString) self.iconWarning = QIcon() self.iconWarning.addPixmap( QPixmap( ":/tango-status-32px/images/tango-icon-theme/32x32/status/weather-severe-alert.png" ), QIcon.Normal, QIcon.Off) self.iconNoWarning = QIcon() self.iconNoWarning.addPixmap( QPixmap( ":/tango-status-32px/images/tango-icon-theme/32x32/status/weather-clear.png" ), QIcon.Normal, QIcon.Off) def setWarningAction(self, warningAction): """ Sets the warning QAction (for setting icons and to connect to its triggered SIGNAL to show self). """ self.warningAction = warningAction self._connectToWarningAction() def setWarningService(self, warningService): """ Sets the WarningService (to whose SIGNALs to listen to). """ self.warningService = warningService self._connectToWarningService() def updateWarnings(self, errorString, desc): """ Having updated the errorString elsewhere, this method updates the error string in the UI and sets the correct warning icon. """ self.errorString = errorString self.errorMsgTextEdit.setPlainText(self.errorString) if self.warningAction: # todo: figure out how to use the tooltip to show desc # self.warningAction.setToolTip(desc) self.warningAction.setIcon(self.iconWarning) if not desc: desc = "There are new warnings. Open the Warnings Window to see them." logging.info(desc) @Slot(str, str) def appendWarning(self, msg, desc): """ Public slot to append a warning to the list of warnings. Usually, this is called by the WarningsService. """ errorString = "%s\n%s" % (self.errorString, msg) self.updateWarnings(errorString, desc) @Slot(str, str) def setWarning(self, msg, desc): """ Public slot to clear all warnings and send this one as the only one. Usually, this is called by the WarningsService. """ errorString = msg self.updateWarnings(errorString, desc) def _connectToWarningAction(self): if self.warningAction: self.warningAction.triggered.connect(self._showDialog) def _showDialog(self): self.show() scrollBar = self.errorMsgTextEdit.verticalScrollBar() scrollBar.setValue(scrollBar.maximum()) if self.warningAction: # set no warning icon self.warningAction.setIcon(self.iconNoWarning) def _connectToWarningService(self): if self.warningService: self.warningService.appendWarningSignal.connect(self.appendWarning) self.warningService.setWarningSignal.connect(self.setWarning)
def setup(self): """initializes the uio of the erp client""" self.progress.setFixedWidth(1000) self.progress.setCancelButton(None) # self.progress.setWindowModality(Qt.WindowModal) self.progress.setValue(1) self.mainwindow.setObjectName("MainWindow") self.mainwindow.resize(832, 668) self.mainwindow.setStyleSheet( "QToolBar{\n" "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,\n" "stop:0 rgba(0,0,0),stop:1 rgb(162, 162, 162, 162));\n" "border: 0px;\n" "}\n" "QToolBar > QWidget{\n" "color:white;\n" "}\n" "QToolBar > QWidget:hover {\n" "background:transparent;\n" " }\n" "QToolBar > QWidget:checked {\n" "background:transparent;\n" " }\n" "#MainWindow{\n" "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,\n" "stop:0 rgba(0,0,0),stop:1 rgb(162, 162, 162, 162));\n" "border: 0px;\n" "}\n" "") self.centralWidget = QWidget(self.mainwindow) self.centralWidget.setObjectName("centralWidget") self.gridLayout_2 = QGridLayout(self.centralWidget) self.gridLayout_2.setObjectName("gridLayout_2") self.stackedWidget = QStackedWidget(self.centralWidget) self.stackedWidget.setStyleSheet("") self.stackedWidget.setObjectName("stackedWidget") self.shortcut = NewShortcut() scroll = QScrollArea() scroll.setWidget(self.shortcut.shortcut_setting) self.stackedWidget.addWidget(self.shortcut.shortcut_setting) self.home_page = QWidget() self.home_page.setObjectName("home_page") self.gridLayout = QGridLayout(self.home_page) self.gridLayout.setObjectName("gridLayout") self.billing_frame_2 = QFrame(self.home_page) self.billing_frame_2.setStyleSheet( "background-image:url(:/images/billing_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#6CBED2;") self.billing_frame_2.setFrameShape(QFrame.StyledPanel) self.billing_frame_2.setFrameShadow(QFrame.Raised) self.billing_frame_2.setObjectName("billing_frame_2") self.verticalLayout_4 = QVBoxLayout(self.billing_frame_2) self.verticalLayout_4.setObjectName("verticalLayout_4") spacerItem = QSpacerItem(20, 217, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_4.addItem(spacerItem) self.label_10 = QLabel(self.billing_frame_2) self.label_10.setStyleSheet("background:transparent;") self.label_10.setObjectName("label_10") self.verticalLayout_4.addWidget(self.label_10) self.gridLayout.addWidget(self.billing_frame_2, 0, 1, 1, 1) self.employee_frame_3 = QFrame(self.home_page) self.employee_frame_3.setStyleSheet( "background-image:url(:/images/employee_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#0099CC;") self.employee_frame_3.setFrameShape(QFrame.StyledPanel) self.employee_frame_3.setFrameShadow(QFrame.Raised) self.employee_frame_3.setObjectName("employee_frame_3") self.verticalLayout_5 = QVBoxLayout(self.employee_frame_3) self.verticalLayout_5.setObjectName("verticalLayout_5") spacerItem1 = QSpacerItem(20, 217, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_5.addItem(spacerItem1) self.label_11 = QLabel(self.employee_frame_3) self.label_11.setStyleSheet("background:transparent;") self.label_11.setObjectName("label_11") self.verticalLayout_5.addWidget(self.label_11) self.gridLayout.addWidget(self.employee_frame_3, 0, 2, 1, 1) self.menu_frame_4 = QFrame(self.home_page) self.menu_frame_4.setStyleSheet( "background-image:url(:/images/menu_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#297ACC;") self.menu_frame_4.setFrameShape(QFrame.StyledPanel) self.menu_frame_4.setFrameShadow(QFrame.Raised) self.menu_frame_4.setObjectName("menu_frame_4") self.verticalLayout_3 = QVBoxLayout(self.menu_frame_4) self.verticalLayout_3.setObjectName("verticalLayout_3") spacerItem2 = QSpacerItem(20, 216, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_3.addItem(spacerItem2) self.label_12 = QLabel(self.menu_frame_4) self.label_12.setStyleSheet("background:transparent;") self.label_12.setObjectName("label_12") self.verticalLayout_3.addWidget(self.label_12) self.gridLayout.addWidget(self.menu_frame_4, 1, 0, 1, 1) self.report_frame_5 = QFrame(self.home_page) self.report_frame_5.setStyleSheet( "background-image:url(:/images/report_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#006BB2;") self.report_frame_5.setFrameShape(QFrame.StyledPanel) self.report_frame_5.setFrameShadow(QFrame.Raised) self.report_frame_5.setObjectName("report_frame_5") self.verticalLayout_6 = QVBoxLayout(self.report_frame_5) self.verticalLayout_6.setObjectName("verticalLayout_6") spacerItem3 = QSpacerItem(20, 216, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_6.addItem(spacerItem3) self.label_13 = QLabel(self.report_frame_5) self.label_13.setStyleSheet("background:transparent;") self.label_13.setObjectName("label_13") self.verticalLayout_6.addWidget(self.label_13) self.gridLayout.addWidget(self.report_frame_5, 1, 1, 1, 1) self.waste_frame_6 = QFrame(self.home_page) self.waste_frame_6.setStyleSheet( "background-image:url(:/images/waste_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#003D7A;") self.waste_frame_6.setFrameShape(QFrame.StyledPanel) self.waste_frame_6.setFrameShadow(QFrame.Raised) self.waste_frame_6.setObjectName("waste_frame_6") self.verticalLayout_7 = QVBoxLayout(self.waste_frame_6) self.verticalLayout_7.setObjectName("verticalLayout_7") spacerItem4 = QSpacerItem(20, 216, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_7.addItem(spacerItem4) self.label_14 = QLabel(self.waste_frame_6) self.label_14.setStyleSheet("background:transparent;") self.label_14.setObjectName("label_14") self.verticalLayout_7.addWidget(self.label_14) self.gridLayout.addWidget(self.waste_frame_6, 1, 2, 1, 1) self.inventory_frame_1 = QFrame(self.home_page) self.inventory_frame_1.setStyleSheet( "background-image:url(:/images/inventory_frame.png);\n" "background-repeat: no-repeat;\n" "background-position: center;\n" "background-color:#ADEBFF;") self.inventory_frame_1.setFrameShape(QFrame.StyledPanel) self.inventory_frame_1.setFrameShadow(QFrame.Raised) self.inventory_frame_1.setObjectName("inventory_frame_1") self.verticalLayout_2 = QVBoxLayout(self.inventory_frame_1) self.verticalLayout_2.setObjectName("verticalLayout_2") spacerItem5 = QSpacerItem(20, 217, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem5) self.label_9 = QLabel(self.inventory_frame_1) self.label_9.setStyleSheet("background:transparent;") self.label_9.setObjectName("label_9") self.verticalLayout_2.addWidget(self.label_9) self.gridLayout.addWidget(self.inventory_frame_1, 0, 0, 1, 1) self.stackedWidget.addWidget(self.home_page) self.detail_page = QWidget() self.detail_page.setObjectName("detail_page") self.horizontalLayout_2 = QHBoxLayout(self.detail_page) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.main_tabWidget = QTabWidget(self.detail_page) self.main_tabWidget.setAutoFillBackground(False) self.main_tabWidget.setStyleSheet("") self.main_tabWidget.setTabPosition(QTabWidget.West) self.main_tabWidget.setIconSize(QSize(60, 60)) self.main_tabWidget.setElideMode(Qt.ElideNone) self.main_tabWidget.setObjectName("main_tabWidget") ##initializes the tabs self.add_tabs() self.main_tabWidget.setFocusPolicy(Qt.StrongFocus) self.main_tabWidget.focusInEvent = self.change_focus self.main_tabWidget.currentChanged.connect(self.change_focus) self.stackedWidget.currentChanged.connect(self.change_focus) ###### self.horizontalLayout_2.addWidget(self.main_tabWidget) self.stackedWidget.addWidget(self.detail_page) if ('Admin', True) in self.access: self.stackedWidget.addWidget(Admin(self.mainwindow)) notification = NotificationTab() tab = notification.notificationTab_tab_4 tab.custom_class_object = notification # class_object is used to access the api through the self.stackedWidget.addWidget(tab) self.gridLayout_2.addWidget(self.stackedWidget, 0, 0, 1, 1) self.mainwindow.setCentralWidget(self.centralWidget) self.menuBar = QMenuBar(self.mainwindow) self.menuBar.setGeometry(QRect(0, 0, 832, 29)) self.menuBar.setObjectName("menuBar") self.mainwindow.setMenuBar(self.menuBar) self.mainToolBar = QToolBar(self.mainwindow) self.mainToolBar.setLayoutDirection(Qt.RightToLeft) self.mainToolBar.setStyleSheet("") self.mainToolBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.mainToolBar.setObjectName("mainToolBar") self.mainwindow.addToolBar(Qt.TopToolBarArea, self.mainToolBar) self.statusBar = QStatusBar(self.mainwindow) self.statusBar.setObjectName("statusBar") self.mainwindow.setStatusBar(self.statusBar) self.toolBar = QToolBar(self.mainwindow) self.toolBar.setLayoutDirection(Qt.RightToLeft) self.toolBar.setStyleSheet("") self.toolBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.toolBar.setObjectName("toolBar") self.mainwindow.addToolBar(Qt.TopToolBarArea, self.toolBar) self.actionNotification = QAction(self.mainwindow) self.actionNotification.setCheckable(True) self.actionNotification.setChecked(False) self.actionNotification.setEnabled(True) icon6 = QIcon() icon6.addPixmap(QPixmap(":/images/notification.png"), QIcon.Normal, QIcon.Off) self.actionNotification.setIcon(icon6) self.actionNotification.setAutoRepeat(True) self.actionNotification.setVisible(True) self.actionNotification.setIconVisibleInMenu(False) self.actionNotification.setObjectName("actionNotification") self.actionNotification self.actionAdmin = QAction(self.mainwindow) # self.actionAdmin.setCheckable(True) icon7 = QIcon() icon7.addPixmap(QPixmap(":/images/admin.png"), QIcon.Normal, QIcon.Off) self.actionAdmin.setIcon(icon7) self.actionAdmin.setObjectName("actionAdmin") self.actionRefresh = QAction(self.mainwindow) icon8 = QIcon() icon8.addPixmap(QPixmap(":/images/refresh.png"), QIcon.Normal, QIcon.Off) self.actionRefresh.setIcon(icon8) self.actionRefresh.setObjectName("actionRefresh") self.actionHome = QAction(self.mainwindow) # self.actionHome.setCheckable(True) icon9 = QIcon() icon9.addPixmap(QPixmap(":/images/home.png"), QIcon.Normal, QIcon.Off) self.actionHome.setIcon(icon9) self.actionHome.setObjectName("actionHome") self.actionSettings = QAction(self.mainwindow) icon10 = QIcon() icon10.addPixmap(QPixmap(":/images/settings.png"), QIcon.Normal, QIcon.Off) self.actionSettings.setIcon(icon10) self.actionSettings.setObjectName("actionRefresh") self.toolBar.addAction(self.actionNotification) self.toolBar.addSeparator() self.toolBar.addAction(self.actionAdmin) if ('Admin', True) in self.access: self.toolBar.addSeparator() else: self.actionAdmin.setVisible(False) self.toolBar.addAction(self.actionHome) self.toolBar.addSeparator() self.toolBar.addAction(self.actionRefresh) self.toolBar.addSeparator() self.toolBar.addAction(self.actionSettings) ##retranslates self.mainwindow.setWindowTitle( QApplication.translate("MainWindow", settings.company, None, QApplication.UnicodeUTF8)) self.label_10.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">BILLING</p></body></html>", None, QApplication.UnicodeUTF8)) self.label_11.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">EMPLOYEE</p></body></html>", None, QApplication.UnicodeUTF8)) self.label_12.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">MENU</p></body></html>", None, QApplication.UnicodeUTF8)) self.label_13.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">REPORT</p></body></html>", None, QApplication.UnicodeUTF8)) self.label_14.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">WASTE</p></body></html>", None, QApplication.UnicodeUTF8)) self.label_9.setText( QApplication.translate( "MainWindow", "<html><head/><body><p align=\"center\">INVENTORY</p></body></html>", None, QApplication.UnicodeUTF8)) self.inventory_frame_1.setToolTip( QApplication.translate("MainWindow", "Go to the Inventory Tab", None, QApplication.UnicodeUTF8)) self.billing_frame_2.setToolTip( QApplication.translate("MainWindow", "Go to the Billing Tab", None, QApplication.UnicodeUTF8)) self.employee_frame_3.setToolTip( QApplication.translate("MainWindow", "Go to the Employee Tab", None, QApplication.UnicodeUTF8)) self.menu_frame_4.setToolTip( QApplication.translate("MainWindow", "Go to the Menu Tab", None, QApplication.UnicodeUTF8)) self.report_frame_5.setToolTip( QApplication.translate("MainWindow", "Go to the Report Tab", None, QApplication.UnicodeUTF8)) self.waste_frame_6.setToolTip( QApplication.translate("MainWindow", "Go to the Waste Tab", None, QApplication.UnicodeUTF8)) self.toolBar.setWindowTitle( QApplication.translate("MainWindow", "toolBar", None, QApplication.UnicodeUTF8)) self.actionNotification.setText("&&Notification") # QApplication.translate("MainWindow", "&Notification", None, QApplication.UnicodeUTF8)) self.actionNotification.setToolTip( QApplication.translate("MainWindow", "Click to see new notifications", None, QApplication.UnicodeUTF8)) # self.actionNotification.setShortcut( # QApplication.translate("MainWindow", "Ctrl+Shift+N", None, QApplication.UnicodeUTF8)) self.actionAdmin.setText('&&Admin') # QApplication.translate("MainWindow", "Admin", None, QApplication.UnicodeUTF8)) self.actionAdmin.setToolTip( QApplication.translate("MainWindow", "Click to go to admin interface", None, QApplication.UnicodeUTF8)) # self.actionAdmin.setShortcut( # QApplication.translate("MainWindow", "Ctrl+Shift+A", None, QApplication.UnicodeUTF8)) self.actionRefresh.setText("&&Refresh") # QApplication.translate("MainWindow", "Refresh", None, QApplication.UnicodeUTF8)) self.actionRefresh.setToolTip( QApplication.translate("MainWindow", "refreshes the data from the server", None, QApplication.UnicodeUTF8)) # self.actionRefresh.setShortcut( # QApplication.translate("MainWindow", "Ctrl+Shift+R", None, QApplication.UnicodeUTF8)) self.actionHome.setText('&&Home') # QApplication.translate("MainWindow", "Home", None, QApplication.UnicodeUTF8)) self.actionHome.setToolTip( QApplication.translate("MainWindow", "Go back to the home screen", None, QApplication.UnicodeUTF8)) self.actionSettings.setText('&&Settings') # QApplication.translate("MainWindow", "Settings", None, QApplication.UnicodeUTF8)) self.actionSettings.setToolTip( QApplication.translate("MainWindow", "Go to the settings panel", None, QApplication.UnicodeUTF8)) # self.actionHome.setShortcut( # QApplication.translate("MainWindow", "Ctrl+Shift+H", None, QApplication.UnicodeUTF8)) self.stackedWidget.setCurrentIndex(1) self.main_tabWidget.setCurrentIndex(0) self.ob = self.main_tabWidget.tabBar() # self.add_tool_tip(self.ob) todo avoided due to segmentation fault error, left for future fixes self.tb = EventHandlerForTabBar() self.ob.installEventFilter(self.tb) QMetaObject.connectSlotsByName(self.mainwindow)
def __init__(self, start, hive_connection): super(Kitchen, self).__init__() self.setupUi(self) # Hive database self.database_connector = hive_connection self.recipe_reader = RecipeReader(self.database_connector) self.recipe_reader.load_recipes() # Recipe List self.recipes = self.recipe_reader.get_recipes() item = QListWidgetItem('< None >') self.recipe_list.addItem(item) for recipe in self.recipes: item = QListWidgetItem(recipe) self.recipe_list.addItem(item) self.recipe_list.itemClicked.connect(self.set_ingredients) self.recipe_list.currentItemChanged.connect(self.clear_table) self.regex = re.compile('([0-9,.]+)([a-zA-Z]*)') self.start = start self.cancel_bt.clicked.connect(self.show_start) # name widget chooser self.mid = MealInputDialog('Title', 'Message', 'Name', 'Links', ('Cancel', 'Accept'), lambda x, y: print(x)) # language tag self.lang_tag = 'de' # language dicts self.stuff_hor_header_labels = { 'en': ['Amount', 'Unit', 'Name'], 'de': ['Menge', 'Einheit', 'Name'] } self.weekly_hor_header_labels = {'en': 'Meal', 'de': 'Gericht'} self.weekly_vert_header_labels = { 'en': [ 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday' ], 'de': [ 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag' ] } self.set_language_label_text = { 'en': 'set Language:', 'de': 'Sprache wechseln:' } self.rad_buttons_text = { 'en': [ 'Calories Summation', 'Show stock (empty things)', 'Show stock (existing things)', 'Bought goods' ], 'de': [ 'Kalorienrechner', 'Leere Nahrungsmittel', 'Vorhandene Nahrungsmittel', 'Einkaufsinventur' ] } self.tab_text = { 'en': ['Recipes', 'Weekly Rota', 'Playlist'], 'de': ['Rezepte', 'Wochenplan', 'Playlist'] } self.buttons_text = { 'en': [('Calculate calories', 'Push to Database'), 'Cancel'], 'de': [('Kalorien berechnen', 'Übernehmen'), 'Zurück'] } self.button_bought_calc_val = True # Tables self.stuff_table.setColumnCount(3) if not pyside_import: self.stuff_table.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) else: self.stuff_table.horizontalHeader().setResizeMode( QHeaderView.Stretch) self.weekly_tw.setColumnCount(1) self.weekly_tw.setRowCount(7) self.toggle_language() if not pyside_import: self.weekly_tw.verticalHeader().setSectionResizeMode( QHeaderView.Stretch) self.weekly_tw.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) else: self.weekly_tw.verticalHeader().setResizeMode(QHeaderView.Stretch) self.weekly_tw.horizontalHeader().setResizeMode( QHeaderView.Stretch) # Time self.time_lcd.setDigitCount(8) timer = QTimer(self) timer.timeout.connect(self.show_time) timer.start(1000) self.show_time() # Timer self.timer_lcd.setDigitCount(8) self.timer_dial.setMaximum(3600) if pyside_import: self.timer_dial.dialMoved.connect(self.set_timer) else: self.timer_dial.valueChanged.connect(self.set_timer) self.timer_timer = QTimer(self) self.timer_timer.timeout.connect(self.count_downwards) self.timer_bt.clicked.connect(self.timer_start) self.timer_time = 0 self.timer_running = False bl_pixmap = QPixmap('icons/aperture.png') red_pixmap = QPixmap('icons/aperture_red.png') self.icon_bl = QIcon() self.icon_bl.addPixmap(bl_pixmap) self.icon_red = QIcon() self.icon_red.addPixmap(red_pixmap) # Music buttons # prev prev_icon = QIcon() prev_pixmap = QPixmap('icons/prev.png') prev_icon.addPixmap(prev_pixmap) self.prev_bt.setIcon(prev_icon) # next next_icon = QIcon() next_pixmap = QPixmap('icons/next.png') next_icon.addPixmap(next_pixmap) self.next_bt.setIcon(next_icon) # play self.play_icon = QIcon() play_pixmap = QPixmap('icons/play.png') self.play_icon.addPixmap(play_pixmap) self.pause_icon = QIcon() pause_pixmap = QPixmap('icons/pause.png') self.pause_icon.addPixmap(pause_pixmap) self.play_pause_bt.setIcon(self.play_icon) # stop stop_icon = QIcon() stop_pixmap = QPixmap('icons/stop.png') stop_icon.addPixmap(stop_pixmap) self.stop_bt.setIcon(stop_icon) # search search_icon = QIcon() search_pixmap = QPixmap('icons/search2.png') search_icon.addPixmap(search_pixmap) self.go_bt.setIcon(search_icon) # table self.weekly_meals = {} self.stuff_table.cellClicked.connect(self.item_clicked) self.weekly_tw.cellClicked.connect(self.weekly_cell_clicked) # button calc self.calculate_bt.clicked.connect(self.calculate_cal) self.lcd_palette = self.calorie_lcd.palette() self.lcd_palette.setColor(self.lcd_palette.WindowText, QColor(102, 255, 102)) self.calorie_lcd.setPalette(self.lcd_palette) # radio buttons self.show_emp_rad.clicked.connect( lambda: self.radio_button_clicked(True, True)) self.show_rad.clicked.connect( lambda: self.radio_button_clicked(True, False)) self.cal_rad.clicked.connect( lambda: self.radio_button_clicked(True, None)) self.bought_rb.clicked.connect( lambda: self.radio_button_clicked(False, None)) # video stand_by_image = cv2.imread('src/default.png') self.update_frame(stand_by_image) #self.queue = queue.Queue() #self.capture_thread = threading.Thread(target=self.grab, args=(0, self.queue, stand_by_image)) #self.timer = QTimer(self) #self.timer.timeout.connect(self.update_frame) #self.timer.start(1) #global running #running = True #self.capture_thread.start() # language button self.language_bt.clicked.connect(self.toggle_language)
def notifyOntologyAdded(self, ontology): """ Notify that an ontology was added to the index. Parameter : - ontology : The added ontology. """ if ontology is None: return self.addRecentOntology(ontology) i = len(self.menuOntology.actions()) - 3 ontologyMenu = None for x in range(i, len(self.menuOntology.actions())): a = self.menuOntology.actions()[x] if a.text() == ontology.name: # Don't need to add menu. ontologyMenu = a.menu() break if ontologyMenu is None: ontologyMenu = QMenu(self) ontologyMenu.setTitle(ontology.name) ontologyMenu.clear() # Update action icon = QIcon() icon.addPixmap(QPixmap(":/actions/gfx/actions/update-product.png"), QIcon.Normal, QIcon.Off) actionUpdate = ontologyMenu.addAction("Update") actionUpdate.setData(ontology) actionUpdate.setIcon(icon) actionUpdate.setIconVisibleInMenu(True) actionUpdate.triggered.connect(partial(self._updateOntology_, ontology)) icon = QIcon() icon.addPixmap(QPixmap(":/actions/gfx/actions/document-revert.png"), QIcon.Normal, QIcon.Off) actionRevert = ontologyMenu.addAction("Revert") actionRevert.setData(ontology) actionRevert.setIcon(icon) actionRevert.setIconVisibleInMenu(True) actionRevert.triggered.connect( partial(self._revertOntology_, ontology, ontologyMenu)) icon = QIcon() icon.addPixmap( QPixmap(":/actions/gfx/actions/document-properties.png"), QIcon.Normal, QIcon.Off) actionProperties = ontologyMenu.addAction("Properties") actionProperties.setData(ontology) actionProperties.setIconVisibleInMenu(True) actionProperties.setIcon(icon) actionProperties.triggered.connect( partial(self._showOntologyProperties_, ontology)) ontologyMenu.addSeparator() # Close action icon = QIcon() icon.addPixmap(QPixmap(":/actions/gfx/actions/document-close.png"), QIcon.Normal, QIcon.Off) actionClose = ontologyMenu.addAction("Close") actionClose.setIcon(icon) actionClose.setIconVisibleInMenu(True) actionClose.setData(ontology) actionClose.triggered.connect( partial(self._closeOntology_, ontology, ontologyMenu)) ontologyMenu.addSeparator() # Add ontology menu to menu bar self.menuOntology.addMenu(ontologyMenu)