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/Box.py

347 lines
12 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/python
#-*- 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
from PySide.QtGui import QMessageBox
from DisplayMethod import DisplayMethodScroll, StartWidget
from mainframe import MainFrame
from mainmenu import MainMenu
from helpwidget import HelpWgt
from tools import ToolsWidget
from conf_connection import FrameConnection
from LeftMenu import LeftMenu
from MainFrameResult import MainFrameRes, analysis, get_entire_frame
from View_Process import ViewProc
from session_function import ViewSessionInfo
from CertificateClass import CertClass
from pid_information import client_list_pid
from more import icon_visible
from calculate.api.client.sid_func import client_del_sid
#from more import show_msg
import time
#class MainWgt(QtGui.QWidget):
class MainWgt(QtGui.QMainWindow):
size_x = 800
size_y = 800
valSignal = QtCore.Signal()
# mainwidth = 600
def __init__(self, ClientObj):
super(MainWgt, self).__init__()
self.ClientObj = ClientObj
self.mainwidth = 570
self.initUI()
self.valSignal.connect(self.setScrollBarVal)
def set_wid (self, i):
if i:
self.mainwidth = i
def initUI(self):
# Создание нижнего статус бара
self.statusbar = self.statusBar()
self.statusbar.showMessage('Ready')
# Создание верхнего главного меню
# MainMenu(self)
self.vlayout = QtGui.QVBoxLayout()
# self.vlayout.setContentsMargins(0,0,0,0)
# self.vlayout.setSpacing(0)
self.topmenu = MainMenu(self)
self.vlayout.addWidget(self.topmenu)
self.layout = QtGui.QHBoxLayout()
self.layout.setAlignment(QtCore.Qt.AlignLeft)
self.left_frame = LeftMenu(self)
self.left_frame.hide()
# Главный Фрэйм
# self.main_frame = FrameConnection(self, self.ClientObj)
self.main_frame = StartWidget(self, self.ClientObj)
self.layout.addWidget(self.left_frame)
self.layout.addWidget(self.main_frame)
self.vlayout.addLayout(self.layout)
self.Main = QtGui.QWidget(self)
self.Main.setLayout(self.vlayout)
self.setCentralWidget(self.Main)
self.move(200, 200)
self.resize(800,800)
self.setMinimumHeight(300)
self.setWindowTitle(self.ClientObj.Name)
self.setWindowIcon (QtGui.QIcon('/usr/share/pixmaps/cl-install-gui.png'))
def onChanged(self, text):
self.lbl.setText(text)
self.lbl.adjustSize()
def connecting(self):
self.ConnectWidget = FrameConnection(self, self.ClientObj)
self.ConnectWidget.setAttribute(QtCore.Qt.WA_ShowModal)
self.ConnectWidget.show()
def help(self):
self.HelpWidget = HelpWgt(self)
self.HelpWidget.setAttribute(QtCore.Qt.WA_ShowModal)
self.HelpWidget.show()
def tools(self):
self.ToolsWgt = ToolsWidget(self, self.ClientObj)
self.ToolsWgt.show()
def work_with_certificates(self):
self.certWidget = CertClass(self, self.ClientObj)
# self.certWidget.setAttribute(QtCore.Qt.WA_ShowModal)
self.certWidget.show()
def display_methods(self):
try:
self.main_frame.hide()
self.main_frame.destroy()
del (self.main_frame)
except:
pass
self.main_frame = DisplayMethodScroll(self, self.ClientObj)
self.layout.addWidget(self.main_frame)
self.left_frame.hide()
self.left_frame.old_title = None
self.setCentralWidget(self.Main)
icon_visible(self, 'Methods', False)
def view_processes(self):
try:
self.main_frame.hide()
self.main_frame.destroy()
del (self.main_frame)
except:
pass
self.main_frame = ViewProc(self, self.ClientObj)
self.layout.addWidget(self.main_frame)
self.left_frame.hide()
self.setCentralWidget(self.Main)
# set new Title
self.ClientObj.MainWidget.setWindowTitle (self.ClientObj.Name)
icon_visible(self, 'Methods', True)
def view_session_info(self):
self.SessionWgt = ViewSessionInfo(self, self.ClientObj.client)
self.SessionWgt.setAttribute(QtCore.Qt.WA_ShowModal)
self.SessionWgt.show()
def disconnect(self):
if not self.ClientObj.client:
return 1
list_pid = client_list_pid(self.ClientObj.client)
# if not list_pid:
# list_pid = []
msgBox = QMessageBox()
msgBox.setText(_("Close your session?"))
msgBox.setInformativeText(_('at closing session, ' \
'data %d processes will be deleted!') %len(list_pid))
msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No | \
QMessageBox.Cancel)
msgBox.setDefaultButton(QMessageBox.Cancel)
msgBox.setWindowIcon(QtGui.QIcon.fromTheme("network-disconnect"))
reply = msgBox.exec_()
if reply == QtGui.QMessageBox.Yes:
# Exit with closing session
self.ClientObj.signaling._Thread__stop()
while not self.ClientObj.signaling._Thread__stopped:
time.sleep(0.3)
client_del_sid(self.ClientObj.client)
self.ClientObj.client = None
icon_visible(self, 'Methods', False)
icon_visible(self, 'Disconnect', False)
icon_visible(self, 'Processes', False)
icon_visible(self, 'Session', False)
icon_visible(self, 'Connect', True)
icon_visible(self, 'Certificates', True)
self.process_dict = {}
elif reply == QtGui.QMessageBox.No:
self.ClientObj.signaling._Thread__stop()
while not self.ClientObj.signaling._Thread__stopped:
time.sleep(0.3)
self.ClientObj.client = None
icon_visible(self, 'Methods', False)
icon_visible(self, 'Disconnect', False)
icon_visible(self, 'Processes', False)
icon_visible(self, 'Session', False)
icon_visible(self, 'Connect', True)
icon_visible(self, 'Certificates', True)
self.process_dict = {}
else:
return 0
try:
self.main_frame.hide()
self.main_frame.destroy()
del (self.main_frame)
except:
pass
self.main_frame = StartWidget(self, self.ClientObj)
self.layout.addWidget(self.main_frame)
self.left_frame.hide()
self.setCentralWidget(self.Main)
# set new Title
self.setWindowTitle (self.ClientObj.Name)
def main_frame_view(self, view, method_name):
try:
self.main_frame.hide()
self.main_frame.destroy()
del (self.main_frame)
except:
pass
self.main_frame = MainFrame(self, self.ClientObj, view, method_name)
self.layout.addWidget(self.main_frame)
self.setCentralWidget(self.Main)
def main_frame_res(self, method_name, meth_result):
try:
self.main_frame.hide()
self.main_frame.destroy()
del (self.main_frame)
except:
pass
self.main_frame = MainFrameRes(self, self.ClientObj, \
method_name, meth_result)
self.layout.addWidget(self.main_frame)
self.left_frame.hide()
self.setCentralWidget(self.Main)
analysis(self, meth_result)
def main_view_process(self, method_name, meth_result, pid):
try:
self.main_frame.hide()
self.main_frame.destroy()
del (self.main_frame)
except:
pass
self.ClientObj.process_dict [pid]['layout'] = QtGui.QVBoxLayout()
self.main_frame = MainFrameRes(self, self.ClientObj, \
method_name, meth_result)
self.layout.addWidget(self.main_frame)
self.left_frame.hide()
self.setCentralWidget(self.Main)
get_entire_frame(self, pid)
# self.main_frame.MainFrameWgt.resize(self.main_frame.size())
def result_create(self, meth_result):
# self.main_frame.MainFrameWgt.show()
try:
self.main_frame.hide()
del (self.main_frame)
except:
pass
self.main_frame = MainFrameRes(self, self.ClientObj, \
self.ClientObj.process_dict[meth_result.message]['name'], \
meth_result)
self.layout.addWidget(self.main_frame)
self.left_frame.hide()
self.setCentralWidget(self.Main)
def setScrollBarVal(self):
self.main_frame.verticalScrollBar().setValue(self.main_frame.verticalScrollBar().maximum())
def resizeEvent(self, resize_var):
self.set_wid (self.main_frame.size().width())
def closeEvent(self, event):
# reply = QtGui.QMessageBox.question(self, 'Message',
# "Close your session?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No,\
# QtGui.QMessageBox.Cancel)
if self.ClientObj.client:
list_pid = client_list_pid(self.ClientObj.client)
msgBox = QMessageBox()
msgBox.setText("Close your session?")
msgBox.setInformativeText('at closing session, '
'data %d processes will be deleted!' %len(list_pid))
msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No | \
QMessageBox.Cancel)
msgBox.setDefaultButton(QMessageBox.Cancel)
msgBox.setWindowIcon(QtGui.QIcon.fromTheme("application-exit"))
reply = msgBox.exec_()
if reply == QtGui.QMessageBox.Yes:
# Exit with closing session
self.ClientObj.signaling._Thread__stop()
time.sleep(0.3)
# num = client_list_pid(self.ClientObj.client)
# if num:
# show_msg ('at closing session, '
# 'data %d processes will be deleted!' %num)
client_del_sid(self.ClientObj.client)
'''Closing session...'''
event.accept()
QtGui.QApplication.exit()
elif reply == QtGui.QMessageBox.No:
self.ClientObj.signaling._Thread__stop()
time.sleep(0.3)
# Exit without closing session
event.accept()
QtGui.QApplication.exit()
else:
event.ignore()
else:
event.accept()