r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!RebGUI] A lightweight alternative to VID

Awi
15-Jan-2011
[8897x3]
Here I found another bug with the text-list style. When your list 
is longer than the box (means you have to scroll), deleting the item 
at the bottom caused some calculation mismatch in redraw. This don't 
happen when you start deleting from the top. Here is the test case:
do %rebgui.r

display "test scroll panel" [
	tl-rute: text-list data [ "a"  "b"  "c"  "d"  "e"  "f"]
	button  red "-" [
		if tl-rute/selected [
			remove find tl-rute/data tl-rute/selected
			tl-rute/redraw
		]
	]
]
do-events
Delete "f", then delete other items, you will start to see "none" 
displayed in the list. This don't happen if you start by deleting 
other than "f" items.
GrahamC
15-Jan-2011
[8900]
usually there are methods to do this ..  certainly there is for table/remove-row 
n
Awi
15-Jan-2011
[8901x2]
RebDOC says nothing about deleting rows in text-list. Yes there is 
add-row and remove-row in table.
But the table in 2.x has the habit to prevent drawing text :-), that's 
why I moved my code to text-list, avoiding tables.
Awi
17-Jan-2011
[8903]
Ashley & Graham, just want to let you know that my reservation program 
using b218 is finished, and has been working perfectly. Many thanks 
for your work on RebGUI and all the support. Hopefully I can join 
the effort soon and give some work back to the community. (Currently 
I only have drop-list2 and text-list2, but both are incomplete and 
based on incomplete b218, so I think sharing them will do more confusion 
than help).
GrahamC
17-Jan-2011
[8904]
Maybe we should have moved RebGUI to github instead so people could 
fork and post their changes ... I guess we could still do so if Ashley 
restarts development.
Awi
17-Jan-2011
[8905]
Yes good idea, and if I'm not asking too much, just a small documentaion 
explaining the basic concept of 2x RebGUI, to get people (me) started. 
Currently my only reference is RebDOC and tour.r and diff-ing with 
117. For example I wanted to bring the b117 panel style (no border, 
silver background) back, I looked for some hours, and give up. Even 
some short points in this AltMe thread would be helpful. For example 
I found out how to do append-widget in 2.x through searching in google 
and found the chat history in altme.
GrahamC
17-Jan-2011
[8906]
Yeah ... the docs are in this channel for the tricky stuff.  But 
Ashley has assumed that R3 was going to quickly replace R2 hence 
the lack of movement here.
Awi
17-Jan-2011
[8907]
I also assumed that since like 2008 :-) Some things like this project 
cannot wait, and RebGUI and Rebol2 are more than good enough for 
almost every case in my project. And I think if Rebol3 and r3-gui 
are out someday, I'll just rewrite my apps.
GrahamC
17-Jan-2011
[8908]
Agreed.
Awi
6-Feb-2011
[8909x3]
Found another bug in b218: when using rate and feel, Ok button in 
alerts no longer working, the same with Yes/No buttons in confirm. 
Here is a code sample:
do %rebgui.r

