Callback Functions
The functions that are called when a widget is activated all have the same form:
def cb(self, e):
...
The first argument is always self because the callbacks in this application are all
methods defined in the PeakViewerApp class.
That allows them to access the data and other parts of the GUI if needed.
The second argument is an event object. It has several attributes, but the one we use most often is a reference to the widget that caused the event.
Here is an example. When one of the buttons next to the chromosome name in the main display is clicked we want to update the display to show the next or previous chromsome in the data set. The code that sets up the application attaches this callback to both buttons:
def change_chromosome_cb(self, e):
delta = 1 if e.obj is self.forward_button else -1
self.chr_index = (self.chr_index + delta) % len(self.clist)
...
The goal is to update the value of the variable that holds the current chromosome ID.
If the user clicked the forward button we want to add 1, otherwise we want to subtract 1.
The first statement looks at e.obj, which is a reference to the widget that triggered this event, and assigns delta to be either 1 or -1, depending on which button was clicked.
The second line updates the chromosome ID.
filter_cb
Callback function invoked when any of the widgets used for filtering (sliders, checkbox, etc) is activated.
Source code in src/xo/gui.py
604 605 606 607 608 609 610 | |
change_chromosome_cb
Callback function invoked when the left or right button next to the chromosome name is clicked.
Source code in src/xo/gui.py
619 620 621 622 623 624 625 626 627 | |
chromosome_edited_cb
Callback function invoked whenever the chromosome ID is updated. This will happen when the user edits the chromosome name or the name changes after a button click.
Source code in src/xo/gui.py
629 630 631 632 633 634 635 636 637 638 639 640 | |
toggle_text_cb
Callback function invoked when a toggle button in the chromosome display is clicked. Toggles the visibility of the frame and updates the button name based on the new visibility state.
Source code in src/xo/gui.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 | |