You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-3-console-gui/console/gui/statusfield.py

63 lines
2.3 KiB

#-*- coding: utf-8 -*-
# Copyright 2012 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from PySide import QtGui, QtCore
class StatusLabel(QtGui.QLabel):
def __init__(self, name, width):
QtGui.QLabel.__init__(self, name)
self.setWordWrap(True)
class StatusFieldWgt(QtGui.QWidget):
def __init__(self, parent, layout):
super(StatusFieldWgt, self).__init__()
self.setLayout(layout)
class StatusField (QtGui.QScrollArea):
# bottom in main frame
def __init__(self, parent, ClientObj):
QtGui.QScrollArea.__init__(self)
self.layout = QtGui.QVBoxLayout()
self.status_widget = StatusFieldWgt(self, self.layout)
self.setWidget(self.status_widget)
# for clear memory after closed this window
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
def addMessage(self, text):
self.layout.addWidget(StatusLabel(_(text), self.size().width()))
if self.layout.count() > 30:
self.layout.removeItem(self.layout.itemAt(0))
self.status_widget = StatusFieldWgt(self, self.layout)
self.setWidget(self.status_widget)
self.verticalScrollBar().setValue(self.verticalScrollBar().maximum())
# update size children widget
self.resizeEvent(0)
def resizeEvent(self, resize_var):
width = self.size().width()
if width > 30:
if self.verticalScrollBar().isVisible():
self.status_widget.setFixedWidth(width - \
self.verticalScrollBar().size().width() - 5)
else:
self.status_widget.setFixedWidth(width - 6)
# update size children widget
self.status_widget.updateGeometry()