How to create and sensibly manage several Gtk.SpinButtons? - python

I need to create several Gtk.SpinButton - their amount will vary.
How to create and sensibly manage several Gtk.SpinButtons?
Gtk3+ and Python
def d_on_value_changed(self, scroll):
print(self.e_spinbutton.get_value_as_int())
print("Zmieniam nowy")
return True
def touch_entry_element(self, line):
self.e_spinbutton = str('self.espinbutton_')+str(line)
self.e_on_value_changed = str('self.e_on_value_changed_')+str(line)
print(self.e_spinbutton)
# spinbutton
adjustment = Gtk.Adjustment(upper=5000, step_increment=5, page_increment=20)
self.e_spinbutton = Gtk.SpinButton()
self.e_spinbutton.set_adjustment(adjustment)
self.e_spinbutton.connect("value-changed", self.d_on_value_changed)

Related

Is there a way to create a pipeline locally using zipline?

I have set up zipline locally on PyCharm. The simulations work, moreover, I have access to premium data from quandl (which automatically updated when I entered my API key). However, now my question is, how do I make a pipeline locally using zipline.
Zipline's documentation is challenging. Zipline.io (as of 2021-0405) is also down. Fortunately, Blueshift has documentation and sample code that shows how to make a pipeline that can be run locally:
Blueshift sample pipeline code is here. (Pipelines library here.)
Zipline documentation can be accessed from MLTrading (archive documentation here) since though challenging it is still useful.
Full code of the pipeline sample code from Blueshift, but modified to run locally through PyCharm, is below the line. Please note as I'm sure you're already aware, the strategy is a bad strategy and you shouldn't trade on it. It does show local instantiations of pipelines though.
"""
Title: Classic (Pedersen) time-series momentum (equal weights)
Description: This strategy uses past returns and go long (short)
the positive (negative) n-percentile
Style tags: Momentum
Asset class: Equities, Futures, ETFs, Currencies
Dataset: All
"""
"""
Sources:
Overall Algorithm here:
https://github.com/QuantInsti/blueshift-demo-strategies/blob/master/factors/time_series_momentum.py
Custom (Ave Vol Filter, Period Returns) Functions Here:
https://github.com/QuantInsti/blueshift-demo-strategies/blob/master/library/pipelines/pipelines.py
"""
import numpy as np
from zipline.pipeline import CustomFilter, CustomFactor, Pipeline
from zipline.pipeline.data import EquityPricing
from zipline.api import (
order_target_percent,
schedule_function,
date_rules,
time_rules,
attach_pipeline,
pipeline_output,
)
def average_volume_filter(lookback, amount):
"""
Returns a custom filter object for volume-based filtering.
Args:
lookback (int): lookback window size
amount (int): amount to filter (high-pass)
Returns:
A custom filter object
Examples::
# from library.pipelines.pipelines import average_volume_filter
pipe = Pipeline()
volume_filter = average_volume_filter(200, 1000000)
pipe.set_screen(volume_filter)
"""
class AvgDailyDollarVolumeTraded(CustomFilter):
inputs = [EquityPricing.close, EquityPricing.volume]
def compute(self, today, assets, out, close_price, volume):
dollar_volume = np.mean(close_price * volume, axis=0)
high_volume = dollar_volume > amount
out[:] = high_volume
return AvgDailyDollarVolumeTraded(window_length=lookback)
def period_returns(lookback):
"""
Returns a custom factor object for computing simple returns over
period.
Args:
lookback (int): lookback window size
Returns:
A custom factor object.
Examples::
# from library.pipelines.pipelines import period_returns
pipe = Pipeline()
momentum = period_returns(200)
pipe.add(momentum,'momentum')
"""
class SignalPeriodReturns(CustomFactor):
inputs = [EquityPricing.close]
def compute(self, today, assets, out, close_price):
start_price = close_price[0]
end_price = close_price[-1]
returns = end_price / start_price - 1
out[:] = returns
return SignalPeriodReturns(window_length=lookback)
def initialize(context):
'''
A function to define things to do at the start of the strategy
'''
# The context variables can be accessed by other methods
context.params = {'lookback': 12,
'percentile': 0.1,
'min_volume': 1E7
}
# Call rebalance function on the first trading day of each month
schedule_function(strategy, date_rules.month_start(),
time_rules.market_close(minutes=1))
# Set up the pipe-lines for strategies
attach_pipeline(make_strategy_pipeline(context),
name='strategy_pipeline')
def strategy(context, data):
generate_signals(context, data)
rebalance(context, data)
def make_strategy_pipeline(context):
pipe = Pipeline()
# get the strategy parameters
lookback = context.params['lookback'] * 21
v = context.params['min_volume']
# Set the volume filter
volume_filter = average_volume_filter(lookback, v)
# compute past returns
momentum = period_returns(lookback)
pipe.add(momentum, 'momentum')
pipe.set_screen(volume_filter)
return pipe
def generate_signals(context, data):
try:
pipeline_results = pipeline_output('strategy_pipeline')
except:
context.long_securities = []
context.short_securities = []
return
p = context.params['percentile']
momentum = pipeline_results
long_candidates = momentum[momentum > 0].dropna().sort_values('momentum')
short_candidates = momentum[momentum < 0].dropna().sort_values('momentum')
n_long = len(long_candidates)
n_short = len(short_candidates)
n = int(min(n_long, n_short) * p)
if n == 0:
print("{}, no signals".format(data.current_dt))
context.long_securities = []
context.short_securities = []
context.long_securities = long_candidates.index[-n:]
context.short_securities = short_candidates.index[:n]
def rebalance(context, data):
# weighing function
n = len(context.long_securities)
if n < 1:
return
weight = 0.5 / n
# square off old positions if any
for security in context.portfolio.positions:
if security not in context.long_securities and \
security not in context.short_securities:
order_target_percent(security, 0)
# Place orders for the new portfolio
for security in context.long_securities:
order_target_percent(security, weight)
for security in context.short_securities:
order_target_percent(security, -weight)

