X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 08 Jun 2015 08:40 AM by  anon
two bugs in WIDGET_WINDOW
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:2
New Member


--
08 Jun 2015 08:40 AM
    I've encountered two problems with WIDGET_WINDOW that I've been unable to find a solution for, and they seem to be the result of a bug. One is that when using the SYMBOL function, the graphics do not appear until after there is a mouse click within the window; all other graphic functions that I've tried so far appear right away. The other problem is that when using the SAVE method with the window to write a PDF file, the output is blank , but appears normal if this is done within a widget_event handler.Neither of these problems occur when the WINDOW function is used instead. The following program demonstrates both problems, using an example adapted from the documentation for SYMBOL: ;------------------------------------------------ pro demo_widget_window_event,event help,/str,event WIDGET_CONTROL,event.top,GET_UVALUE=owin oWin.Save, 'demo_widget_window_2.pdf', BITMAP=0 ;this PDF is fine if (TAG_NAMES(Event, /STRUCTURE_NAME) EQ 'WIDGET_KILL_REQUEST') then begin WIDGET_CONTROL,event.top,/DESTROY if obj_valid(owin) then begin obj_destroy,owin ;alternative: ;wclass=obj_class(owin) ;if wclass EQ 'GRAPHICSWIN' || wclass EQ 'GRAPHICSBUFFER' then owin.close endif endif RETURN END ;pro demo_widget_window ;or run as a MAIN program: pagename='demo_widget_window' keyboard_event=0 opengl=1 ;both options give same result widget_top=WIDGET_BASE(TITLE=pagename,SPACE=0,YPAD=0,XPAD=0,/COL,$ /TLB_KILL_REQUEST_EVENTS ,TLB_SIZE_EVENTS=1 ,$ KBRD_FOCUS_EVENTS=keyboard_event) ;MBAR=menubase) ;in most cases, creating a menu bar is the reason for using widget_window,$ ;as well as customized handling of widget events top_base=widget_top winbase=WIDGET_BASE(widget_top) xsize=900 ysize=800 ;create main draw base/widget dbase=WIDGET_BASE(winbase,XOFFSET=0,YOFFSET=0) wWindow=WIDGET_WINDOW(dbase,$ XSIZE=xsize,YSIZE=ysize,FRAME=0,$ RENDERER=(OpenGL EQ 0)) WIDGET_CONTROL,widget_top,/REALIZE ;do before getting owin property WIDGET_CONTROL,wWindow,GET_VALUE=oWin oWin.Select WIDGET_CONTROL,widget_top,SET_UVALUE=owin ;does not matter if XMANAGER call is here, or farther down ; XMANAGER,'demo_widget_window',widget_top,NO_BLOCK=1 m = MAP('Orthographic', COLOR='light blue', $ CURRENT=oWin, $ ;POSITION=[x0, y0, x1, y1], $ NORMAL coord. assumed LIMIT=[30, -120, 50, -90], $ CENTER_LONGITUDE=-105, CENTER_LATITUDE=40) c = MAPCONTINENTS(/USA) m.mapgrid.ORDER, /SEND_TO_BACK lon = [-104.98,-104.80,-111.88,-116.22,-112.03, $ -119.75,-100.78,-100.34,-96.68,-95.69, $ -97.54,-97.53,-105.97,-112.07] lat = [39.74,41.87,40.75,43.61,46.60, $ 39.16,46.82,44.37,40.81,39.06, $ 35.48,30.27,35.67,33.45] labels = ['CO','WY','UT','ID','MT','NV','ND', $ 'SD','NE','KS','OK','TX','NM','AZ'] capitals = SYMBOL( lon, lat, 'Star', /DATA, $ /SYM_FILLED, SYM_COLOR='red', SYM_SIZE = 2, $ LABEL_STRING=labels ) oWin.refresh XMANAGER,'demo_widget_window',widget_top,NO_BLOCK=1 oWin.Save, 'demo_widget_window_1.pdf', BITMAP=0 ;for whatevern reason, this PDF is blank end

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    08 Jun 2015 02:19 PM
    Hi Daniel, After some testing it looks like the two bugs are related. The widget window does not refresh in time which means that when the PDF is saved then it is blank. This also keeps the symbols for the capitols in your example to only appear when the focus is directed to the widget window even if they are set as the front item in the window. I went ahead and created a new bug report for you and I created an example for how to get this to work with a widget window. It's not as much of a workaround as a simple code re-write with a button to draw the maps, which ensures that the focus is where it needs to be. I hope this helps! pro demo_widget_window_event,event if event.select then begin WIDGET_CONTROL, event.top, GET_UVALUE = owin ;clear the window of all current plots then plot our map owin.window.erase owin.window.setcurrent owin.window.refresh,/disable m = MAP('Orthographic', COLOR='light blue', $ LIMIT=[30, -120, 50, -90], $ CENTER_LONGITUDE=-105, CENTER_LATITUDE=40,/current,$ fill_color = 0, /widget) c = MAPCONTINENTS(/USA,fill_background = 0) m.mapgrid.ORDER, /SEND_TO_BACK lon = [-104.98,-104.80,-111.88,-116.22,-112.03, $ -119.75,-100.78,-100.34,-96.68,-95.69, $ -97.54,-97.53,-105.97,-112.07] lat = [39.74,41.87,40.75,43.61,46.60, $ 39.16,46.82,44.37,40.81,39.06, $ 35.48,30.27,35.67,33.45] labels = ['CO','WY','UT','ID','MT','NV','ND', $ 'SD','NE','KS','OK','TX','NM','AZ'] capitals = SYMBOL( lon, lat, 'Circle', $ /SYM_FILLED, SYM_COLOR='red', SYM_SIZE = 2, $ LABEL_STRING=labels, /data ) capitals.order,BRING_TO_FRONT =1 owin.window.refresh ;save window after we refresh it oWin.Save, 'demo_widget_window_1.pdf', BITMAP=0 endif END pro demo_widget_window ireset, /no_prompt ;create main draw base/widget dbase=WIDGET_BASE(/column, XOFFSET=0,YOFFSET=0) ;create a simple draw button button = WIDGET_BUTTON(dbase,value = 'DRAW') ;create out draw window wWindow=WIDGET_WINDOW(dbase,XSIZE=900,YSIZE=800) WIDGET_CONTROL,dbase,/REALIZE ;get the ID of the draw window WIDGET_CONTROL,wWindow,GET_VALUE=oWin ;save the draw window in the UVALUE of the base widget WIDGET_CONTROL, dbase, SET_UVALUE = oWin XMANAGER,'demo_widget_window',dbase,NO_BLOCK=1 end

    Deleted User



    New Member


    Posts:2
    New Member


    --
    08 Jun 2015 03:59 PM
    Hi Zach, Thanks for confirming that there seems to be a bug. Is there a way to "ensure that the focus is where it needs to be" through use of widget_control, rather than adding a widget button for this? I had tried using widget_control myself, in various ways, but without success. Or could a delay be added so that the window refresh completes?

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    10 Jun 2015 08:10 AM
    Daniel, I had not thought of using widget control and I figured out a way to use it to get the screen to draw everything! I make two calls to widget_control, one to get the draw view and one to set the draw view to the exact same variable. This causes the widget_window to refresh and display the symbols properly. unfortunately I could not get the widget to save the pdf properly. This is where the bug comes in because it seems like it is jumping the gun on saving the window before anything is actually present in the window. I added a button for saving which will save the plot as a PDF for you. Here is the new example code that worked for me. I hope this helps! pro demo_widget_window_event,event if event.select then begin WIDGET_CONTROL, event.top, GET_UVALUE = owin oWin.Save, 'demo_widget_window_1.pdf', BITMAP=0 endif END pro demo_widget_window ireset, /no_prompt ;create main draw base/widget dbase=WIDGET_BASE(/column, XOFFSET=0,YOFFSET=0) ;create w widget button for saving the image button = WIDGET_BUTTON(dbase,value = 'SAVE') ;create a draw window wWindow=WIDGET_WINDOW(dbase,XSIZE=900,YSIZE=800) ;relize the widget WIDGET_CONTROL,dbase,/REALIZE ;get the ID of the draw window WIDGET_CONTROL,wWindow,GET_VALUE=oWin owin.window.setcurrent owin.refresh, /disable m = MAP('Orthographic', COLOR='light blue', $ LIMIT=[30, -120, 50, -90], $ CENTER_LONGITUDE=-105, CENTER_LATITUDE=40,/current,$ fill_color = 0, /widget) c = MAPCONTINENTS(/USA,fill_background = 0) m.mapgrid.ORDER, /SEND_TO_BACK lon = [-104.98,-104.80,-111.88,-116.22,-112.03, $ -119.75,-100.78,-100.34,-96.68,-95.69, $ -97.54,-97.53,-105.97,-112.07] lat = [39.74,41.87,40.75,43.61,46.60, $ 39.16,46.82,44.37,40.81,39.06, $ 35.48,30.27,35.67,33.45] labels = ['CO','WY','UT','ID','MT','NV','ND', $ 'SD','NE','KS','OK','TX','NM','AZ'] capitals = SYMBOL( lon, lat, 'Star', $ /SYM_FILLED, SYM_COLOR='red', SYM_SIZE = 2, $ LABEL_STRING=labels, /data ) capitals.order,BRING_TO_FRONT =1 owin.refresh ;line to get the widget window to draw symbols widget_control, wWindow, SET_DRAW_VIEW = [0,0] ;save the window widget ID in the base widget WIDGET_CONTROL, dbase, SET_UVALUE = oWin XMANAGER,'demo_widget_window',dbase,NO_BLOCK=1 end
    You are not authorized to post a reply.