예제 #1
0
    def initUI(self):

        self.value_label = QtGui.QLabel()
        self.buy_label = QtGui.QLabel()
        self.sell_label = QtGui.QLabel()

        self.graph_widget = GraphWidget()
        self.notification_widget = NotifyWidget(self.name)
        self.notification_widget.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)

        # connect notifications settings and graph
        self.notification_widget.below_absolute_changed.connect(self.graph_widget.setAbsoluteBelow)
        self.notification_widget.above_absolute_changed.connect(self.graph_widget.setAbsoluteAbove)

        self.notification_widget.loadConfiguration()
        
        # layout of the widget
        value_buy_sell_layout = QtGui.QHBoxLayout()
        value_buy_sell_layout.addWidget(self.value_label)
        value_buy_sell_layout.addSpacing(10)
        value_buy_sell_layout.addWidget(self.buy_label)
        value_buy_sell_layout.addSpacing(10)
        value_buy_sell_layout.addWidget(self.sell_label)
        value_buy_sell_layout.addStretch(1)

        values_graph_layout = QtGui.QVBoxLayout()
        values_graph_layout.addLayout(value_buy_sell_layout)
        values_graph_layout.addWidget(self.graph_widget)

        layout = QtGui.QHBoxLayout()
        layout.addLayout(values_graph_layout)
        layout.addWidget(self.notification_widget)
        self.setLayout(layout)
예제 #2
0
class CoinWidget(QtGui.QWidget):
   
    data_updated = QtCore.pyqtSignal()

    def __init__(self, name, trade_data):
        super(CoinWidget, self).__init__()
        self.trade_data = trade_data
        self.name = name
        self.trade_data.start()
        self.trade_data.data_updated.connect(self.checkLimits)
        self.trade_data.data_updated.connect(self.dataUpdatedEmit)
        self.alarm = None
        self.initUI()
     
    def setAlarm(self, alarm):
        self.alarm = alarm  

    def initUI(self):

        self.value_label = QtGui.QLabel()
        self.buy_label = QtGui.QLabel()
        self.sell_label = QtGui.QLabel()

        self.graph_widget = GraphWidget()
        self.notification_widget = NotifyWidget(self.name)
        self.notification_widget.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)

        # connect notifications settings and graph
        self.notification_widget.below_absolute_changed.connect(self.graph_widget.setAbsoluteBelow)
        self.notification_widget.above_absolute_changed.connect(self.graph_widget.setAbsoluteAbove)

        self.notification_widget.loadConfiguration()
        
        # layout of the widget
        value_buy_sell_layout = QtGui.QHBoxLayout()
        value_buy_sell_layout.addWidget(self.value_label)
        value_buy_sell_layout.addSpacing(10)
        value_buy_sell_layout.addWidget(self.buy_label)
        value_buy_sell_layout.addSpacing(10)
        value_buy_sell_layout.addWidget(self.sell_label)
        value_buy_sell_layout.addStretch(1)

        values_graph_layout = QtGui.QVBoxLayout()
        values_graph_layout.addLayout(value_buy_sell_layout)
        values_graph_layout.addWidget(self.graph_widget)

        layout = QtGui.QHBoxLayout()
        layout.addLayout(values_graph_layout)
        layout.addWidget(self.notification_widget)
        self.setLayout(layout)

    def checkLimits(self):
        value = self.trade_data.getValue()
        if self.notification_widget.aboveAbsoluteEnabled():
            if value > self.notification_widget.getAboveAbsolute():
                self.alarm.startAlarm('%s: value is above %f' % (self.name, self.notification_widget.getAboveAbsolute()))
        if self.notification_widget.belowAbsoluteEnabled():
            if value < self.notification_widget.getBelowAbsolute():
                self.alarm.startAlarm('%s: value is bellow %f' % (self.name, self.notification_widget.getBelowAbsolute()))


    def dataUpdatedEmit(self):
        self.value_label.setText('Value: <b>%s</b>' % self.trade_data.getValue())
        self.buy_label.setText('Buy: <b>%s</b>' % self.trade_data.getBuy())
        self.sell_label.setText('Sell: <b>%s</b>' % self.trade_data.getSell())
        self.notification_widget.coinValue(self.trade_data.getValue())
        self.data_updated.emit()

    def getName(self):
        return self.name

    def saveConfiguration(self):
        self.notification_widget.saveConfiguration()

    def closeEvent(self, event):
        self.trade_data.stop()
        self.saveConfiguration()
        event.accept()