Message Boards Message Boards

Code for a basic, general use drag-and-drop panel

Posted 6 years ago

I was trying to compare two large tables side-by-side in Mathematica today, and I couldn't fit everything I wanted to see on the screen. My first attempt to fix this problem involved combining the two tables into a Row and using the Alignment option to fix their relative vertical position, but then the grids' relative positioning was just that: fixed. In the work I was doing, I wanted to move the different grids around like they were sheets of paper on a desk, as an accountant might do while comparing two sets of figures. "Ah-ha!", realized. "I need a windowing interface!".

Luckily, the Wolfram language makes it just incredibly easy to build new interfaces from scratch! Here's what I came up with about an hour of tinkering (for not all-together arbitrary reasons, I decided I preferred having everything in a single front-end window, than using for example, Palettes). The amazing thing to me is that the code that does the work here is just 4 lines! It leaves out a lot of niceties like exception handling and scoping (right now I just define things like screen size and window start position in Global`, but that would be easy to change), but even in this basic state it is a nice little tool that will help me with my work :). The function Windowing defined below takes as its only argument a List of WL expressions that you want to display together in a drag-and-drop interface. Please try it out and let me know what you think!

(* defines some example objects... these could be almost any WL expression *)
data1=Column[RandomInteger[10, 10], Frame->All];
data2=Column[RandomInteger[10, 4], Frame->All];

(* define some visual parameters: background color, universe size, initial position of the two windows *)
bgColor = Lighter[Gray, 0.75];
uSize = {900, 900};
initPos = {{330, 600}, {300, 650}};

(* this code defines the interface *)
Windowing[exprList_]:= DynamicModule[
    {U},
    U = {bgColor, Rectangle[{0, 0}, uSize]};
    Graphics[{U, MapThread[Locator, {initPos, exprList}]}]
]

(* Let's see how it looks. I intentionally made the grids overlapping at the start to better illustrate my initial frustration ;) *)
Windowing[{data1, data2}]
Attachments:
POSTED BY: Paco Jain
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract