import pyqtgraph as _pg
# Regular imports
import time as _t
import os as _os
import numpy as _n
import scipy.special as _scipy_special
import traceback as _traceback
_p = _traceback.print_last
import spinmob as _s
_d = _s.data
# import pyqtgraph and create the App.
import pyqtgraph as _pg
_e = _pg.QtCore.QEvent
# Syntax highlighter
from . import _syntax
_a = _pg.mkQApp()
# set the font if we're in linux
#if _sys.platform in ['linux', 'linux2']: _a.setFont(_pg.QtGui.QFont('Arial', 8))
_defaults = dict(margins=(10,10,10,10))
# Get the current working directory and keep it! Dialogs change this on the fly
_cwd = _os.getcwd()
# HACK FOR WEIRD BEHAVIOR WITH hasattr AND PYQTGRAPH OBJECTS. NO IDEA.
def hasattr_safe(x,a):
try:
x.a
return True
except:
return False
class BaseObject(object):
log = None
def __init__(self, autosettings_path=None):
"""
Base object containing stuff common to all of our objects. When
deriving objects from this, call BaseObject.__init__(self) as the
LAST step of the new __init__ function.
"""
# Parent object (to be set)
self._parent = None
self._style = ''
# for remembering settings; for child objects, overwrite both, and
# add a load_gui_settings() to the init!
self._autosettings_path = autosettings_path
self._autosettings_controls = []
self._lazy_load = dict()
# common signals
return
def hide(self, opposite=False):
"""
Hides the widget.
Parameters
----------
opposite=False
If True, do the opposite (show the widget).
"""
if opposite: self._widget.show()
else: self._widget.hide()
return self
def show(self, opposite=False):
"""
Shows the widget.
Parameters
----------
opposite=False
If True, do the opposite (show the widget).
"""
if opposite: self._widget.hide()
else: self._widget.show()
return self
def set_hidden(self, hidden=True):
"""
Hides or shows the widget.
Parameters
----------
hidden=True
Whether it should be hidden.
"""
if hidden: self.hide()
else: self.show()
return self
def set_colors(self, text=None, background=None):
"""
Sets the colors of the text area.
Parameters
----------
text=None
Color of the main text.
background=None
Color of the background. None means transparent.
"""
self._widget.setStyleSheet(self._widget.__class__.__name__ + " {"+self._style+" background-color: "+str(background)+"; color: "+str(text)+"}")
return self
def set_style(self, style=''):
"""
Sets the style for the object. Updates self._style for future calls
to self.set_colors() etc.
Parameters
----------
style=''
Can be any css style elements or a list of them, e.g.,
'font-family:monospace; background-color:pink;'
"""
self._widget.setStyleSheet(self._widget.__class__.__name__ + " {"+style+"}")
self._style = style
return self
def set_width(self, width):
"""
Sets the width of the object. This is only valid for some controls, as
it just uses self.setFixedWidth.
"""
self._widget.setFixedWidth(width)
return self
def set_height(self, height):
"""
Sets the width of the object. This is only valid for some controls, as
it just uses self.setFixedHeight.
"""
self._widget.setFixedHeight(height)
return self
def set_pyqtgraph_options(self, **kwargs):
"""
Sets the options for a pyqtgraph widget, via keyword arguments, e.g.,
suffix='pants'.
Returns self
"""
self._widget.setOpts(**kwargs)
return self
def set_parent(self, parent):
"""
Sets the parent object manually (usually this is done automatically
when placing the object).
"""
self._parent = parent
def get_pyqtgraph_options(self):
"""
Returns a copy of the current options dictionary for the pyqtgraph widget.
"""
return dict(self._widget.opts)
def get_parent(self):
"""
Gets the parent object into which this object was placed.
"""
return self._parent
def get_window(self):
"""
Returns the object's parent window. Returns None if no window found.
"""
x = self
while not x._parent == None and \
not isinstance(x._parent, Window):
x = x._parent
return x._parent
def process_events(self):
"""
Processes pending GUI events. This just calls
self.get_window().process_events()
so it requires the object to have been placed somewhere within a window.
"""
self.get_window().process_events()
return self
def sleep(self, seconds=0.05, dt=0.01):
"""
A "smooth" version of time.sleep(): waits for the time to pass but
processes events every dt as well.
Note this requires that the object is either a window or embedded
somewhere within a window.
"""
t0 = _t.time()
while _t.time()-t0 < seconds:
# Pause a bit to avoid heavy CPU
_t.sleep(dt)
# process events
self.process_events()
def block_events(self):
"""
Prevents the widget from sending signals.
"""
self._widget.blockSignals(True)
self._widget.setUpdatesEnabled(False)
def unblock_events(self):
"""
Allows the widget to send signals.
"""
self._widget.blockSignals(False)
self._widget.setUpdatesEnabled(True)
def disable(self, value=True):
"""
Disables the widget.
Parameters
----------
value=True
If set to False, enables the widget.
"""
self._widget.setEnabled(not value)
return self
def enable(self, value=True):
"""
Enables the widget.
Parameters
----------
value=True
If set to False, disables the widget.
"""
self._widget.setEnabled(value)
return self
def print_message(self, message="heya!"):
"""
If self.log is defined to be an instance of TextLog, it print the
message there. Otherwise use the usual "print" to command line.
"""
if self.log == None: print(message)
else: self.log.append_text(message)
def save_gui_settings(self, *a):
"""
Saves just the current configuration of the controls if the
autosettings_path is set.
"""
# only if we're supposed to!
if self._autosettings_path:
# Get the gui settings directory
gui_settings_dir = _os.path.join(_cwd, 'egg_settings')
# make sure the directory exists
if not _os.path.exists(gui_settings_dir): _os.mkdir(gui_settings_dir)
# make a path with a sub-directory
path = _os.path.join(gui_settings_dir, self._autosettings_path)
# for saving header info
d = _d.databox(delimiter=',')
# add all the controls settings
for x in self._autosettings_controls: self._store_gui_setting(d, x)
# Summary of standard set_value items
d.h(_autosettings_standard_items=list(d.hkeys))
# Add any additional special information specified by derived objects.
self._additional_save_gui_settings(d)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共56个文件
py:42个
dat:9个
binary:2个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
资源分类:Python库 所属语言:Python 资源全名:Spinmob-3.4.5.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![application/x-gzip](https://img-home.csdnimg.cn/images/20210720083646.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 56 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/277f6345dca0446498fbbc03843436aa_qq_38161040.jpg!1)
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)