Matplotlib plot zooming with scroll wheel

This should work. It re-centers the graph on the location of the pointer when you scroll. import matplotlib.pyplot as plt def zoom_factory(ax,base_scale = 2.): def zoom_fun(event): # get the current x and y limits cur_xlim = ax.get_xlim() cur_ylim = ax.get_ylim() cur_xrange = (cur_xlim[1] – cur_xlim[0])*.5 cur_yrange = (cur_ylim[1] – cur_ylim[0])*.5 xdata = event.xdata # get … Read more

MouseListener Help Java

Any Component can have a MouseListener. JLabel is nice for a colored rectangle, as long as you make it opaque. Addendum: Having recommended MouseAdapter elsewhere, I should mention that one instance is enough. Addendum: This update adds the mouse listener in the ColorLabel constructor. import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.GridLayout; import java.awt.event.MouseAdapter; import … Read more

Generate Tkinter Buttons dynamically

I think the problem is that the lambda is picking up the final value of i after the for loop ends. This should fix that (untested): import Tkinter as tk for i in range(boardWidth): newButton = tk.Button(root, text=str(i+1), command=lambda j=i+1: Board.playColumn(j, Board.getCurrentPlayer())) Board.boardButtons.append(newButton) Update BTW, this worked by adding an argument to the lambda function … Read more

Force redraw before long running operations

The following code will do what you’re looking for. However I would not use it. Use the BackgroundWorker class for long time operations. It’s easy to use and very stable. Here the code: public static void ProcessUITasks() { DispatcherFrame frame = new DispatcherFrame(); Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(delegate(object parameter) { frame.Continue = false; return null; }), null); … Read more

How to set a custom object in a JTable row

Instead of splitting the User object up before you create the model, add it directly to the model and allow the model to do the work for you… For example public class VstTableItemModel extends AbstractTableModel { private List<User> users; public VstTableItemModel(List<User> users) { this.users = new ArrayList<User>(users); } @Override public int getRowCount() { return users.size(); … Read more

UI Automation “Selected text”

private void button1_Click(object sender, EventArgs e) { Process[] plist = Process.GetProcesses(); foreach (Process p in plist) { if (p.ProcessName == “notepad”) { AutomationElement ae = AutomationElement.FromHandle(p.MainWindowHandle); AutomationElement npEdit = ae.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, “Edit”)); TextPattern tp = npEdit.GetCurrentPattern(TextPattern.Pattern) as TextPattern; TextPatternRange[] trs; if (tp.SupportedTextSelection == SupportedTextSelection.None) { return; } else { trs = tp.GetSelection(); lblSelectedText.Text = … Read more