How to segregate my data better within a Python class

I've been working on a project that is a calculator for an electronic part. This is my first full-scale Python project and it has gone through many iterations along the way.
The data is not organized as well as I would like, which I think is making it difficult to improve the program.
I have a class for the module, which has two parts inside of it. Each part has its own attributes that are independent of each other, and the whole module itself has some attributes that the parts don't care about, and some attributes that the parts need. The module also has to do some calculations based on the results of the independent calculations done inside the parts. Here is a photo of the idea I'm trying to explain. As an aside, sometimes there are modules with only one part, but I can suppress the other part by applying some 0's arrays. I would like to be able to have a module where the one part is entirely missing, but that is not my current goal.
The problem is that my class has ~100 lines of self.XXX = None at the beginning to initialize everything, and several functions which IMO are repetitive. It is also quite difficult to traverse the data when stepping through the code - for example, I have to find variables like self.current__partA and self.current__partB. What I think would be helpful is to have something like self.partA.current. If it is done this way, I think it would be more readable.
The problem is, I tried subclasses and it seems like I can't achieve this kind of idea because when I initialize the subclass, I have to initalize a new superclass, meaning that there are two superclasses (two modules with a total of 4 parts, when I want 1 module/2 parts), so I can't really access the info of both subclasses from the superclass because each subclass will have its own instance of the superclass.
I also looked at inner classes but there is an issue where I don't think I can truly access the outer class from the inner class, which kind of defeats the purpose of using this. That could work to a degree, but it would make my code longer and less readable, from what I am seeing.
The first solutions I had were things like dictionaries, which I don't totally hate, but that lead to really janky code that had very little tolerance for errors. The reason is, when you add a list to a dictionary, you can't have a function that automatically throws an error. I can check the dictionary, but it just feels unnatural. It seems to me that it would make more sense to keep each value as a class variable and use functions, getters and setters to manipulate it through the calculation.
My main goal is to organize the data and code effectively so that I am using less lines of code and the program is easier to modify, and it is easier to step through the process. I am not entirely sold on the class structure, it just seemed to be the best way to accommodate what I am trying to do. Is there a way to achieve what I am asking here, or is there a generally more pythonic way to organize my code that would result in a more effective solution?
class Module:
def __init__(self, module_file):
temp_ic, temp_value = self.get__corrected_value(module_file)
temp_if, temp_vf = self.get__corrected_value(module_file)
self.ic_value = interp1d(temp_ic, temp_value, fill_value='extrapolate')
self.ic_esw_on = interp1d(self.get__corrected_esw(module_file), self.get__corrected_esw(module_file["ESWON - IC ESWON"]), fill_value='extrapolate')
self.ic_esw_off = interp1d(self.get__corrected_esw(module_file["IC - IC ESWOFF"]), self.get__corrected_esw(module_file["ESWOFF - IC ESWOFF"]), fill_value='extrapolate')
self.rg_on_esw_on = interp1d(module_file["RGON - ESWON RGON"], module_file["ESWON - ESWON RGON"], fill_value='extrapolate')
self.rg_off_esw_off = interp1d(module_file["RGOFF - ESWOFF RGOFF"], module_file["ESWOFF - ESWOFF RGOFF"], fill_value='extrapolate')
self.ic_err = interp1d(self.get__corrected_esw(module_file["IC - IC ERR"]), self.get__corrected_esw(module_file["ERR - IC ERR"]), fill_value='extrapolate')
self.if_vf = interp1d(temp_if, temp_vf, fill_value='extrapolate')
self.rg_on_err = interp1d(module_file["RGON - ERR RGON"], module_file["ERR - ERR RGON"], fill_value='extrapolate')
self.nameplate_vcc = module_file['Nameplate VCC']
if module_file['vcc_ratio'] > 0:
self.vcc_ratio = module_file['vcc_ratio']
else:
self.vcc_ratio = 0
self.name = self.get__module_name(module_file)
self.current__PartA = []
self.current__PartB = []
self.some_thing_loss__PartA = []
self.esw_on_loss = []
self.esw_off_loss = []
self.esw_loss__PartA = []
self.energy__PartA = []
self.value__PartA = []
self.some_thing_loss__PartB = []
self.err_loss = []
self.energy__PartB = []
self.value__PartB = []
self.rg_scalar_esw_on = None
self.rg_scalar_esw_off = None
self.rg_scalar_err = None
self.value_dc__PartA = module_file['PartA value DC']
self.value_dc__PartB = module_file['PartB value DC']
self.value_dc__module = module_file['Module value DC']
self.trans_r_values__PartA = module_file["PartA R Values"]
self.trans_t_values__PartA = module_file["PartA T Values"]
self.trans_r_values__PartB = module_file["PartB R Values"]
self.trans_t_values__PartB = module_file["PartB T Values"]
self.some_thing_loss_total__PartA = None
self.some_thing_loss_total__PartB = None
self.esw_on_loss_total = None
self.esw_off_loss_total = None
self.esw_loss_total = None
self.err_loss_total = None
self.device_loss_total__PartA = None
self.device_loss_total__PartB = None
self.module_loss_total = None
self.delta_tcase_ave = None
self.delta_value_ave__PartA = None
self.delta_value_ave__PartB = None
self.nominal_value_ave__PartA = None
self.nominal_value_ave__PartB = None
self.delta_value_max__PartA = None
self.delta_value_max__PartB = None
self.nominal_value_max__PartA = None
self.nominal_value_max__PartB = None
self.value_max_PartA_list = []
self.value_max_PartB_list = []
self.thermal_interp_is_four_degree = self.check__thermal_interp()
self.switches_per_degree = None
self.input_output_freq = None
self.time_division = None
self.input_t_sink = None
self.step_size = None
self.step_range = None
self.sec_per_cycle_degree = None
self.duty_p = None
self.value_PartA_list = None
self.value_PartB_list = None
self.time_list = None
self.rad_list = None
self.value_max__PartA_thermo = None
self.value_max__PartB_thermo = None
self.value_max__time_value = None
def check__some_input_conditions_and_change_input(self): # todo could this be cleaned?
blah
def get__max_current(self):
return max(self.nominal_value_max__PartB, self.nominal_value_max__PartA)
def set__some_module_values(self, is_three_level, system): # todo call this something different, and break it out for 3-level
blah
def set_values_for_both_parts(self, input_instance, system_instance, module_location=None):
lots of blah
def set__current_PartA(self, current):
self.current__PartA = current
def set__current_partB(self, current):
blah
def calculate__another_other_loss_for_part_A(self, duty):
blah
def calculate__another_loss_for_partB(self, duty):
blah
def calculate__another_loss_for_partA(self, duty=None):
blah
def calculate__some_loss_for_partA(self, duty=None):
blah
def calculate__some_loss_for_partB(self, duty=None):
blah
def calculate__energy_power_for_both_parts(self):
blah
def calculate__temperatures_for_both_parts(self):
blah
def calculate__max_temp(self): # maybe split into PartA and PartB separately?
self.create_thermal_resistance_dict()
value_PartA_list = []
value_PartB_list = []
next_array_PartA = self.value__PartA
next_array_PartA = self.rotate(next_array_PartA, -1)
delta_p_PartA = [next_el - last_el for next_el, last_el in zip(next_array_PartA, self.value__PartA)]
last_power_PartA = self.value__PartA[-1] - self.device_loss_total__PartA
first_power_PartA = self.value__PartA[0] - self.device_loss_total__PartA
value_dict_PartA_added = [self.get_PartA_value_from_time(i * self.sec_per_cycle_degree + self.value_max__time_value) for i in range(self.step_range)]
value_dict_PartA_added = [old + new for old, new in zip(self.value_max__PartA_thermo, value_dict_PartA_added)]
value_PartA_inst_init = [self.input_t_sink + self.delta_value_ave__PartA + self.delta_tcase_ave - last_power_PartA * self.value_max__PartA_thermo[i] + first_power_PartA * value_dict_PartA_added[i] for i in range(self.step_range)]
delta_value_PartB = self.device_loss_total__PartB * self.value_dc__PartB
next_array_PartB = self.value__PartB
next_array_PartB = self.rotate(next_array_PartB, -1)
delta_p_PartB = [next_el - last_el for next_el, last_el in zip(next_array_PartB, self.value__PartB)]
last_power_PartB = self.value__PartB[-1] - self.device_loss_total__PartB
first_power_PartB = self.value__PartB[0] - self.device_loss_total__PartB
value_dict_PartB_added = [self.get_PartB_value_from_time(i * self.sec_per_cycle_degree + self.value_max__time_value) for i in range(self.step_range)]
value_dict_PartB_added = [old + new for old, new in zip(self.value_max__PartB_thermo, value_dict_PartB_added)]
value_PartB_inst_init = [self.input_t_sink + delta_value_PartB + self.delta_tcase_ave - last_power_PartB * self.value_max__PartB_thermo[i] + first_power_PartB * value_dict_PartB_added[i] for i in range(self.step_range)]
for index in range(self.step_range):
value_dict_PartA_fix = [value_dict_PartA_added[i] if i <= index else self.value_max__PartA_thermo[i] for i in range(self.step_range)]
# value_dict_PartA_fix_orig = [val for val in value_dict_PartA_fix]
value_dict_PartA_fix.reverse()
new_value_PartA = self.rotate(value_dict_PartA_fix, index)
new_value_PartA = new_value_PartA[:359]
temp_add_vals_PartA = [delta_p * value for delta_p, value in zip(delta_p_PartA, new_value_PartA)]
sum_temp_add_vals_PartA = sum(temp_add_vals_PartA)
value_PartA_list.append(sum_temp_add_vals_PartA)
value_dict_PartB_fix = [value_dict_PartB_added[i] if i <= index else self.value_max__PartB_thermo[i] for i in range(self.step_range)]
# value_dict_PartB_fix_orig = [val for val in value_dict_PartB_fix]
value_dict_PartB_fix.reverse()
new_value_PartB = self.rotate(value_dict_PartB_fix, index)
new_value_PartB = new_value_PartB[:359]
temp_add_vals_PartB = [delta_p * value for delta_p, value in zip(delta_p_PartB, new_value_PartB)]
sum_temp_add_vals_PartB = sum(temp_add_vals_PartB)
value_PartB_list.append(sum_temp_add_vals_PartB)
value_PartA_list = [value + diff for value, diff in zip(value_PartA_inst_init, value_PartA_list)]
value_ave_PartA = self.nominal_value_ave__PartA - np.average(value_PartA_list)
self.value_PartA_list = [value + value_ave_PartA for value in value_PartA_list]
value_PartB_list = [value + diff for value, diff in zip(value_PartB_inst_init, value_PartB_list)]
value_ave_PartB = self.nominal_value_ave__PartB - np.average(value_PartB_list)
self.value_PartB_list = [value + value_ave_PartB for value in value_PartB_list]
self.time_list = [i * self.sec_per_cycle_degree + self.value_max__time_value for i in range(self.step_range)]
self.rad_list = [i * self.step_size for i in range(self.step_range)]
self.nominal_value_max__PartA = max(value_PartA_list)
self.nominal_value_max__PartB = max(value_PartB_list)
self.delta_value_max__PartA = max(self.value_PartA_list) - self.input_t_sink
self.delta_value_max__PartB = max(self.value_PartB_list) - self.input_t_sink
self.value_max_PartA_list = value_PartA_list
self.value_max_PartB_list = value_PartB_list
def rotate(self, l, n):
return l[-n:] + l[:-n]
def do_calculation_for_either_part(self, step, spcd, index, scalar, growth, time): # todo does everything need to be passed in?
blah
def get_other_part's_value(self, time): # todo could this be folded into below
blah
def get_one_part's_value(self, time):
blah
def integrate_value_for_other_part(self, step, spcd, start_time, index): # todo could this be folded into below
blah
def integrate_value_for_one_part(self, step, spcd, start_time, index): # todo remove interp check
blah
def create_some_dict_for_both_parts(self): # todo could this be cleaned
50 lines of blah
def get__other_corrected_array(self, array): # todo could this be simplified?
blah
def get__corrected_array(self, input arrays): # todo is this necessary
blah
def get__some_value(self, value): # todo isn't there one of these already?
blah
def get__module_name(self, module_file):
blah
The commentators are correct that an MCVE would definitely enhance your post and so my answer is a bit limited. I just want to point out that your data members can be any python object.
So if your data access pattern would benefit from storing your data in pandas and interacting with it as pandas:
class YourClass:
def __init__(self, data):
self.data = # Your pandas df
Or json:
import json
class YourClass:
def __init__(self, data):
self.data = json.loads(data)
Or numpy:
class YourClass:
def __init__(self, data):
self.data = # Your numpy ndarray
And then your class can be called simply as YourClass(data)
Edit: Looking at your code, literally ALL of your self.value = None lines are superfluous in my view. if they are a members of a tabular data input they can be initialized:
class Module:
def __init__(self, data):
self.data = pd.DataFrame()
Once they are initialized as an empty dataframe their CRUD operations can map to the very mature pandas CRUD operations. Similarly self.data = {} for key-value pairs data structure like JSON, and so on. For the rest, you can catch the case where data.key is undefined in generic getters and setters and not bother with initializing them.

