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

138 lines
4.9 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 calculate.lib.cl_datavars import ClDataVars
from calculate.api.cl_api import DataVarsApi
from calculate.console.cl_gui import DataVarsGui
from Box import MainWgt
from PySide import QtGui
import os
import ConfigParser
class ApiClient (QtGui.QWidget):
def __init__(self, app):
super(ApiClient, self).__init__()
self.app = app
# Initialization GUI variables
VarsGui = DataVarsGui()
VarsGui.importGui()
VarsGui.flIniFile()
try:
self.Version = VarsGui.Get('cl_gui_ver')
except:
self.Version = ''
try:
self.Name = VarsGui.Get('cl_gui_name')
except:
self.Name = 'calculate-client-gui'
# Initialization of system variables
Vars = DataVarsApi()
Vars.importApi()
Vars.flIniFile()
clVars = ClDataVars()
clVars.flIniFile()
# Initialization other variables
self.homePath = clVars.Get('ur_home_path')
path_to_cert = '~/.calculate/client_cert/'
self.path_to_cert = path_to_cert.replace("~",self.homePath)
# read from users configuratuon file
user_config = '~/.calculate/console_gui/console_gui.conf'
self.user_config = user_config.replace("~",self.homePath)
if not os.path.isfile(self.user_config):
self.create_user_config()
self.read_user_config(self.user_config)
# other variable
# self.WindowTitle = 'cl-api-client'
self.default_host = 'localhost'
self.default_port = '8888'
self.client = None
self.MainWidget = MainWgt(self)
self.res_layout = QtGui.QVBoxLayout(self)
self.process_dict = {}
self.param_objects = {}
def create_user_config(self):
if not os.path.exists ('~/.calculate'.replace("~",self.homePath)):
os.mkdir('~/.calculate'.replace("~",self.homePath))
if not os.path.exists ('~/.calculate/console_gui'.replace("~",self.homePath)):
os.mkdir('~/.calculate/console_gui'.replace("~",self.homePath))
if not os.path.isfile (self.user_config):
cfg_text = '[other]\n'\
'lang = en\n\n'\
'[gui]\n'\
'bg_color = 250 250 250\n'
fp = open(self.user_config, 'w')
fp.write(cfg_text)
fp.close()
def read_user_config(self, config):
config = ConfigParser.ConfigParser()
config.read(self.user_config)
###################### other ##########################
# get language
try:
self.lang = config.get('other', 'lang')
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
self.lang = 'en'
# get path to certificates
try:
path_to_cert = config.get('other', 'path_to_cert')
self.path_to_cert = path_to_cert.replace("~",self.homePath)
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
pass
if self.path_to_cert.lower() == 'not':
path_to_cert = '~/.calculate/client_cert/'
self.path_to_cert = path_to_cert.replace("~",self.homePath)
###################### gui ##########################
# get background color
try:
self.method_background_color = config.get('gui', 'bg_color')
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
self.method_background_color = '#f0f0f0'
# get background image
try:
self.background_image = config.get('gui', 'bg_image')
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
self.background_image = '/usr/share/apps/kwin/calculatecubecap.png'
# get background image repeat
try:
self.background_repeat = config.get('gui', 'bg_repeat')
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
self.background_repeat = 'no-repeat'
# get background opacity
try:
self.bg_opacity = config.get('gui', 'bg_opacity')
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
self.bg_opacity = '220'