Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Sep 16, 2019 11:54 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Ideas on how to create task list
PostPosted: Fri Feb 19, 2010 10:19 pm 
Offline

Joined: Sun Jun 24, 2007 12:24 pm
Posts: 441
Location: Madrid
Hi there.

An application I'm developing for the office requires tasks to be launched and run in the background, most of which take a few minutes to complete. While looking at UI options on how to display something like this I was suggested to take a hint from the way Transmission displays active torrents:

Image

The idea would be to have a simple toolbar at the top controlling whether all tasks are paused or just the selected ones and to delete all or selected ones and that each task is an item in a sort of listbox.

Now, I know a normal listbox wouldn't be able to do something like this so I come to ask how would you guys go about implementing something like this?

I had thought trying to do a sort of simple list that adds canvas, one after the other, for as many tasks as are created (the list is dynamic, and the user can keep adding tasks to it) and display in the task a progressbar and several lines of information (again, very similar to the screenshot taken from Transmission's site).

Since not all lines may be identical I was thinking of having "template" canvases I could subclass for the individual tasks depending on the type but the part I have no clue on how to being is on creating the pseudo-listbox to contain the canvases and how to stack them in a way they looked like a listbox (and scroll accordingly). The listbox and the canvases themselves have almost no interaction in them, other than being able to select them.

Could someone throw a hint this way on how this could be accomplished?

_________________
----
http://eduo.info/
http://gallery.eduo.info/
http://twitter.com/eduo/


Top
 Profile  
Reply with quote  
 Post subject: Re: Ideas on how to create task list
PostPosted: Fri Feb 19, 2010 11:54 pm 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
Location: Southern California
Here's how I would organize it...

* I would create a new class TaskDisplay. One of the properties would hold a picture. There would be public methods allowing other objects to update the state (i.e. progress), and a Draw method to fill the picture. Keep track of state changes with a Dirty property so that you can tell if a redraw is necessary.

* I would have a single Canvas subclass which sits on the window and holds a list of TaskDisplay instances in a property, one per task.

* I would have a Timer that tells the Canvas to refresh periodically, and a scroll bar.

Now the code which does the real work can report progress to the TaskDisplays without triggering screen updates. And the Timer lets you control how often you want to update the screen. This can be important. You want to be able to control the frequency of CPU consuming redraws separately from the frequency at which your tasks report progress. Your end user can't see progress updates 1,000x per second, for example.

When the Canvas Paint event is raised, you take the scroll bar position, walk the TaskDisplay list, and figure out what should be on the screen. Call TaskDisplay.Draw on just those instances. There's no need to draw 1,000 TaskDisplays if only 4 are visible on the screen at a time. This is also where the Dirty property comes in. If the state has not changed since the last Draw, the TaskDisplay instance can just skip drawing its picture to save time. Now copy the pictures to the actual Canvas, taking into account the scroll position and copying partial pictures at the top and bottom as necessary so you have nice, smooth, pixel-by-pixel scrolling just like a "real" list box. (Actually, for TaskDisplays which are only partially on screen at the top, you can probably pass a negative y value to Canvas.Graphics.DrawPicture. For the bottom let the Canvas clip it.)

For figuring out which TaskDisplays should be on screen, you will want a TaskDisplay.GetHeight method. I would pass the Canvas to both TaskDisplay.GetHeight and TaskDisplay.Draw. That way TaskDisplay can query the Canvas for important details, like the Canvas width. A TaskDisplay will need to compare the Canvas width to its picture object to detect a resize and recreate the picture / redraw on resize.

Scrolling is just a matter of refreshing the Canvas.

Properly designed your TaskDisplay class would be easy to subclass for different tasks and display requirements.

If you don't want to draw your own progress bar, place a ProgressBar control on your Window, but off the visible part of the Window so users can't see it. Be sure to lock its position so that if your window is resized it doesn't all of a sudden become visible. (You can't just uncheck Visible for this to work.) Now in TaskDisplay.Draw the TaskDisplay can get this ProgressBar, set the max and value, and use DrawInto to render the bar to its picture. (This will work on Mac OS X and Windows. Not sure about Linux.) Remember that Mac OS X bars are normally animated. You can either forget about the animation, or have your Timer fire fast enough for the animation to work. (And in that case always redraw the bar regardless of Dirty.)

Hope this helps!

_________________
Daniel L. Taylor
Custom Controls for Real Studio WE!
Visit: http://www.webcustomcontrols.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Ideas on how to create task list
PostPosted: Fri Feb 19, 2010 11:56 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
You most certainly can do this kind of thing with a listbox.....
investigate the CELLBACKGROUNDPAINT event, put code there to draw your text/progress bar
and use INVALIDATECELL to update as required.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Ideas on how to create task list
PostPosted: Sat Feb 20, 2010 12:12 pm 
Offline

Joined: Sun Jun 24, 2007 12:24 pm
Posts: 441
Location: Madrid
DaveS wrote:
You most certainly can do this kind of thing with a listbox.....
investigate the CELLBACKGROUNDPAINT event, put code there to draw your text/progress bar
and use INVALIDATECELL to update as required.


Can I put all these elements in a single listbox cell? Would you have an example you could point me to? Obviously not what I want but using the events in this way. I have never seen anything like this in RB yet.

_________________
----
http://eduo.info/
http://gallery.eduo.info/
http://twitter.com/eduo/


Top
 Profile  
Reply with quote  
 Post subject: Re: Ideas on how to create task list
PostPosted: Sat Feb 20, 2010 3:42 pm 
Offline
User avatar

Joined: Fri Sep 30, 2005 11:48 am
Posts: 3554
Location: Lenexa, KS
Look at Alex's Custom Cells listbox at http://homepage.mac.com/alexrestrepo/indexmain.html

_________________
Bob K.

A blog about being a Real Studio/Xojo developer at http://www.bkeeneybriefs.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Ideas on how to create task list
PostPosted: Sat Feb 20, 2010 6:21 pm 
Offline

Joined: Sun Jun 24, 2007 12:24 pm
Posts: 441
Location: Madrid
Bob Keeney wrote:
Look at Alex's Custom Cells listbox at http://homepage.mac.com/alexrestrepo/indexmain.html


Ah. This is quite different than my idea of putting a canvas in a listbox cell, indeed.

It's a HELL of a lot more work, too and wouldn't be able to use any standard widgets, I understand.

_________________
----
http://eduo.info/
http://gallery.eduo.info/
http://twitter.com/eduo/


Top
 Profile  
Reply with quote  
 Post subject: Re: Ideas on how to create task list
PostPosted: Sun Feb 21, 2010 7:07 pm 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
Location: Southern California
eduo wrote:
Bob Keeney wrote:
Look at Alex's Custom Cells listbox at http://homepage.mac.com/alexrestrepo/indexmain.html


Ah. This is quite different than my idea of putting a canvas in a listbox cell, indeed.

It's a HELL of a lot more work, too and wouldn't be able to use any standard widgets, I understand.


What are your standard widgets? Existing control subclasses? ContainerControls?

DrawInto has a few quirks. But if you don't hit those problems, or can work around them, you could use a variation of the architecture I described, or a ListBox with CellBackgroundPaint, to get your widgets on screen.

Past experience causes me to lean towards just doing the work myself, but a ListBox is capable so long as you work within its boundaries.

_________________
Daniel L. Taylor
Custom Controls for Real Studio WE!
Visit: http://www.webcustomcontrols.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Ideas on how to create task list
PostPosted: Mon Feb 22, 2010 5:51 pm 
Offline

Joined: Sun Jun 24, 2007 12:24 pm
Posts: 441
Location: Madrid
taylor-design wrote:
eduo wrote:
Bob Keeney wrote:
Look at Alex's Custom Cells listbox at http://homepage.mac.com/alexrestrepo/indexmain.html

Ah. This is quite different than my idea of putting a canvas in a listbox cell, indeed.
It's a HELL of a lot more work, too and wouldn't be able to use any standard widgets, I understand.


What are your standard widgets? Existing control subclasses? ContainerControls?


The mockups had used standard controls. I specifically avoided using anything else somehow thinking I could somehow make a class of each and load them as needed and I wanted to use each platform's controls instead of rolling my own.

Can I use DrawInto to draw widgets directly? That's something else I didn't know.

_________________
----
http://eduo.info/
http://gallery.eduo.info/
http://twitter.com/eduo/


Top
 Profile  
Reply with quote  
 Post subject: Re: Ideas on how to create task list
PostPosted: Mon Feb 22, 2010 8:44 pm 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
Location: Southern California
eduo wrote:
The mockups had used standard controls. I specifically avoided using anything else somehow thinking I could somehow make a class of each and load them as needed and I wanted to use each platform's controls instead of rolling my own.

Can I use DrawInto to draw widgets directly? That's something else I didn't know.


