From b8e4c124309e0c002b7ac1ec73092ec0fe918066 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 23 Feb 2016 15:07:15 +0300 Subject: [PATCH] callbacks update, mainscreen update --- src/callbacks.py | 11 +++++++---- src/mainscreen.py | 47 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index dc35ef9..ae9c172 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -1,9 +1,12 @@ # TODO: add all callbacks (replace test callbacks and use wrappers) -def self_connection_status(a, b, c): - print 'WOW, it works!' - print 'Status: ', str(b) +def self_connection_status(st): + def wrapped(a, b, c): + print 'WOW, it works!' + print 'Status: ', str(b) + st.status = b + return wrapped def friend_status(a, b, c, d): @@ -22,4 +25,4 @@ def init_callbacks(tox, window): """ tox.callback_friend_status(friend_status, 0) tox.callback_friend_message(friend_message, 0) - tox.callback_self_connection_status(self_connection_status, 0) + tox.callback_self_connection_status(self_connection_status(window.connection_status), 0) diff --git a/src/mainscreen.py b/src/mainscreen.py index 5ec6bac..70a0d6e 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -2,6 +2,36 @@ import sys from PySide import QtGui, QtCore +from toxcore_enums_and_consts import * + + +class StatusCircle(QtGui.QWidget): + + def __init__(self, parent=None): + QtGui.QWidget.__init__(self, parent) + # setGeometry(x_pos, y_pos, width, height) + self.setGeometry(0, 0, 32, 32) + self.status = 0 + + def paintEvent(self, event): + paint = QtGui.QPainter() + paint.begin(self) + paint.setRenderHint(QtGui.QPainter.Antialiasing) + # make a white drawing background + paint.setBrush(QtCore.Qt.white) + paint.drawRect(event.rect()) + k = 16 + rad_x = rad_y = 10 + if not self.status: # offline + color = QtCore.Qt.red + else: + color = QtCore.Qt.green + + paint.setPen(color) + center = QtCore.QPoint(k, k) + paint.setBrush(color) + paint.drawEllipse(center, rad_x, rad_y) + paint.end() class MainWindow(QtGui.QMainWindow): @@ -69,6 +99,10 @@ class MainWindow(QtGui.QMainWindow): msgBox.setText("Toxygen is pythonic Tox client. Version: " + util.program_version) msgBox.exec_() + def paintEvent(self, event): + pass + #self.connection_status.paintEvent(event) + def setup_right_bottom(self, Form): Form.setObjectName("right_bottom") Form.resize(500, 150) @@ -132,12 +166,13 @@ class MainWindow(QtGui.QMainWindow): font.setBold(False) self.label_2.setFont(font) self.label_2.setObjectName("label_2") - self.graphicsView_2 = QtGui.QGraphicsView(Form) - self.graphicsView_2.setGeometry(QtCore.QRect(200, 34, 64, 64)) - self.graphicsView_2.setMinimumSize(QtCore.QSize(32, 32)) - self.graphicsView_2.setMaximumSize(QtCore.QSize(32, 32)) - self.graphicsView_2.setBaseSize(QtCore.QSize(32, 32)) - self.graphicsView_2.setObjectName("graphicsView_2") + self.connection_status = StatusCircle(self) + self.connection_status.setGeometry(QtCore.QRect(200, 34, 64, 64)) + self.connection_status.setMinimumSize(QtCore.QSize(32, 32)) + self.connection_status.setMaximumSize(QtCore.QSize(32, 32)) + self.connection_status.setBaseSize(QtCore.QSize(32, 32)) + self.connection_status.setObjectName("connection_status") + def setup_right_top(self, Form): Form.setObjectName("Form")