def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setWindowTitle("Self Spy") self.spy = 0 self.setWindowFlag(Qt.WindowTitleHint) self.resize(1000, 900) self.setStyleSheet("background-color: #F0DFF7;") self.highGroundLayout = QHBoxLayout() self.clock = Clock() self.focusChart = PieChart() self.highGroundLayout.addWidget(self.clock) self.highGroundLayout.addWidget(self.focusChart) self.focusLayout = Focus(self.focusName, self.focusTime) self.activeLayout = Active(self.activeName, self.activeTime) self.middleLayout = QHBoxLayout() self.middleLayout.addLayout(self.focusLayout) self.middleLayout.addLayout(self.activeLayout) self.layout.addLayout(self.highGroundLayout) self.layout.addLayout(self.middleLayout) widget = QWidget() widget.setLayout(self.layout) self.setCentralWidget(widget)
class MainWindow(QMainWindow): focusName = ['-', '-', '-', '-', '-'] focusTime = ['00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00'] activeName = ['-', '-', '-', '-', '-'] activeTime = ['00:00:00', '00:00:00', '00:00:00', '00:00:00', '00:00:00'] layout = QVBoxLayout() fileToRead = 'temp.csv' running = True def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setWindowTitle("Self Spy") self.spy = 0 self.setWindowFlag(Qt.WindowTitleHint) self.resize(1000, 900) self.setStyleSheet("background-color: #F0DFF7;") self.highGroundLayout = QHBoxLayout() self.clock = Clock() self.focusChart = PieChart() self.highGroundLayout.addWidget(self.clock) self.highGroundLayout.addWidget(self.focusChart) self.focusLayout = Focus(self.focusName, self.focusTime) self.activeLayout = Active(self.activeName, self.activeTime) self.middleLayout = QHBoxLayout() self.middleLayout.addLayout(self.focusLayout) self.middleLayout.addLayout(self.activeLayout) self.layout.addLayout(self.highGroundLayout) self.layout.addLayout(self.middleLayout) widget = QWidget() widget.setLayout(self.layout) self.setCentralWidget(widget) def closeEvent(self, event): self.running = False def initSpy(self): self.spy = Spy(self) def updateWindow(self, focusName, focusTime, activeName, activeTime, focusPath): self.focusLayout.updateName(focusName) sleep(0.5) self.focusLayout.updateTime(focusTime) sleep(0.5) self.activeLayout.updateName(activeName) sleep(0.5) self.activeLayout.updateTime(activeTime) sleep(1.25) self.focusChart.chartUpdate(focusPath)
def __init__(self, parent=None, text=None, image=None, rect=sf.Rectangle()): Widget.__init__(self, parent, rect) Active.__init__(self) if text: self._text = text self._textSelect = text.getCopyWidget() self._textActive = self._textSelect self._currentText = self._text else: self._text = None self._textSelect = None self._textActive = None self._currentText = None if image: self._image = image self._imageSelect = image.getCopyWidget() self._imageActive = self._imageSelect self._currentImage = self._image else: self._image = None self._imageSelect = None self._imageActive = None self._currentImage = None self._useCharacterSize = None self._hasImage = False self._hasLabel = False if image: self._imageSelect.lighten() self._image.canFocus = self._imageSelect.canFocus = False self._image.isStaticToView =\ self._imageSelect.isStaticToView = False self._hasImage = True if text: self._textSelect.lighten() self._text.canFocus = self._textSelect.canFocus = False self._text.isStaticToView =\ self._textSelect.isStaticToView = False self._hasLabel = True if rect != sf.Rectangle(): self.rect = rect elif self._hasImage: self.rect = self._image.rect elif self._hasLabel: self.rect = self._text.rect self.drawWidget(True)
def __init__(self, parent=None, rect=sf.Rectangle(sf.Vector2(0,0), sf.Vector2(30,30))): Widget.__init__(self, parent, rect) Active.__init__(self) self._rectangle = sf.RectangleShape(rect.size) self._line = [sf.VertexArray(sf.PrimitiveType.LINES, 2),\ sf.VertexArray(sf.PrimitiveType.LINES, 2)] self.keepActivation = True self.outlineRectangleColor = sf.Color.WHITE self.outlineRectangleThickness = 2 self.crossColor = sf.Color.BLACK self.rect = rect
def __init__(self, parent=None, radius=10, position = sf.Vector2(0,0), \ bigCircleColor=sf.Color.WHITE, \ smallCircleColor=sf.Color.RED, smallCircleProportion = 0.5,\ origin = Position.Center): Widget.__init__(self, parent, \ sf.Rectangle(position, sf.Vector2(radius, radius)/0.5)) Active.__init__(self) self.keepActivation = True self._bigCircle = sf.CircleShape(radius) self._smallCircle = sf.CircleShape(smallCircleProportion * radius) self._bigCircle.fill_color = bigCircleColor self._smallCircle.fill_color = smallCircleColor self._proportion = smallCircleProportion self.size = sf.Vector2(radius, radius)/0.5 self.pos = position self.posOrigin = origin
def __init__(self, parent=None, rect=sf.Rectangle(),\ alignment = Position.Center, spacing=sf.Vector2(0, 0), \ autoDefineSize = True, select=False, active=False, \ alwaysUpdateSelection=True, alwaysUpdateActivation=True, \ permanentSelection=False, permanentActivation=False, \ changeRight = sf.Keyboard.RIGHT, changeLeft = sf.Keyboard.LEFT,\ changeTop = sf.Keyboard.UP, changeBottom = sf.Keyboard.DOWN): Layout.__init__(self, parent, rect, alignment, spacing, autoDefineSize) Active.__init__(self, select, active, alwaysUpdateSelection,\ alwaysUpdateActivation, permanentSelection, permanentActivation) self.canFocus=False self.changeLeft = changeLeft self.changeRight = changeRight self.changeTop = changeTop self.changeBottom = changeBottom self._howActiveKeyboard = [self.changeLeft, self.changeRight, self.changeTop, self.changeBottom] self._currentSelect = None
def main(): accuracies1 = [] mnist = Data(balance=False) mnist.load_data('mnist_train.csv', 'mnist_test.csv') print('') print('Data Size: ' + str(len(mnist.train_x))) model = Model(input_shape=784, num_classes=10, save_path='none', verbose=False) accuracies1.append(model.train(mnist.train_x, mnist.train_y, mnist.test_x, mnist.test_y)) mnist.reduce_data(percentage=0.99) model = Model(784, 10, 'none', verbose=False) model.set_loss_params(weights=mnist.get_weights()) active = Active(mnist, model, 10, 1.00) accuracies1 += active.run(100, 100, 600) print(accuracies1)
async def init_active(self, user): activeUser = Active(user, self.client) if not activeUser in self.client.Active: await activeUser.start() self.client.Active.append(activeUser) else: await self.client.Active[self.client.Active.index(activeUser) ].update()
def activeIt(self, force=False): if self._event: if self._style == Style.OneLine: self._event.enteredText = self._text.text.string else: self._event.enteredText = self._text._label.text.string if self.event.getOnePressedKeys[1]: self.event.textCursor -= 1 elif self.event.getOnePressedKeys[2]: self.event.textCursor -= 1 elif self.event.getOnePressedKeys[3]: pass #Chercher ce qu'il y a au dessus elif self.event.getOnePressedKeys[4]: pass #Chercher ce qu'il y a en dessous elif self.event.getOneMouseClicked: self.event.textCursor += self.getCharacterIndex(position) Active.activeIt(self, True)
def __init__(self, parent=None, rect = sf.Rectangle(sf.Vector2(), sf.Vector2(20, 5)), \ defaultText=None, defaultBackground=None, \ defaultForground=None, maxSizeX = sf.Vector2(-1,-1),\ spacing = 0, style=Style.MultiLines, percentage=0.9): Widget.__init__(self, parent, rect) Active.__init__(self) self._maxSize = maxSize self._minSize = rect.size if style == Style.MultiLines and not defaultText: defaultText = TextArray if not defaultBackground: self._background=Image(self, sf.Image(20, 20, sf.Color.MAGENTA)) else: self._background=defaultBackground if not defaultForground: self._forground=Button(self, None, Image(None, sf.Image(20, 20,\ sf.Color.MAGENTA))) else: self._forground = defaultForground self._text = defaultText self._spacing = spacing self._cursor = sf.VertexArray(sf.PrimitiveType.LINES, 2) self._style = style self._percentage = percentage self.keepActivation=True self._howActiveKeyboard=[None, sf.Keyboard.LEFT, sf.Keyboard.RIGHT, \ sf.Keyboard.TOP, sf.Keyboard.DOWN, sf.Keyboard.ESCAPE] self._howActiveMouse=[sf.Mouse.LEFT] self._background.rect = self.rect self._forground.origin = Position.CENTER self._forground.rect = sf.Rectangle(self.pos + self.size/2, \ percentage*self.size) self._background.canFocus = False
def activeIt(self, force=False): Active.activeIt(self) self.changeStatus()
def update(self, render=None): Active.update(self) Widget.update(self, render)
def disactiveIt(self, force=False): if self.isActive: self.event.resetText Active.disactiveIt(self, True)
def disactiveIt(self, force=True): Active.disactiveIt(self) self.changeStatus()
def selectIt(self): Active.selectIt(self) self.changeStatus()
def update(self, render=None): Active.update(self) currentHowActiveMouse = None if self.isActive and self.isSelect: done = False for widgetList in self._widget: for child in widgetList: if isinstance(child, Active) and child.isSelect and child is not self._currentSelect: self._currentSelect = child done = True break if done: break if not self._currentSelect: done = False for widgetList in self._widget: for child in widgetList: if isinstance(child, Active): self._currentSelect = child done = True break if done: break self._deselectOtherWidget() if self.event and self._currentSelect: currentHowActiveMouse = self._currentSelect.howActiveMouse if not self._currentSelect.howSelect(): self._currentSelect.howActiveMouse=[None] posCurrentSelect = self.getWidgetPosition(self._currentSelect) caseCurrentSelect = self.getWidgetCase(self._currentSelect) if not self.changeLeft in self._currentSelect.howActiveKeyboard and\ self.event.getOnePressedKeys(self.changeLeft): done = False for x in range(posCurrentSelect.x-1, -1, -1): for y in range(posCurrentSelect.y, len(self._widget[x])): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break for y in range(0, posCurrentSelect.y): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break if not done: for x in range(len(self._widget)-1, posCurrentSelect.x, -1): for y in range(posCurrentSelect.y, len(self._widget[x])): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break for y in range(0, posCurrentSelect.y): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break elif not self.changeRight in self._currentSelect.howActiveKeyboard and\ self.event.getOnePressedKeys(self.changeRight): done = False y = posCurrentSelect.y for x in range(posCurrentSelect.x + caseCurrentSelect.x, \ len(self._widget)): for y in range(posCurrentSelect.y, len(self._widget[x])): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break for y in range(0, posCurrentSelect.y): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break if not done: for x in range(0, posCurrentSelect.x): for y in range(posCurrentSelect.y, len(self._widget[x])): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break for y in range(0, posCurrentSelect.y): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break elif not self.changeTop in self._currentSelect.howActiveKeyboard and \ self.event.getOnePressedKeys(self.changeTop): done = False for y in range(posCurrentSelect.y-1, -1, -1): for x in range(posCurrentSelect.x, len(self._widget)): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break for x in range(0, posCurrentSelect.x): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break if not done: for y in range(len(self._widget[0])-1, posCurrentSelect.y, -1): for x in range(posCurrentSelect.x, len(self._widget)): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break for x in range(0, posCurrentSelect.x): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break elif not self.changeBottom in self._currentSelect.howActiveKeyboard and\ self.event.getOnePressedKeys(self.changeBottom): done = False x = posCurrentSelect.x for y in range(posCurrentSelect.y + caseCurrentSelect.y, \ len(self._widget[0])): for x in range(posCurrentSelect.x, len(self._widget)): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break for x in range(0, posCurrentSelect.x): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break if not done: for y in range(0, posCurrentSelect.y): for x in range(posCurrentSelect.x, len(self._widget)): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break for x in range(0, posCurrentSelect.x): child = self.__getitem__(sf.Vector2(x, y)) if isinstance(child, Active) and child is not self._currentSelect: done = True self._currentSelect = child break if done: break self._deselectOtherWidget() else: if self._currentSelect: self._currentSelect.permanentSelection=False self._currentSelect.deselectIt() Layout.update(self, render) if self._currentSelect: self._currentSelect.howActiveMouse = currentHowActiveMouse
def deselectIt(self): Active.deselectIt(self) self.changeStatus()