There are some instances where DrawInto doesn't work correctly, but yes, you are supposed to be able to draw a control to a Graphics object (Canvas or Picture) with DrawInto. However, this does not automatically handle interactivity for you. It can be good if you just want to display information in a custom Canvas. But if you want a user to be able to, say, click a popup and actually have it popup, you're out of luck because all you've done is draw a popup to a Graphics object, then put the drawing on screen.

Another possible avenue would be to...

* Have a ContainerControl subclass with all your controls for a single task.

* Create and embed instances of that subclass into one big ContainerControl on the Window.

* Fake scrolling by offsetting the Left / Top positions of the embedded ContainerControls.

You can pretty effectively fake a scrolling list of standard RB controls this way, and they remain fully interactive. The catch is that you cannot mark the Window composite on Mac OS X. If you do, your embedded controls will draw outside the master ContainerControl as you scroll. And even on non-composite Windows, some controls want to draw outside the boundary box of the master ContainerControl. Unfortunately ProgressBar happens to be one of them. You could probably work around this by having a Canvas subclass which, again, uses DrawInto to render a ProgressBar to screen. Once you take the drawing away from the framework, you probably would eliminate this issue (and ProgressBar is not interactive to begin with, so no loss there).

I've played with this technique, but not deployed anything with it, so I don't know if there are visual bugs on different OS versions or other stability problems. It seems to be pretty stable and visual artifact free on XP. Not sure about Vista or 7 because at the time I was researching this I didn't test on those.

While we're on the topic: you've hit upon one real weakness with the RB framework. It sucks for dynamically creating and managing controls at runtime.

A Window or ContainerControl should have two methods, AddControl and RemoveControl. It should be possible to create new instances of any control at runtime, and add/remove them using those methods. In addition, ContainerControls should directly support scrolling. That is you should be able to drop ScrollBars on a window and have them set properties in a ContainerControl, and the area within that ContainerControl should scroll in response. Of course no controls within the ContainerControl should ever be able to draw outside of the visible box of the ContainerControl. This should not be that hard. Both Mac OS and Windows support dynamic control creation and clip regions. I can't imagine Linux does not.

If that's how things worked, your task would be dead simple.

RB has always had a funky, hacked way of dealing with creation/destruction of controls at runtime. Neither control arrays nor ContainerControls are complete, simple, well designed solutions to the problem. I really, really wish they would fix this once and for all by employing the simple, obvious pattern I outlined above. Add two methods and two properties to ContainerControl, and modify it to work correctly as they are used.

_________________
Daniel L. Taylor
Custom Controls for Real Studio WE!
Visit: http://www.webcustomcontrols.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Ideas on how to create task list
PostPosted: Mon Feb 22, 2010 9:12 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
taylor-design wrote:
A Window or ContainerControl should have two methods, AddControl and RemoveControl. It should be possible to create new instances of any control at runtime, and add/remove them using those methods.


The issue is that you have no way to add event handlers to controls created this way.
Creating controls is easy, hooking them up to the rest of the framework that people expect to work isn't.
Controls created this way would have to take a delegate to handle all their events and that's very foreign to a lot of people.

That's why control arrays work. You have a spot to implement the event handlers.

Not saying it's impossible - it'd just be very foreign.

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: Ideas on how to create task list
PostPosted: Mon Feb 22, 2010 11:22 pm 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
Location: Southern California
npalardy wrote:
taylor-design wrote:
A Window or ContainerControl should have two methods, AddControl and RemoveControl. It should be possible to create new instances of any control at runtime, and add/remove them using those methods.


The issue is that you have no way to add event handlers to controls created this way.


Subclass and set the event handlers there.

Quote:
That's why control arrays work. You have a spot to implement the event handlers.


Control arrays don't work well for what eduo is trying to do. They don't work well or at all for many situations that call for dynamic control management. The pattern I described would solve these types of problems and be very easy to understand. Yes, in those cases you would have to create subclasses to implement your event handling. But if you're creating controls at runtime, those controls most likely have shared behavior that is best defined in a subclass any way.

At the very least RB should support scrolling and proper clipping of drawing operations in ContainerControls so problems like eduo's are simple to solve. Whatever eduo does, including exploring control arrays, he is going to have to work extra hard to simulate a scrolling environment that should be there for him.

_________________
Daniel L. Taylor
Custom Controls for Real Studio WE!
Visit: http://www.webcustomcontrols.com/


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group