PyQT labels cut-off

I am working on an Sonos Controller using the PyQT lib.
When i change to netxt or prev track, the labels are updated with the artist, title and album info. They are cut-off tho. Anyone experienced this before ? Its not a length issue, as the cutting off seems to change.
This is the code I update the labels with:
def currentTrackInfo(self):
currentTrackInfoDict = {}
currentZone = str(self.cb.currentText())
deviceDict = self.sonosZonesCoordinatorsIP()
for key, value in deviceDict.items():
if value == currentZone:
device = SoCo(key)
track = device.get_current_track_info()
current_title = track['title']
current_artist = track["artist"]
current_album = track["album"]
currentTrackInfoDict.update({"current_title": current_title})
currentTrackInfoDict.update({"current_artist": current_artist})
currentTrackInfoDict.update({"current_album": current_album})
self.artImage()
return currentTrackInfoDict
def updateTrackInfo(self):
self.artistlabel.clear
self.albumlabel.clear
self.titlelabel.clear
self.currentTrackInfoDict = self.currentTrackInfo()
self.artistlabel.setText("{}".format(self.currentTrackInfoDict["current_artist"]))
self.albumlabel.setText("{}".format(self.currentTrackInfoDict["current_album"]))
self.titlelabel.setText("{}".format(self.currentTrackInfoDict["current_title"]))

