-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathMyCombo.py
99 lines (87 loc) · 3.2 KB
/
MyCombo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#**************************************************************************
# Copyright (C) 2018, Paul Lutus *
# *
# This program is free software; you can redistribute it and/or modify *
# it under the terms of the GNU General Public License as published by *
# the Free Software Foundation; either version 2 of the License, or *
# (at your option) any later version. *
# *
# This program is distributed in the hope that it will be useful, *
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# GNU General Public License for more details. *
# *
# You should have received a copy of the GNU General Public License *
# along with this program; if not, write to the *
# Free Software Foundation, Inc., *
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
#**************************************************************************
import re
import sys
import os
import time
import struct
import signal
import numpy as np
from PyQt5 import Qt
from PyQt5 import QtCore,QtGui
from PyQt5.QtWidgets import QWidget
class Combo():
def __init__(self,main,config,control,function,config_name,content = None):
self.main = main
self.config = config
self.control = control
self.function = function
self.config_name = config_name
self.index = 0
self.inhibit = False
self.set_content(content)
self.control.currentIndexChanged.connect(self.set_value)
def enable(self,value):
self.control.setEnabled(value)
def check_valid_range(self):
if self.content != None:
n = len(self.content)-1
self.index = (self.index,n)[self.index > n]
def set_content(self,content):
self.inhibit = True
self.control.clear()
self.content = content
if content != None:
self.control.addItems(content)
self.check_valid_range()
self.inhibit = False
self.process_index()
def process_index(self,index = None):
if index == None:
self.index = self.config[self.config_name]
else:
self.config[self.config_name] = index
self.index = index
self.check_valid_range()
self.inhibit = True
self.control.setCurrentIndex(self.index)
self.inhibit = False
def get_index(self):
return self.index
def get_value(self,index = None):
self.process_index(index)
if self.content == None:
v = 0
else:
v = self.content[self.index]
try:
v = int(v)
except:
None
return v
def set_value(self,index = None):
if not self.inhibit:
self.process_index(index)
if self.content != None:
if len(self.content) > 0:
a = self.index
b = self.content[self.index]
self.function(a,b)