def testFamilyThree(self): a = AppModel() x, y, z = createFamily(3) b = a.familyThree(x, y, z) # Should be first non-business row (index values for seat list) self.assertEqual((14, 13, 12), b)
def testTourFullPlane(self): a = AppModel() for seat in range(0, 120): a.seatList[seat].isOpen = False b, c = createTourists() d = a.seatingAlgorithmTourist(b, c) self.assertEqual((-1, -1), d)
def testLeftFullFamThree(self): a = AppModel() b, c, d = createFamily(3) for seat in range(14, 120, 6): a.seatList[seat].isOpen = False e = a.familyThree(b, c, d) self.assertEqual((15, 16, 17), e)
def testTourist(self): a = AppModel() x, y = createTourists() b = a.seatingAlgorithmTourist(x, y) # Should be seated in first two non-business seats (returns 12, 13 as index into seat list; seat numbers are 13, 14) self.assertEqual((12, 13), b)
def testFamilyFour(self): a = AppModel() w, x, y, z = createFamily(4) b = a.familyFour(w, x, y, z) # Should be first non-business row (index values for seat list) self.assertEqual((14, 13, 12, 15), b)
def testFamilyFive(self): a = AppModel() v, w, x, y, z = createFamily(5) b = a.familyFive(v, w, x, y, z) # Should be first non-business row (index values for seat list) self.assertEqual((12, 13, 14, 15, 16), b)
def testFullPlane(self): a = AppModel() for seat in range(120): a.seatList[seat].isOpen = False b = createBusiness() c = a.seatBusiness(b) self.assertEqual(-1, c)
def testTouristLeftFull(self): a = AppModel() for seat in range(12, 120, 6): a.seatList[seat].isOpen = False a.seatList[seat + 1].isOpen = False b, c = createTourists() d = a.seatingAlgorithmTourist(b, c) self.assertEqual((16, 17), d)
def monitor(self): my_app = AppModel() url_content = my_app.read() my_app.get_response(url_content) #con = MyController() #con.monitor()
def testFullBusiness(self): a = AppModel() # Simulates business select being full for seat in range(12): a.seatList[seat].isOpen = False # Checks that passenger is given the first available seat outside of business select (index = 12, seat 13) b = createBusiness() c = a.seatBusiness(b) self.assertEqual(12, c)
def testNoWinMidSeats(self): a = AppModel() for seat in range(12, 120, 6): a.seatList[seat].isOpen = False a.seatList[seat + 1].isOpen = False for seat in range(16, 120, 6): a.seatList[seat].isOpen = False a.seatList[seat + 1].isOpen = False b, c = createTourists() d = a.seatingAlgorithmTourist(b, c) self.assertEqual((14, 15), d)
def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setupUi(self) self.appModel = AppModel() self.listViewModel = QStringListModel(self) self.info.setEditTriggers(QAbstractItemView.NoEditTriggers) self.initTable() self.initListSites() self.setConnections()
def __init__(self): Gtk.Window.__init__(self, title="Mistrz szachownicy GTK") self.engine = AppModel() self.gameFlag = False self.timeCounter = TIME_LIMIT self.set_default_size(800, 800) self.set_size_request(800, 800) self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) self.add(self.box) self._menuSetUp() self._boardSetUp() self._progressBarSetUp() self._controlSetUp() self._statsSetUp() self._makeItPretty()
def __init__(self): super(AppScreenQ, self).__init__() self.setWindowTitle("Mistrz szachownicy QT") self.timeCounter = TIME_LIMIT self.gameFlag = False self.bar = None self.engine = AppModel() self.mainLayout = QVBoxLayout() self.setMinimumSize(800, 800) self._menuSetUp() self._boardSetUp() self._progressSetUp() self._controlSetUp() self._statsSetUp() widget = QWidget() widget.setLayout(self.mainLayout) self.setCentralWidget(widget) self.show()
def __init__(self): import gtk.glade import Paths import Signals xml = gtk.glade.XML(Paths.glade, 'preferences') Signals.autoconnect(self, xml) self.__dialog = xml.get_widget('preferences') import gconf from GConfDir import GConfDir self.__client = gconf.client_get_default() self.__dir = GConfDir(self.__client, Keys.root, gconf.CLIENT_PRELOAD_NONE) from AppFinder import AppFinder from AppModel import AppModel from Application import Application finder = AppFinder(self.__client) model = AppModel() for path in finder: Application(self.__client, model, path) from MasterNotifier import MasterNotifier from WindowIcon import WindowIcon self.__master = xml.get_widget('master') self.__apps_group = xml.get_widget('apps-group') self.__notifier = MasterNotifier(self.__client, self.__master_refresh) self.__icon = WindowIcon(self.__client, self.__dialog) view = xml.get_widget('applications') import gtk selection = view.get_selection() selection.set_mode(gtk.SELECTION_NONE) renderer = gtk.CellRendererText() column = gtk.TreeViewColumn('Application', renderer) column.set_cell_data_func(renderer, self.__name_data_func) column.set_sort_column_id(model.COLUMN_NAME) column.set_reorderable(True) column.set_resizable(True) view.append_column(column) renderer = gtk.CellRendererToggle() renderer.connect('toggled', self.on_application_toggled, model) column = gtk.TreeViewColumn('Enabled', renderer) column.set_cell_data_func(renderer, self.__enabled_data_func) column.set_sort_column_id(model.COLUMN_ENABLED) column.set_reorderable(True) view.append_column(column) view.set_model(model)
def testReport(self): # Creates over 20 passengers to be randomly chosen using the AppModel function to be sure it returns list of 10 # Seats the passengers, since they are appended to the passenger list using the seating algorithm a = AppModel() b, c, d = createFamily(3) e = a.familyThree(b, c, d) f, g = createTourists() h = a.seatingAlgorithmTourist(f, g) i, j, k, l, m = createFamily(5) n = a.familyFive(i, j, k, l, m) o, p, q, r, s = createFamily(5) t = a.familyFive(o, p, q, r, s) u = createBusiness() v = a.seatBusiness(u) w, x = createTourists() y = a.seatingAlgorithmTourist(w, x) z, ab, ac = createFamily(3) ad = a.familyThree(z, ab, ac) # Call for generating report which should return list of 10 passenger objects and checking length gen = a.generateReport() self.assertEqual(len(gen), 10)
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setupUi(self) self.appModel = AppModel() self.listViewModel = QStringListModel(self) self.info.setEditTriggers(QAbstractItemView.NoEditTriggers) self.initTable() self.initListSites() self.setConnections() def initListSites(self): for site in Sites: self.listViewModel.insertRow(self.listViewModel.rowCount()) index = self.listViewModel.index(self.listViewModel.rowCount() - 1) self.listViewModel.setData(index, site.name) self.listSites.setModel(self.listViewModel) def initTable(self): self.info.setColumnCount(6) self.info.setHorizontalHeaderLabels([ 'Site', 'Author', 'Header', 'Url', 'Count comments', 'Count likes' ]) self.info.resizeColumnsToContents() def setConnections(self): self.actionExit.triggered.connect(QCoreApplication.instance().quit) self.actionAbout.triggered.connect(self.about) self.addNewArticleBtn.clicked.connect(self.parseSite) self.appModel.changeArticlesSignal.connect(self.onChangedArticled) def about(self): QMessageBox.about(self, "About", "Ametov Pavel\n8-T3O-302B-16") def error(self, message: str): box = QMessageBox() box.setWindowTitle("Error") box.setText(message) box.exec() def parseSite(self): try: index = self.listSites.currentIndex().row() numberArticle = self.numberArticle.text() if index == -1: raise Exception('Select site') try: numberArticle = int(numberArticle) except Exception as err: raise Exception("Incorrect value of article") site = Sites(index) self.appModel.parseSite(site, numberArticle) except Exception as err: self.error(err.args[0]) def onChangedArticled(self): self.info.clear() self.initTable() articles = self.appModel.articlesModels self.info.setRowCount(len(articles)) for index in range(len(articles)): article = articles[index] self.info.setItem(index, 0, QTableWidgetItem(article.site.name)) self.info.setItem(index, 1, QTableWidgetItem(article.author)) self.info.setItem(index, 2, QTableWidgetItem(article.header)) self.info.setItem(index, 3, QTableWidgetItem(article.url)) self.info.setItem(index, 4, QTableWidgetItem(str(article.countComments))) self.info.setItem(index, 5, QTableWidgetItem(str(article.countLikes))) self.info.resizeColumnsToContents()
class AppScreenQ(QMainWindow): def __init__(self): super(AppScreenQ, self).__init__() self.setWindowTitle("Mistrz szachownicy QT") self.timeCounter = TIME_LIMIT self.gameFlag = False self.bar = None self.engine = AppModel() self.mainLayout = QVBoxLayout() self.setMinimumSize(800, 800) self._menuSetUp() self._boardSetUp() self._progressSetUp() self._controlSetUp() self._statsSetUp() widget = QWidget() widget.setLayout(self.mainLayout) self.setCentralWidget(widget) self.show() def _menuSetUp(self): fileMenu = self.menuBar().addMenu("&Menu") newAct = QAction('Opis gry', self) newAct.triggered.connect(self._overviewDisplay) fileMenu.addAction(newAct) def _overviewDisplay(self): dlg = QDialog(self) dlg.setWindowTitle("Opis gry!") overviewLayout = QVBoxLayout() overview = QLabel(OVERVIEW_TEXT) overview.setWordWrap(True) overviewLayout.addWidget(overview) buttonBox = QDialogButtonBox(QDialogButtonBox.Ok) buttonBox.setCenterButtons(True) buttonBox.accepted.connect(dlg.accept) overviewLayout.addWidget(buttonBox) dlg.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) dlg.setLayout(overviewLayout) dlg.show() def _statsSetUp(self): style = """ border: 2px solid gray; border-radius: 10px; padding: 8px; selection-background-color: darkgray;""" self.stats = QHBoxLayout() self.scoreStatic = QLabel("Aktualny wynik:") self.scoreStatic.setMinimumHeight(40) self.scoreStatic.setMaximumHeight(40) self.scoreStatic.setStyleSheet(style) self.scoreStatic.setAlignment(QtCore.Qt.AlignCenter) self.score = QLabel("0") self.score.setMinimumHeight(40) self.score.setMaximumHeight(40) self.score.setStyleSheet(style) self.score.setAlignment(QtCore.Qt.AlignCenter) self.coordStatic = QLabel("Znajdź:") self.coordStatic.setMinimumHeight(40) self.coordStatic.setMaximumHeight(40) self.coordStatic.setStyleSheet(style) self.coordStatic.setAlignment(QtCore.Qt.AlignCenter) self.coord = QLabel("") self.coord.setMinimumHeight(40) self.coord.setMaximumHeight(40) self.coord.setStyleSheet(style) self.coord.setAlignment(QtCore.Qt.AlignCenter) self.stats.addWidget(self.scoreStatic) self.stats.addWidget(self.score) self.stats.addWidget(self.coordStatic) self.stats.addWidget(self.coord) self.mainLayout.addLayout(self.stats) def _controlSetUp(self): style = """ border-style: solid; border-color: gray; border-width: 2px; border-radius: 10px;""" self.menu = QHBoxLayout() self.startButton = QPushButton('Start', self) self.startButton.setStyleSheet(style) self.startButton.setMinimumHeight(40) self.startButton.clicked.connect(self._onButtonStart) self.stopButton = QPushButton('Stop', self) self.stopButton.setStyleSheet(style) self.stopButton.setMinimumHeight(40) self.stopButton.clicked.connect(self._onButtonStop) self.stopButton.setEnabled(False) self.menu.addWidget(self.startButton) self.menu.addWidget(self.stopButton) self.mainLayout.addLayout(self.menu) def _progressSetUp(self): self.progress = QProgressBar(self) self.progress.setTextVisible(False) self.progress.setStyleSheet("border: 2px solid grey;" "border-radius: 5px;" "text-align: center;" ) self.mainLayout.addWidget(self.progress) self.progress.setMaximum(TIME_LIMIT) def _boardSetUp(self): frameWidget = QWidget() frameLayout = QHBoxLayout() frameLayout.addStretch() frameWidget.setFixedSize(560, 560) frameLayout.addWidget(frameWidget) frameLayout.addStretch() self.mainLayout.addLayout(frameLayout) squareLayout = QGridLayout(frameWidget) squareLayout.setSpacing(0) self.squares = QButtonGroup() for i in range(8 * 8): newButton = QPushButton() policy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) newButton.setSizePolicy(policy) x = getX(i) y = getY(i) if (x + y) % 2 == 0: newButton.setStyleSheet("background-color: linen") else: newButton.setStyleSheet("background-color: sienna") self.squares.addButton(newButton, i) squareLayout.addWidget(newButton, x, y) self.squares.setExclusive(True) self.squares.buttonPressed.connect(self._onSquareClick) self.squares.buttonReleased.connect(self._onSquareRelease) self.mainLayout.addLayout(squareLayout) def _onButtonStart(self): if self.gameFlag: return self.startButton.setEnabled(False) self.stopButton.setEnabled(True) self.gameFlag = True self.timeCounter = TIME_LIMIT self.bar = QTimer() self.bar.timeout.connect(self._onClockChanged) self.bar.start(TIME_INTERVAL) self.engine.counterReset() self.engine.getNextPosition() self.coord.setText(self.engine.getCurrentNotation()) self.score.setText("0") def _onButtonStop(self): if not self.gameFlag: return self.bar.stop() self.stopButton.setEnabled(False) self.startButton.setEnabled(True) self.gameFlag = False def _onClockChanged(self): if (self.timeCounter == 0) or (self.gameFlag is False): self.startButton.setEnabled(True) self.stopButton.setEnabled(False) self.gameFlag = False self.timeCounter -= 1 self.progress.setValue(self.timeCounter) def _onSquareClick(self, btn): if not self.gameFlag: return i = self.squares.id(btn) x = getX(i) y = getY(i) if self.engine.getCurrentPosition() == (x, y): btn.setStyleSheet("background-color: green") self.engine.counterAdd() self.engine.getNextPosition() self.coord.setText(self.engine.getCurrentNotation()) self.score.setText(str(self.engine.getCounter())) return btn.setStyleSheet("background-color: red") def _onSquareRelease(self, btn): i = self.squares.id(btn) x = getX(i) y = getY(i) if (x + y) % 2 == 0: btn.setStyleSheet("background-color: linen") else: btn.setStyleSheet("background-color: sienna")
class AppScreenG(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Mistrz szachownicy GTK") self.engine = AppModel() self.gameFlag = False self.timeCounter = TIME_LIMIT self.set_default_size(800, 800) self.set_size_request(800, 800) self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) self.add(self.box) self._menuSetUp() self._boardSetUp() self._progressBarSetUp() self._controlSetUp() self._statsSetUp() self._makeItPretty() def _makeItPretty(self): css = b""" button { color: black; border-style: solid; border-color: gray; border-width: 1px; } button:disabled * { color:gray } #stats { color: black; border: 2px solid gray; padding: 0px; border-radius: 10px; margin: 4px; background: cornsilk; min-height: 40px; } #menu { color: black; margin: 4px; padding: 0px; border-style: solid; border-color: gray; border-width: 2px; border-radius: 10px; background: cornsilk; min-height: 40px; } progress { min-height: 20px; } progressbar, trough { min-height: 20px; margin: 2px; padding: 2px; } #whitesquare { background: linen; } #blacksquare { background: sienna; } #redsquare { background: red; } #greensquare { background: green; } #boxframe { padding: 10px; } """ self.box.set_name("boxframe") self.scoreStatic.set_name("stats") self.score.set_name("stats") self.coordStatic.set_name("stats") self.coord.set_name("stats") self.startButton.set_name("menu") self.stopButton.set_name("menu") css_provider = Gtk.CssProvider() css_provider.load_from_data(css) context = Gtk.StyleContext() screen = Gdk.Screen.get_default() context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) def _menuSetUp(self): menuBar = Gtk.MenuBar() menu = Gtk.Menu() overview = Gtk.MenuItem("Menu") overview.set_submenu(menu) menuText = Gtk.MenuItem("Opis gry") menuText.connect("activate", self._overviewDisplay) menu.append(menuText) menuBar.append(overview) menuBox = Gtk.VBox(False, 2) menuBox.pack_start(menuBar, False, False, 0) self.box.pack_start(menuBox, True, True, 0) def _overviewDisplay(self, widget): dialog = Gtk.MessageDialog( self, 0, Gtk.MessageType.OTHER, Gtk.ButtonsType.OK, "Opis gry!", ) dialog.set_modal(False) dialog.format_secondary_text( OVERVIEW_TEXT ) dialog.connect("response", self._onDialogResponse) dialog.show() def _onDialogResponse(self, widget, response_id): widget.destroy() def _progressBarSetUp(self): self.progressbar = Gtk.ProgressBar() self.box.pack_start(self.progressbar, False, False, 0) def _statsSetUp(self): self.stats = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=True) self.scoreStatic = Gtk.Label("Aktualny wynik:") self.score = Gtk.Label("0") self.coordStatic = Gtk.Label("Znajdź:") self.coord = Gtk.Label("") self.stats.add(self.scoreStatic) self.stats.add(self.score) self.stats.add(self.coordStatic) self.stats.add(self.coord) self.box.pack_start(self.stats, False, False, 0) def _controlSetUp(self): self.menu = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=True) self.startButton = Gtk.Button("Start") self.startButton.connect("clicked", self._onStartClick) self.menu.add(self.startButton) self.stopButton = Gtk.Button("Stop") self.stopButton.connect("clicked", self._onStopClick) self.stopButton.set_sensitive(False) self.menu.add(self.stopButton) self.box.pack_start(self.menu, False, False, 0) def _boardSetUp(self): self.gameBox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self.grid = Gtk.Grid() self.grid.set_size_request(560, 560) self.gameBox.pack_start(self.grid, False, False, 0) self.box.pack_start(self.gameBox, False, False, 0) for i in range(8 * 8): newButton = Gtk.Button() newButton.set_hexpand(True) newButton.set_vexpand(True) newButton.connect("pressed", self._onSquareClick) newButton.connect("released", self._onSquareRelease) x = getX(i) y = getY(i) if (x + y) % 2 == 0: newButton.set_name("whitesquare") else: newButton.set_name("blacksquare") self.grid.attach(newButton, x, y, 1, 1) def _onStartClick(self, btn): if self.gameFlag: return self.startButton.set_sensitive(False) self.stopButton.set_sensitive(True) self.gameFlag = True self.timeout_id = GLib.timeout_add(TIME_INTERVAL, self._onClockChanged) self.timeCounter = TIME_LIMIT self.engine.counterReset() self.engine.getNextPosition() self.coord.set_label(self.engine.getCurrentNotation()) self.score.set_label("0") def _onStopClick(self, btn): if not self.gameFlag: return self.stopButton.set_sensitive(False) self.gameFlag = False def _onClockChanged(self): if (self.timeCounter == 0) or (self.gameFlag is False): self.startButton.set_sensitive(True) self.stopButton.set_sensitive(False) self.gameFlag = False return False self.timeCounter -= 1 self.progressbar.set_fraction(self.timeCounter / TIME_LIMIT) return True def _onSquareClick(self, btn): if not self.gameFlag: return x = self.grid.child_get_property(btn, "top-attach") y = self.grid.child_get_property(btn, "left-attach") if self.engine.getCurrentPosition() == (x, y): btn.set_name("greensquare") self.engine.counterAdd() self.engine.getNextPosition() self.coord.set_label(self.engine.getCurrentNotation()) self.score.set_label(str(self.engine.getCounter())) return btn.set_name("redsquare") def _onSquareRelease(self, btn): x = self.grid.child_get_property(btn, "top-attach") y = self.grid.child_get_property(btn, "left-attach") if (x + y) % 2 == 0: btn.set_name("whitesquare") else: btn.set_name("blacksquare")
top.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1) self.notebook = ttk.Notebook(self) self.log_view = LogView(self.model, master=self) self.database_view = DatabaseView(self.model, master=self) self.notebook.add(self.log_view, text="Log") self.notebook.add(self.database_view, text="Database") self.notebook.add(tk.Frame(), text="Test Arduino Conncetivity") self.notebook.grid(column=0, row=0, sticky=tk.N + tk.S + tk.E + tk.W) def busy(self): self.master.config(cursor="wait") def not_busy(self): self.master.config(cursor="") def quit(self): self.model.close_files() super().quit() if __name__ == '__main__': app = MainAppView(AppModel()) app.master.title('CherryLock Manager') app.mainloop()
def testBusiness(self): a = AppModel() x = Passenger('a', 'b', 'Business', 0) b = a.seatBusiness(x) self.assertEqual(0, b)
def testBusinessPref(self): a = AppModel() b = createBusiness() b.preference = 110 c = a.seatBusiness(b) self.assertEqual(109, c)
def testTouristPref(self): a = AppModel() b, c = createTourists() b.preference, c.preference = 100, 103 d = a.seatingAlgorithmTourist(b, c) self.assertEqual((99, 102), d)