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.
280 lines
11 KiB
280 lines
11 KiB
#!/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 calculate.api.client.function import get_sid
|
|
from more import ButtonMenu, icon_visible, LabelWordWrap
|
|
|
|
class LeftMenu(QtGui.QScrollArea):
|
|
|
|
def __init__(self, parent):
|
|
super(LeftMenu, self).__init__(parent)
|
|
self.parent = parent
|
|
|
|
self.horizontalScrollBar().hide()
|
|
self.old_title = None
|
|
|
|
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
|
|
|
|
|
def create_menu(self, display_wgt, groups, sub_groups, ClientObj):
|
|
# create left subgroup menu
|
|
self.old_title = self.parent.ClientObj.MainWidget.windowTitle()
|
|
icon_visible(self.parent.ClientObj.MainWidget, 'Methods', True)
|
|
|
|
self.widget = QtGui.QWidget (self)
|
|
|
|
# self.cur_palette = display_wgt.parent.viewport().palette()
|
|
self.widget.setPalette(self.cur_palette)
|
|
|
|
self.lable_list = []
|
|
self.button_list = {}
|
|
self.layout = QtGui.QVBoxLayout(self.widget)
|
|
|
|
self.layout.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignHCenter)
|
|
|
|
|
|
self.group_name = LabelWordWrap(sub_groups[0].split('.')[0], self)
|
|
|
|
self.group_name.setStyleSheet( \
|
|
'QLabel'
|
|
'{'
|
|
'background-color: rgba(255, 255, 255, 180);'
|
|
'border: 2px outset gray;'
|
|
'border-radius: 6px;'
|
|
'}')
|
|
|
|
#inset, outset, solid, and ridge
|
|
|
|
self.group_name.setAlignment(QtCore.Qt.AlignHCenter)
|
|
self.layout.addWidget(self.group_name)
|
|
|
|
|
|
for num in range(len(sub_groups)):
|
|
if len(sub_groups[num].split('.')) > 1:
|
|
# try:
|
|
sub_group = sub_groups[num].split('.')[1]
|
|
# except (UnicodeDecodeError, UnicodeEncodeError):
|
|
# pass
|
|
attrubute_list = []
|
|
sub_group_list = []
|
|
if self.button_list.has_key(sub_group):
|
|
attrubute_list = self.button_list[sub_group][0]
|
|
sub_group_list = self.button_list[sub_group][1]
|
|
self.button_list[sub_group] = []
|
|
param_list = [groups[num*3], groups[num*3 +1], groups[num*3 +2]]
|
|
self.button_list[sub_group].append \
|
|
(attrubute_list + param_list)
|
|
sub_group_list.append(sub_groups[num].split('.',1)[1])
|
|
self.button_list[sub_group].append \
|
|
(sub_group_list)
|
|
|
|
Button = ButtonMenu(sub_group, sub_group, 'folder-documents', None)
|
|
Button.clicked.connect(display_wgt.groupActivated \
|
|
(self.button_list[sub_group][0],self.button_list[sub_group][1]))
|
|
self.button_list[sub_group].append(Button)
|
|
|
|
continue
|
|
|
|
# for method_name in range (0, len(groups), 3):
|
|
i = num * 3
|
|
Button = ButtonMenu(groups[i], groups[i + 1], groups[i + 2], self)
|
|
Button.clicked.connect(self.onActivated)
|
|
if not self.button_list.has_key(sub_groups[num]):
|
|
self.button_list[sub_groups[num]] = []
|
|
self.button_list[sub_groups[num]].append(Button)
|
|
|
|
for num in range(len(sub_groups)):
|
|
# add subgroup
|
|
if len(sub_groups[num].split('.')) > 1:
|
|
|
|
sub_group = sub_groups[num].split('.')[1]
|
|
|
|
self.layout.addWidget(self.button_list[sub_group] \
|
|
[len(self.button_list[sub_group]) - 1])
|
|
continue
|
|
|
|
# add methos
|
|
self.layout.addWidget(self.button_list[sub_groups[num]] \
|
|
[len(self.button_list[sub_groups[num]]) - 1])
|
|
|
|
|
|
self.setWidget(self.widget)
|
|
|
|
self.setWidgetResizable(True)
|
|
|
|
self.setFixedWidth(self.sizeHint().width() + \
|
|
self.verticalScrollBar().sizeHint().width())
|
|
|
|
|
|
def onActivated(self):
|
|
method_name = self.sender().objectName()
|
|
|
|
# set new Title
|
|
new_title = self.sender().text()
|
|
try:
|
|
new_title = new_title.decode('utf-8')
|
|
except (UnicodeDecodeError, UnicodeEncodeError):
|
|
pass
|
|
self.parent.ClientObj.MainWidget.setWindowTitle \
|
|
(self.old_title + ' > ' + new_title)
|
|
|
|
step = 0
|
|
self.parent.ClientObj.method_name = method_name
|
|
self.parent.ClientObj.sid = get_sid(self.parent.ClientObj.client.SID_FILE)
|
|
if self.parent.ClientObj.param_objects.has_key(method_name):
|
|
step = self.parent.ClientObj.param_objects[method_name]['step']
|
|
view = self.parent.ClientObj.client.service[0][str(method_name + '_view')] \
|
|
(int(self.parent.ClientObj.sid), step)
|
|
# print view
|
|
self.parent.ClientObj.MainWidget.main_frame_view(view, method_name)
|
|
|
|
def create_steps (self, method_name, steps):
|
|
temp = self.parent.ClientObj.MainWidget.windowTitle().split('>')
|
|
if not _(' Step ') in temp[len(temp)-1]:
|
|
top_name_lbl = temp[len(temp)-1].strip()
|
|
self.old_title = self.parent.ClientObj.MainWidget.windowTitle()
|
|
else:
|
|
top_name_lbl = temp[len(temp)-2].strip()
|
|
|
|
icon_visible(self.parent.ClientObj.MainWidget, 'Methods', True)
|
|
|
|
self.widget = QtGui.QWidget (self)
|
|
self.widget.setPalette(self.cur_palette)
|
|
|
|
self.widget.setStyleSheet("QWidget { background-color: %s }" \
|
|
%self.parent.ClientObj.method_background_color)
|
|
|
|
self.button_list = []
|
|
self.layout = QtGui.QVBoxLayout(self.widget)
|
|
self.layout.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignHCenter)
|
|
|
|
self.method_name_lbl = LabelWordWrap(top_name_lbl, self)
|
|
self.method_name_lbl.setAlignment(QtCore.Qt.AlignCenter)
|
|
|
|
self.method_name_lbl.setStyleSheet( \
|
|
'QLabel'
|
|
'{'
|
|
'background-color: rgba(255, 255, 255, 180);'
|
|
'border: 2px outset gray;'
|
|
'border-radius: 6px;'
|
|
'}')
|
|
|
|
self.layout.addWidget(self.method_name_lbl)
|
|
|
|
for num_step in range(len(steps)):
|
|
self.button_list.append(QtGui.QPushButton(steps[num_step], self))
|
|
self.button_list[num_step].setFlat(True)
|
|
# collect parameters object
|
|
self.button_list[num_step].clicked.connect(self.collect_object)
|
|
# call function (or check parameters)
|
|
self.button_list[num_step].clicked.connect(self.calling_method)
|
|
|
|
self.button_list[num_step].clicked.connect \
|
|
(self.check_step(method_name, num_step))
|
|
|
|
|
|
self.layout.addWidget(self.button_list[num_step])
|
|
|
|
# set bold button
|
|
self.button_list[0].setFont(QtGui.QFont('',-1,QtGui.QFont.Bold))
|
|
|
|
self.setWidget(self.widget)
|
|
|
|
self.setWidgetResizable(True)
|
|
|
|
self.setFixedWidth(self.sizeHint().width() + \
|
|
self.verticalScrollBar().sizeHint().width())
|
|
|
|
self.parent.ClientObj.MainWidget.setWindowTitle \
|
|
(self.old_title + _(' > Step ') + '0')
|
|
|
|
|
|
# create helper signals
|
|
collect = QtCore.Signal()
|
|
calling = QtCore.Signal()
|
|
|
|
def collect_object(self):
|
|
try:
|
|
self.collect.disconnect()
|
|
except RuntimeError, e:
|
|
print e
|
|
|
|
self.collect.connect(self.parent.ClientObj.MainWidget.main_frame.\
|
|
MainFrameWgt.collect_object(False))
|
|
self.collect.emit()
|
|
|
|
def calling_method(self):
|
|
try:
|
|
self.calling.disconnect()
|
|
except RuntimeError, e:
|
|
print e
|
|
self.calling.connect(self.parent.ClientObj.MainWidget.main_frame.\
|
|
MainFrameWgt.calling(True))
|
|
self.calling.emit()
|
|
|
|
def check_step(self, method_name, set_step = None):
|
|
def wrapper():
|
|
# print 'set_step = ', set_step
|
|
step = set_step if set_step else 0
|
|
|
|
# print 'dddd', step
|
|
|
|
self.parent.ClientObj.method_name = method_name
|
|
self.parent.ClientObj.sid = get_sid(self.parent.ClientObj.client.SID_FILE)
|
|
# if self.parent.ClientObj.param_objects.has_key(method_name) and \
|
|
# (not set_step):
|
|
# step = self.parent.ClientObj.param_objects[method_name]['step']
|
|
# print 'step = ', step
|
|
view = self.parent.ClientObj.client.service[0][str(method_name + '_view')] \
|
|
(int(self.parent.ClientObj.sid), step)
|
|
# print view
|
|
# set new Title
|
|
self.parent.ClientObj.MainWidget.setWindowTitle \
|
|
(self.old_title + _(' > Step ') + str(step))
|
|
|
|
# set bold for current step
|
|
for i in range(len(self.button_list)):
|
|
if i == step:
|
|
self.button_list[i].setFont \
|
|
(QtGui.QFont('',-1,QtGui.QFont.Bold))
|
|
else:
|
|
self.button_list[i].setFont \
|
|
(QtGui.QFont('',-1,QtGui.QFont.Normal))
|
|
|
|
self.parent.ClientObj.param_objects[method_name]['step'] = step
|
|
|
|
self.parent.ClientObj.MainWidget.main_frame_view(view, method_name)
|
|
return wrapper
|
|
|
|
def changed_step(self, step):
|
|
|
|
temp = self.parent.ClientObj.MainWidget.windowTitle().split('>')
|
|
if not _(' Step ') in temp[len(temp)-1]:
|
|
self.old_title = self.parent.ClientObj.MainWidget.windowTitle()
|
|
|
|
self.parent.ClientObj.MainWidget.setWindowTitle \
|
|
(self.old_title + _(' > Step ') + str(step))
|
|
|
|
# set bold for current step
|
|
for i in range(len(self.button_list)):
|
|
if i == step:
|
|
self.button_list[i].setFont \
|
|
(QtGui.QFont('',-1,QtGui.QFont.Bold))
|
|
else:
|
|
self.button_list[i].setFont \
|
|
(QtGui.QFont('',-1,QtGui.QFont.Normal)) |