display "rate feel test" [
	lbl: label "label with rate feel" 
		rate 1 
		feel [
			engage: func [f a e] [if a = 'time [print "awi"]]
		]
	btn "test alert" [alert "can you close me?"]
	btn "?" [? lbl]
	btn "unset lbl/rate" [lbl/rate: none show lbl]
	btn "set lbl/rate" [lbl/rate: 1 show lbl]
]
do-events
Nice thing is, when I turn off "rate", it works again, so currently 
I have a workaround, thanks God, I'm very close to shipping as I 
found this bug :-)
Basically what I'm doing is reading/monitoring a serial port using 
rate/feel. Since Rebol does not have a timer, the only thing I can 
think of is using rate/feel, which works very nicely as long as you 
don't "wait". "wait'" will kill your "thread" as the next timer event 
kicks again.
Awi
17-Feb-2011
[8912x4]
I just want to share my modifications of the chat widget in b177, 
I needed a slimmer chat. It should also fix the resize issue:
REBOL []
slim-chat: make baseface [
	options: {
		USAGE:

   chat2 120 data ["Bob" blue "My comment." yello 14-Apr-2007/10:58]

		DESCRIPTION:
			Three column chat display as found in IM apps such as AltME.
			Messages are appended, with those exceeding 'limit not shown.

		OPTIONS:

   [limit n] where n specifies number of messages to show (default 100)
			[id n] where n specifies id column width (default 10)
			[user n] where n specifies user column width (default 15)
			[date n] where n specifies date column width (default 25)
	}
	size: 200x100
	pane: []
	data: []
	edge: default-edge
	action: make default-action [
		on-resize: make function! [face] [

   poke face/pane/2/para/tabs 2 face/pane/1/size/x - sizes/slider - 
   (sizes/cell * any [select face/options 'date 25])
			face/redraw/no-show
		]
	]


 height: 0 ; actual pixel height of all messages (-1 ensures first 
 message is offset to hide it's edge
	rows: 0 ; number of messages
	limit: none ; last n messages to display

	append-message: make function! [
		user [string!]
		user-color [tuple! word! none!]
		msg [string!]
		msg-color [tuple! word! none!]
		date [date!]
		/no-show row
		/local p y t1 t2 t3
	] [
		;	cache current tab stops
		p: self
		t1: pick pane/2/para/tabs 1

  t2: pane/1/size/x - sizes/slider - (sizes/cell * any [select p/options 
  'date 25])

		p: self
		;	get height of message
		y: max sizes/line 4 + second size-text make baseface [
			size: as-pair p/size/x - sizes/slider + 1 10000
			text: msg
			font: default-font
			para: para-wrap
		]

		

		insert tail pane/1/pane reduce [
			make baseface [
				offset: as-pair -1 height - 1
				size: as-pair t2 21
				span: all [p/span find p/span #W #W]
				text: user
				edge: make default-edge [size: 0x1]

    font: make font-top [color: either word? user-color [get user-color] 
    [user-color] style: 'bold]
				color: either word? msg-color [get msg-color] [msg-color]
			]
			make baseface [
				offset: as-pair -1 height - 1 + 20
				size: as-pair p/size/x - sizes/slider + 1 y
				text: form msg
				color: either word? msg-color [get msg-color] [msg-color]
				edge: make default-edge [size: 0x1]
				font: default-font
				para: para-wrap
			]
			make baseface [
				offset: as-pair t2 - 1 height - 1

    size: as-pair (sizes/cell * any [select p/options 'date 25]) + sizes/slider 
    + 1 21
				span: all [p/span find p/span #W #X]

    text: form either now/date = date/date [date/time] [date/date]
				edge: make default-edge [size: 0x1]
				font: make font-top [style: 'bold align: 'right]
				color: either word? msg-color [get msg-color] [msg-color]
			]
		]
		height: height + y - 1 + 20
		if ((length? pane/1/pane) / 3) > limit [
			y: pane/1/pane/2/size/y + pane/1/pane/1/size/y - 2
			remove/part pane/1/pane 3
			foreach [u m d] pane/1/pane [
				u/offset/y: u/offset/y - y
				m/offset/y: m/offset/y - y
				d/offset/y: d/offset/y - y
			]
			height: height - y
		]
		unless no-show [
			insert tail data reduce [user user-color msg msg-color date]
			pane/1/size/y: height
			pane/3/ratio: pane/3/size/y / height
			show p
		]

  show pane/1 ; !!! this cleans up artifacts but "eats" other widgets 
  redraw events !!!
	]


 set-user-color: make function! [id [integer!] color [tuple! word! 
 none!] /local idx] [
		if any [zero? id id > rows] [exit]
		poke data id * 5 - 3 color
		if limit > (rows - id) [

   idx: either rows > limit [(id + limit - rows) * 3 - 2] [id * 3 - 
   2]

   pane/1/pane/:idx/font/color: either word? color [get color] [color]
			show pane/1/pane/:idx
		]
	]


 set-message-text: make function! [id [integer!] string [string!] 
 /local idx] [
		if any [zero? id id > rows] [exit]
		poke data id * 5 - 2 string
		if limit > (rows - id) [

   idx: either rows > limit [(id + limit - rows) * 3 - 1] [id * 3 - 
   1]
			insert clear pane/1/pane/:idx/text string
			redraw
		]
	]


 set-message-color: make function! [id [integer!] color [tuple! word! 
 none!] /local idx] [
		if any [zero? id id > rows] [exit]
		poke data id * 5 - 1 color
		if limit > (rows - id) [

   idx: either rows > limit [(id + limit - rows) * 3 - 1] [id * 3 - 
   1]
			pane/1/pane/:idx/color: either word? color [get color] [color]
			show pane/1/pane/:idx
		]
	]

	redraw: make function! [/no-show /local row] [
		clear pane/1/pane
		height: 0
		rows: (length? data) / 5
		row: max 0 rows - limit: any [select options 'limit 100]

  foreach [user user-color msg msg-color date] skip data row * 5 [

   append-message/no-show user user-color msg msg-color date row: row 
   + 1
		]
		pane/1/size/y: height
		pane/3/ratio: either zero? height [1] [pane/3/size/y / height]
		unless no-show [show self]
	]

	init: make function! [/local p] [
		unless options [options: copy []]
		p: self
		limit: any [select options 'limit 100]
		; chat pane (1)
		insert pane make baseface [
			offset: as-pair 0 sizes/line
			size: p/size - as-pair sizes/slider sizes/line
			span: all [p/span find p/span #W #W]
			pane: []
		]
		;	heading (2)
		insert tail pane make gradface [
			offset: -1x-1
			size: as-pair p/size/x sizes/line
			text: "Chat"
			span: all [p/span find p/span #W #W]
			font: make font-button [align: 'left]
			para: make default-para [tabs: [0 0]]
		]
		;	set header tabs

  poke pane/2/para/tabs 1 sizes/cell * (any [select options 'user 15])

  poke pane/2/para/tabs 2 size/x - sizes/slider - (sizes/cell * any 
  [select options 'date 25])
		;	vertical scroller
		insert tail pane make slider [
			offset: as-pair p/size/x - sizes/slider sizes/line - 2
			size: as-pair sizes/slider p/size/y - sizes/line + 2
			span: case [
				none? p/span [none]
				all [find p/span #H find p/span #W] [#XH]
				find p/span #H [#H]
				find p/span #W [#X]
			]
			action: make default-action [
				on-click: make function! [face] [
					if height > face/size/y [

      face/parent-face/pane/1/offset/y: (height - face/size/y * negate 
      face/data) + sizes/line
						show face/parent-face
					]
				]
			]
		]
		pane/3/init
		action/on-resize self
	]
]
And here is a screenshot: http://uploadpad.com/files/Chat.png
To use this, just save it as slim-chat in rebgui/widgets, and then 
do create-distribution.r. It's fully syntax-compatible with the existing 
chat widget.
I forgot, you will need to add #include %widgets/slim-chat.r in rebgui-widgets.r
GrahamC
17-Feb-2011
[8916]
indonesian?
Awi
17-Feb-2011
[8917]
yes :-)
Awi
25-Feb-2011
[8918x3]
another minor bug in rebgui, I just mentioned it here so it's not 
lost:
REBOL []

do %rebgui.r
counter: 0
muline: copy ""
display "button color not reset" [	
	btn "start timer" [
		if tgl/text = "wait" [wait 0]
		print "hi"
	]
	tgl: toggle data ["wait" "no-wait"]
]
do-events
when a button does some activities, in this case 'wait', the button's 
color changed to the pushed state, but never gets back to it's original 
color.
it's b218
Gabriele
21-Mar-2011
[8921]
calling WAIT inside a vid face action is not really supported by 
REBOL. In practice, there are cases where you may need to do this, 
but it is always a bit tricky.
Awi
21-Mar-2011
[8922x2]
Thanks for the information Gabriele, I've been using this inside 
vid face action to wait for a data from serial port. Until now I 
have not encountered any issue. But maybe I'm just lucky.
What I needed is actually only the timer action of a face to process 
an internal command queue, and while doing this I read some data 
from serial port. If rebol had a timer object, I don't need the face 
anymore. But afaik there is no timer in rebol, since it does not 
support multithreading yet, with exception of the face timer.
Gabriele
24-Mar-2011
[8924]
Timers are not really related to multithreading. If you only need 
a timer, you can just use WAIT with a time! or integer! value. Also, 
one way to work around problems that may happen when using WAIT inside 
a face action is to disable the event port, then WAIT, then enable 
it again. Eg, in your above code, replace the WAIT 0 with:

    saved: system/ports/wait-list
    system/ports/wait-list: []
    wait 0
    system/ports/wait-list: saved


It may be better though to add the serial port to the wait list and 
handle things differently - I can't say without knowing more about 
your program.
Awi
24-Mar-2011
[8925x2]
That solved this issue, thanks for the hint.
On the timer topic, I needed a recurring event that fires every second, 
where I can do some processing, without blocking the main thread 
while waiting until the next event. In .Net I can achieve that using 
a timer object.
GrahamC
16-Apr-2011
[8927x2]
Ashley, any suggestions on how to detect inactivity so that I can 
log a user out of the application?
Do I have to track every event?
Ashley
17-Apr-2011
[8929]
How about checking stats/evals periodically (accounting for the calls 
that this in itself generates)?
GrahamC
17-Apr-2011
[8930]
I'll give that a go ...
Henrik
3-May-2011
[8931]
is there a simple/proper way to resize a rebgui window?
Ashley
4-May-2011
[8932]
build#218:

display "test" [
	box red #HW
	return
	button #Y "resize" [
		var: face/parent-face
		var/size: 300x300
		show var
	]
]
Henrik
4-May-2011
[8933]
thanks
Henrik
13-Jul-2011
[8934]
I need to copy the entire state of a rebgui table for an undo system. 
Any idea how to do that? Deep copying the face object is far too 
slow, so I guess I need to access particuar values in the table that 
will then update the table properly when calling REDRAW.
Ashley
13-Jul-2011
[8935]
table/data
table/widths
table/aligns
Henrik
14-Jul-2011
[8936]
Thanks
Awi
22-Aug-2011
[8937x2]
build#218:
do %rebgui.r
display "test scroll panel" [

 mytable: table options ["id" left .2 "name" right .8  ] data [1 "A" 
 2 "B" 3 "C"] [alert "see me?"]
]
do-events
I tried to fix the bug that selecting the third row brings up an 
empty alert window (no text). I've played with face-iterator and 
table widget source code, but don't know where to look further. If 
anyone can give a hint I would really appreciate it.
Awi
23-Aug-2011
[8939x2]
I found the bug, it's in the rebgui-widgets.r -> face-iterator

    font: either 'left = aligns/:i [default-font] [make default-font 
    [align: aligns/:i]]
should be replaced with

    font: either 'left = aligns/:i [make default-font []] [make default-font 
    [align: aligns/:i]]

otherwise, selecting a line will change default-font/color to white, 
thus any widgets using default-font shown thereafter will appear 
blank
Ashley, if you give me access, I would be more than glad to submit 
the changes back to the repository (including some other widgets 
that I might have fixed along the way)
GrahamC
23-Aug-2011
[8941]
Awi ... I started that repository.  Join up and I'll see if I can 
grant you write access.
Awi
23-Aug-2011
[8942]
Ok, I already following the project in codeplex
GrahamC
23-Aug-2011
[8943]
Ok, made you a developer .. hope that works
GrahamC
26-Aug-2011
[8944]
Awi ... do you now have write access to the repo?
Awi
6-Sep-2011
[8945]
Sorry Graham, I was in vacation recently. Yes, now I have write access 
to the repo. I will need to clean up a bit before posting my changes 
though.
Robert
26-Sep-2011
[8946]
GrahamC "Are the RebGUI widgets being released?" - No, as our internal 
RebGUI is a fork long time ago and I think it developed quite far 
away from the official version of RebGUI. So, not sure if it's useful 
for others.