multiple python progressive progresssbar with varying lengths

I am trying to use the progressive python progressbar to create two stacked progressbar. It should look something like
Articles[####### ]
Links [############]
So if you notice, two progress bars are of differing lengths. I have some code below that creates two progress bars of the same length. I was wondering if someone could tell me how to adjust this so that I can allow each progress bar to be different sizes.
Here is the test code that I developed.
from time import sleep
from blessings import Terminal
from progressive.bar import Bar
from progressive.tree import ProgressTree, Value, BarDescriptor
def progbar(_outer, _inner):
leaf_values = [Value(0) for i in range(2)]
test_d = {
'Link pages scraped': BarDescriptor(value=leaf_values[0],
type=Bar, max_value = _outer),
'Articles collected': BarDescriptor(value = leaf_values[1],
type=Bar, max_value= _inner)
}
def incr_value(obj, _counter_outer, _counter_inner):
if _counter_inner < _outer:
leaf_values[0].value += 1
if _counter_outer < _inner:
leaf_values[1].value += 1
def are_we_done(obj):
if _counter_inner == _outer and _counter_outer == _inner:
return(True)
else:
return(False)
# Create blessings.Terminal instance
t = Terminal()
# Initialize a ProgressTree instance
n = ProgressTree(term=t)
# We'll use the make_room method to make sure the terminal
# is filled out with all the room we need
n.make_room(test_d)
_counter_inner = 0
_counter_outer = 0
while not are_we_done(test_d):
sleep(2)
n.cursor.restore()
# We use our incr_value method to bump the fake numbers
incr_value(test_d,_counter_outer, _counter_inner)
# Actually draw out the bars
n.draw(test_d)
_counter_inner += 1
_counter_outer += 1
if __name__ == '__main__':
progbar(100, 20)
ok, first I assume the indention problem is from the copy and paste
to make it in diffrent sizes you need to change the lines
test_d = {
'Link pages scraped': BarDescriptor(value=leaf_values[0],
type=Bar, max_value = _outer),
'Articles collected': BarDescriptor(value = leaf_values[1],
type=Bar, max_value= _inner)
}
to:
test_d = {
'Link pages scraped': BarDescriptor(value=leaf_values[0],
type=Bar, kwargs=dict(max_value = _outer,width="50%")),
'Articles collected': BarDescriptor(value = leaf_values[1],
type=Bar, kwargs=dict(max_value= _inner,width="10%"))
}
notice that i call the BarDescriptor with kwargs as a normal dict and not with **. thats how they use it in this exapmle: https://github.com/hfaran/progressive/blob/master/progressive/examples.py
and it seems to work (the parameters in the kwargs are used to call the Bar class)
you probably want to change the 10% and 50% to something not hardcoded.
the % means percentage of the terminal width. you can also do "20c" witch means it width will be 20 characters

How do I get close event to work in wxPython using AUIManager?

How would I add another event to the pane created in our GUI manager class (below). I want to detect when the x button closes the pane. I've tried using the same format as wx.EVT_MENU for wx.EVT_CLOSE but it didn't work.
def popup_panel(self, p):
"""
Add a panel object to the AUI manager
:param p: panel object to add to the AUI manager
:return: ID of the event associated with the new panel [int]
"""
ID = wx.NewId()
self.panels[str(ID)] = p
self.graph_num += 1
if p.window_caption.split()[0] in NOT_SO_GRAPH_LIST:
windowcaption = p.window_caption
else:
windowcaption = 'Graph'#p.window_caption
windowname = p.window_name
# Append nummber
captions = self._get_plotpanel_captions()
while (1):
caption = windowcaption + '%s'% str(self.graph_num)
if caption not in captions:
break
self.graph_num += 1
# protection from forever-loop: max num = 1000
if self.graph_num > 1000:
break
if p.window_caption.split()[0] not in NOT_SO_GRAPH_LIST:
p.window_caption = caption
#p.window_caption = windowcaption+ str(self.graph_num)
p.window_name = windowname + str(self.graph_num)
style1 = self.__gui_style & GUIFRAME.FIXED_PANEL
style2 = self.__gui_style & GUIFRAME.FLOATING_PANEL
if style1 == GUIFRAME.FIXED_PANEL:
self._mgr.AddPane(p, wx.aui.AuiPaneInfo().
Name(p.window_name).
Caption(p.window_caption).
Position(10).
Floatable().
Right().
Dock().
MinimizeButton().
Resizable(True).
# Use a large best size to make sure the AUI
# manager takes all the available space
BestSize(wx.Size(PLOPANEL_WIDTH,
PLOPANEL_HEIGTH)))
self._popup_fixed_panel(p)
elif style2 == GUIFRAME.FLOATING_PANEL:
self._mgr.AddPane(p, wx.aui.AuiPaneInfo().
Name(p.window_name).Caption(p.window_caption).
MinimizeButton().
Resizable(True).
# Use a large best size to make sure the AUI
# manager takes all the available space
BestSize(wx.Size(PLOPANEL_WIDTH,
PLOPANEL_HEIGTH)))
self._popup_floating_panel(p)
# Register for showing/hiding the panel
wx.EVT_MENU(self, ID, self.on_view)
if p not in self.plot_panels.values() and p.group_id != None:
self.plot_panels[ID] = p
if len(self.plot_panels) == 1:
self.panel_on_focus = p
self.set_panel_on_focus(None)
if self._data_panel is not None and \
self._plotting_plugin is not None:
ind = self._data_panel.cb_plotpanel.FindString('None')
if ind != wx.NOT_FOUND:
self._data_panel.cb_plotpanel.Delete(ind)
if caption not in self._data_panel.cb_plotpanel.GetItems():
self._data_panel.cb_plotpanel.Append(str(caption), p)
return ID
I want to be able to pick up the event in the plotting child class.
def create_panel_helper(self, new_panel, data, group_id, title=None):
"""
"""
## Set group ID if available
## Assign data properties to the new create panel
new_panel.set_manager(self)
new_panel.group_id = group_id
if group_id not in data.list_group_id:
data.list_group_id.append(group_id)
if title is None:
title = data.title
new_panel.window_caption = title
new_panel.window_name = data.title
event_id = self.parent.popup_panel(new_panel)
#remove the default item in the menu
if len(self.plot_panels) == 0:
pos = self.menu.FindItem(DEFAULT_MENU_ITEM_LABEL)
if pos != -1:
self.menu.Delete(DEFAULT_MENU_ITEM_ID)
# Set UID to allow us to reference the panel later
new_panel.uid = event_id
# Ship the plottable to its panel
wx.CallAfter(new_panel.plot_data, data)
self.plot_panels[new_panel.group_id] = new_panel
# Set Graph menu and help string
helpString = 'Show/Hide Graph: '
for plot in new_panel.plots.itervalues():
helpString += (' ' + plot.label + ';')
self.menu.AppendCheckItem(event_id, new_panel.window_caption,
helpString)
self.menu.Check(event_id, IS_WIN)
wx.EVT_MENU(self.parent, event_id, self._on_check_menu)
wx.EVT_CLOSE(self.parent, event_id, self._on_close_panel)
wx.EVT_SHOW(new_panel, self._on_show_panel)
Did you try catching wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE or wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED? I would think that would do what you want. I am assuming you're using wx.aui rather than wx.agw.aui. I suspect the latter is similar though.
EDIT: Oops. I read this wrong. I thought the OP wanted to know about AUINotebook. The event you're probably looking for is wx.aui.EVT_AUI_PANE_CLOSE

Categories

Resources