Questions re: programming with gtkbasic

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

Questions re: programming with gtkbasic

#1 Post by HairyWill »

I'm just getting to grips with gtkbasic building a small popup notification window that slides up from the bottom of the screen and have a few questions.

1) I would like to be able to pass parameters into my gtkbasic program, can anyone explain the syntax of how I read them in gtkbasic.

2) The window slides slowly up the screen 1 pixel at a time but as it slides onto the screen only the first 40 or so rows of pixels in the label are displayed. If I pop the window fully onscreen and then move it the display is fine. Once the window has reached its final position I can use gtk_widget_hide followed by gtk_widget_show to force a refresh, but executing this for every 1 pixel move causes flicker (unsurprisingly).

I have fixed this by doing hide then show once every 20 pixels but I wonder if there is a better way.

Code: Select all

#!/usr/bin/gtkbasic003
// uncomment these 2 lines, if you use localization and have those files!
//include "/tmp/en-Notify.mo"
//include "/tmp/Notify.mo"

HERE = xwin_getdir(command(2))
HERE &= "/resource" 
xwin_cd(HERE)

foo=xwin_system("xdpyinfo | grep dimensions |awk '{print $2}' | cut -f 1 -d 'x'")
width=foo[0]-5
foo=xwin_system("xdpyinfo | grep dimensions|awk '{print $2}' | cut -f 2 -d 'x'")
height=foo[0]-5

//-- load  file and show the window
gins_glade("project.glade")
gins_main()
gtk("gtk_widget_hide" ,  "window1" , 0 , 0 , 0 , 0 , 0)
gtk("gtk_label_set_label" ,  "label1" , "hello <b>world</b>. \n\nThis is a long string to force the widget to have a height greater than 34. This is a long string to force the widget to have a height greater than 34." , 0 , 0 , 0 , 0)
gdk_flush()
gtk("gtk_window_get_size" ,  "window1" , "&x" , "&y" , 0 , 0 , 0)
a = gtk_returnpointervalue("1")
b = gtk_returnpointervalue("2")

gtk("gtk_widget_show_now" ,  "window1" , 0 , 0 , 0 , 0 , 0)
counter = 0
'note that b is a string but you can do maths on it to get numeric output
final=b+1

//-- mainloop window slide with no eventhandling
while counter < final
  gtk("gtk_window_get_size" ,  "window1" , "&x" , "&y" , 0 , 0 , 0)
  a = gtk_returnpointervalue("1")
  b = gtk_returnpointervalue("2")
  gtk("gtk_window_move" ,  "window1" , (width-a), (height-counter) , 0 , 0 , 0)
  counter = counter + 1
  checkclose()
  gdk_flush()

'force the text to display, I don't understand why this is needed
  if counter/20 = int (counter/20) then
  gtk("gtk_widget_hide" ,  "window1" , 0 , 0 , 0 , 0 , 0)
  gtk("gtk_widget_show" ,  "window1" , 0 , 0 , 0 , 0 , 0)
end if

xwin_usleep(40000)
wend

'force the text to display, I don't understand why this is needed
gtk("gtk_widget_hide" ,  "window1" , 0 , 0 , 0 , 0 , 0)
gtk("gtk_widget_show" ,  "window1" , 0 , 0 , 0 , 0 , 0)

//-- mainloop display entire window with eventhandling
for i = 1 to 10000
  widget , event , pdata = gins_event()
  if widget != Nothing then
    print widget, event, pdata
    if event = "GDK_DELETE" then
      gins_exit()
      end
    end if

    if event = "GDK_BUTTON_RELEASE" then
      gins_exit()
      end
      print widget, event, pdata     
    end if
  end if
  xwin_usleep(2000)
next i

 //------------------------------------------------------------
// this function exits Basic, if the grafical interface closed
sub checkclose()
	a=gins_get("window1" , "name" , "<str>")
	if a = Nothing then
		print "window was closed, exiting..."
		gins_exit()
		end
	end if
end sub
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#2 Post by MU »

Notify.gtb

Code: Select all

#!/usr/bin/gtkbasic003 
//include "/usr/lib/wxbasicscript/basefunctions.inc"

HERE = xwin_getdir(command(2)) 
HERE &= "/resource" 
xwin_cd(HERE) 

//-- this needs basefunctions.inc from Puppybasic:
//args = argvtostring()
//if args = "" then
//	args = "no arguments passed!"
//end if

//-- this shows the first argument, no basefunctions.inc needed
arg1 = command(3)
if arg1 = "" then
	arg1 = "no arguments passed!"
end if
args = "argument 1: " & arg1

foo=xwin_screensize()
width=foo[0]-5 
height=foo[1]-5 

'print width , height

//-- load  file and show the window 
gins_glade("project.glade") 
gins_main() 

gtk("gtk_label_set_label" ,  "label1" , "hello <b>world</b>. \n\n" & args & "\n\nThis is a long string to force the widget to have a height greater than 34. This is a long string to force the widget to have a height greater than 34." , 0 , 0 , 0 , 0) 
gdk_flush() 
gtk("gtk_window_get_size" ,  "window1" , "&x" , "&y" , 0 , 0 , 0) 

w = gtk_returnpointervalue("1") 
h = gtk_returnpointervalue("2") 

gtk("gtk_widget_show" ,  "window1" , 0 , 0 , 0 , 0 , 0) 
counter = 0 
'note that b is a string but you can do maths on it to get numeric output 
final=h+1 

//-- mainloop window slide with no eventhandling 
while counter < final 

	gtk("gtk_window_move" ,  "window1" , (width-w) , (height-counter) , 0 , 0 , 0)
	gtk("gtk_widget_hide" ,  "label3" , 0 , 0 , 0 , 0 , 0)
	gtk("gtk_widget_show" ,  "label3" , 0 , 0 , 0 , 0 , 0)
	counter = counter + 1 
	gdk_flush() 
	'print width-a , height-counter

xwin_usleep(40000) 
wend 

//-- mainloop display entire window with eventhandling 
for i = 1 to 10000 
print i
  widget , event , pdata = gins_event() 
  if widget != Nothing then 
    'print widget, event, pdata 
    if event = "GDK_DELETE" then 
      gins_exit() 
      end 
    end if 

    if event = "GDK_BUTTON_RELEASE" then 
      gins_exit() 
      end 
      'print widget, event, pdata      
    end if 
  end if 
  xwin_usleep(2000) 
next i 

gins_exit() 
end 


 //------------------------------------------------------------ 
// this function exits Basic, if the grafical interface closed 
sub checkclose() 
   a=gins_get("window1" , "name" , "<str>") 
   if a = Nothing then 
      print "window was closed, exiting..." 
      gins_exit() 
      end 
   end if 
end sub
project.glade

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.0.3 on Fri Aug 22 18:24:20 2008 by root@puppypc-->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="type">GTK_WINDOW_POPUP</property>
    <property name="title" translatable="yes">GtkBasic</property>
    <property name="default_width">65</property>
    <property name="default_height">37</property>
    <child>
      <widget class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
        <child>
          <widget class="GtkHBox" id="hbox1">
            <property name="visible">True</property>
            <child>
              <widget class="GtkLabel" id="label1">
                <property name="visible">True</property>
                <property name="label" translatable="yes">label</property>
                <property name="use_markup">True</property>
              </widget>
            </child>
            <child>
              <widget class="GtkLabel" id="label3">
                <property name="width_request">1</property>
                <property name="visible">True</property>
              </widget>
              <packing>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <widget class="GtkButton" id="button1">
                <property name="visible">True</property>
                <property name="label" translatable="yes">ok</property>
              </widget>
              <packing>
                <property name="position">2</property>
              </packing>
            </child>
          </widget>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>
Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#3 Post by HairyWill »

thanks Mark,
Also, xwin_screensize() looks much more sensible than the the method I was using before. Is there a reference anywhere of all the xwin_ functions? Even just an undocumented list would be helpful.

I tweaked up what you posted a bit, mainly removed the button, you just click on the window to close it.
Notify.gtb

Code: Select all

#!/usr/bin/gtkbasic003

HERE = xwin_getdir(command(2))
HERE &= "/resource"
xwin_cd(HERE)

//-- this shows the first argument, no basefunctions.inc needed
arg1 = command(3)
if arg1 = "" then
   arg1 = "empty message!"
end if

foo=xwin_screensize()
width=foo[0]-5
height=foo[1]-5

'print width , height

//-- load  file and show the window
gins_glade("project.glade")
gins_main()

//-- hiding the window while changing the label allows get_size to return
//-- the corect new window size immediately
gtk("gtk_widget_hide" ,  "window1" , 0 , 0 , 0 , 0 , 0)
gtk("gtk_label_set_label" ,  "label1" , arg1 , 0 , 0 , 0 , 0)
gdk_flush()
gtk("gtk_window_get_size" ,  "window1" , "&x" , "&y" , 0 , 0 , 0)

w = gtk_returnpointervalue("1")
h = gtk_returnpointervalue("2")
gtk("gtk_widget_show" ,  "window1" , 0 , 0 , 0 , 0 , 0)
counter = 0
'note that b is a string but you can do maths on it to get numeric output
final=h+1

//-- loop window slide with no eventhandling
while counter < final

   gtk("gtk_window_move" ,  "window1" , (width-w) , (height-counter) , 0 , 0 , 0)
   gtk("gtk_widget_hide" ,  "label1" , 0 , 0 , 0 , 0 , 0)
   gtk("gtk_widget_show" ,  "label1" , 0 , 0 , 0 , 0 , 0)
   counter = counter + 1
   gdk_flush()
   'print width-a , height-counter

xwin_usleep(40000)
wend

//-- loop display entire window with eventhandling
for i = 1 to 10000
  widget , event , pdata = gins_event()
  if widget != Nothing then
    'print widget, event, pdata
    if event = "GDK_DELETE" then
      gins_exit()
      end
    end if

    if event = "GDK_BUTTON_RELEASE" then
      gins_exit()
      end    
    end if
  end if
  xwin_usleep(2000)
next i

gins_exit()
end


 //------------------------------------------------------------
// this function exits Basic, if the grafical interface closed
sub checkclose()
   a=gins_get("window1" , "name" , "<str>")
   if a = Nothing then
      print "window was closed, exiting..."
      gins_exit()
      end
   end if
end sub
project.glade

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="visible">True</property>
    <property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_PROPERTY_CHANGE_MASK</property>
    <property name="type">GTK_WINDOW_POPUP</property>
    <property name="title" translatable="yes">GtkBasic</property>
    <property name="type_hint">GDK_WINDOW_TYPE_HINT_NOTIFICATION</property>
    <child>
      <widget class="GtkFrame" id="frame1">
        <property name="visible">True</property>
        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
        <child>
          <widget class="GtkVBox" id="vbox1">
            <property name="visible">True</property>
            <child>
              <widget class="GtkLabel" id="label1">
                <property name="visible">True</property>
                <property name="label" translatable="yes"><b>hello</b>, here is the message I am to deliver</property>
                <property name="use_markup">True</property>
                <property name="wrap">True</property>
              </widget>
              <packing>
                <property name="position">1</property>
              </packing>
            </child>
          </widget>
        </child>
        
      </widget>
    </child>
  </widget>
</glade-interface>
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#4 Post by MU »

great! :)
I will add it to the demos of the next Gtkbasic release, many thanks!

The xwin_functions:
http://noforum.de/wxBasicscript-documen ... t/xwin.htm

Most are listed there, but not all.
This is the current list:
# grep wBuil xwin.c
void wBuiltin_xwin_getenv(){
void wBuiltin_xwin_getstringcontent(){
void wBuiltin_xwin_cd()
void wBuiltin_xwin_getdir()
void wBuiltin_xwin_usleep()
void wBuiltin_xwin_exec()
void wBuiltin_xwin_execnowait()
void wBuiltin_xwin_system2()
void wBuiltin_xwin_system()
void wBuiltin_xwin_searchpid()
void wBuiltin_xwin_createsimplewindow()
void wBuiltin_xwin_listwindows()
void wBuiltin_xwin_listicons()
void wBuiltin_xwin_listiconsofworkspace()
void wBuiltin_xwin_listiconids()
void wBuiltin_xwin_listiconidsofworkspace()
void wBuiltin_xwin_info()
void wBuiltin_xwin_classinfo()
void wBuiltin_xwin_iconify()
void wBuiltin_xwin_toggle_fullscreen()
void wBuiltin_xwin_activate()
void wBuiltin_xwin_move()
void wBuiltin_xwin_resize()
void wBuiltin_xwin_select()
void wBuiltin_xwin_multiselect()
void wBuiltin_xwin_select_1()
void wBuiltin_xwin_getmouseposition()
void wBuiltin_xwin_screensize()
void wBuiltin_xwin_getworkspace()
void wBuiltin_xwin_getworkspaces()
void wBuiltin_xwin_setworkspace()
void wBuiltin_xwin_movetoworkspace(){
void wBuiltin_xwin_titleandborder(){
void wBuiltin_xwin_hastitleandborder(){
void wBuiltin_xwin_notitlenoborder(){
void wBuiltin_xwin_setlayer(){
void wBuiltin_xwin_setwmstruts(){
#
The result is always a list.
Some do not work in every windowmanager, like those for the workspace.
In compiz, also important ones like listwindows() will not work.

If possible, use GTK functions instead.
xwin is much older than the GTK functions, and the GTK functions usually play better with windowmanagers.

The most important:
xwin_getenv("HOME")
will return "/root"
It displays environment variables.

xwin_system("ls")
returns a directory listing

xwin_exec("leafpad &")
runs leafpad in background.

I just updated my new editor, it now has examplecode for all GTK-functions:
http://www.murga-linux.com/puppy/viewto ... 497#226497

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#5 Post by HairyWill »

thanks Mark
I hope you don't mind me asking more. I must confess I have never tried the following in C so I may be getting it completely wrong.

I want to apply selective formatting to a TextView

Code: Select all

gins_glade("project.glade")
gins_main()
gtk( "gtk_text_view_get_buffer" , "textview1", 0 , 0 , 0 , 0 , 0 )
gtk_setobjectname("BUF")
myint = gtk( "gdk_color_parse"  , "red" , "&pointer" ,  0 ,  0 ,  0 ,  0 )
r1 = gtk_returnpointervalue("1")
gtk( "gtk_widget_modify_text"  , "textview1" , r1 , "&pointer" ,  0 ,  0 ,  0 )
r2 = gtk_returnpointervalue("2")
gtk( "gtk_text_buffer_create_tag"  , "BUF" , "my_tag" , "foreground" , "blue" ,  0 ,  0 )
gtk_setobjectname("TAG")

gtk( "gtk_text_buffer_set_text"  , "BUF" , "Hello there you monkey." , -1 ,  0 ,  0 ,  0 )
gtk( "gtk_text_buffer_get_iter_at_offset"  , "BUF" , "&pointer" , 4 ,  0 ,  0 ,  0 )
start1 = gtk_returnpointervalue("1")
gtk( "gtk_text_buffer_get_end_iter"  , "BUF" , "&pointer" , 0 ,  0 ,  0 ,  0 )
end1 = gtk_returnpointervalue("1")
gtk( "gtk_text_buffer_apply_tag"  , "BUF" , "TAG" , "start1" , "end1" ,  0 ,  0 )
this errors at gtk_text_buffer_create_tag

Code: Select all

(gtkbasic003:17882): GLib-GObject-WARNING **: IA__g_object_set_valist: object class `GtkTextTag' has no property named `U\x89\xe5WVS\x83\xec@\x8b}\u0008\xe8o\xce\xff\xff\x81ó\xcc'
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#6 Post by MU »

*hehe , when I've read your message, I thought:
Oh my god, why must Will start with Textviews?
I had so much trouble to write wrappers...
this certainly will be broken...

Then I googled, and found:
http://www.bravegnu.org/gtktext/x113.html

What you need, is:

Code: Select all

       gtk("gtk_text_buffer_create_tag", "buf1" ,"mycolor" , "foreground" , "#FF0000" , 0, 0)
        gtk("gtk_text_buffer_get_bounds","buf1" , "1" , "2" , 0, 0,0 )
        gtk("gtk_text_buffer_apply_tag_by_name", "buf1" , "mycolor" , "1" , "2" , 0, 0)
You can try this in the demo:
/usr/local/Gtkbasic-003/Demos/Textview/Textview.gtb

Code: Select all

      if widget = "button96" then

        gtk("gtk_text_buffer_get_selection_bounds","buf1" , "1" , "2" , 0, 0,0 )
        gtk("gtk_text_buffer_delete", "buf1" , "1" , "2" , "1", 0,0)
        gtk("gtk_text_buffer_place_cursor", "buf1" , "1" , 0 , 0, 0,0)
        gtk("gtk_text_buffer_insert_at_cursor", "buf1" , "test" , "4" , 0, 0,0)

//--------------- new: set a color:
        gtk("gtk_text_buffer_create_tag", "buf1" ,"mycolor" , "foreground" , "#FF0000" , 0, 0)
        gtk("gtk_text_buffer_get_bounds","buf1" , "1" , "2" , 0, 0,0 )
        gtk("gtk_text_buffer_apply_tag_by_name", "buf1" , "mycolor" , "1" , "2" , 0, 0)
      end if
I think it is important, to get a selection right before you aplply something.
You should not run other commands in between, as the selection is nothing "permanent".


Hey, this is great, I'm glad to have found someone, who shares small code-snippets :)
This will be good to enhance my simple demos.

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#7 Post by MU »

Here is an important issue with textbuffers, this can be a bad trap:

It was not possible, to use pointers.
They must be used different, this is an exception to other widgets.

You have 6 "iters" available.
They have fixed names, from "1" to "6".

This would use iter "1" and iter "2" to select everything:

Code: Select all

gtk("gtk_text_buffer_get_bounds","buf1" , "1" , "2" , 0, 0,0 )
This uses "3" (gets iter at position 10 in the text, and assigns it to iter "3"):

Code: Select all

gtk( "gtk_text_buffer_get_iter_at_offset"  , "buf1" , "3" , "10" ,  0 ,  0 ,  0 )
This uses "4" (gets iter at position 20 in the text, and assigns it to iter "4"):

Code: Select all

gtk( "gtk_text_buffer_get_iter_at_offset"  , "buf1" , "4" , "20" ,  0 ,  0 ,  0 )
This finally sets the color to red from char 10 to char 20:

Code: Select all

gtk("gtk_text_buffer_apply_tag_by_name", "buf1" , "mycolor" , "3" , "4" , 0, 0)
I defined 6 iters to be able to select positions in more than one buffer, so that you can for example copy from buffer1 to buffer2.

I must patch the code, that generates the Gtk-Functionslist in my editor, so that such exceptions are catched.

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#8 Post by MU »

will, your new notify demo flickers.
Please compare it with my last example.
I use a "label3" to hide/show in the loop.
It is empty and only 1 pixel wide, so you see no flickering.
But this is sufficient, to update the popup window, so that all text is visible.
It is sufficient to use it you every 10th time.

good idea, to put it in a frame, I missed that in an own popup before.
It is better readable :)

Notify.gtb

Code: Select all

#!/usr/bin/gtkbasic003 

HERE = xwin_getdir(command(2)) 
HERE &= "/resource" 
xwin_cd(HERE) 

//-- this shows the first argument, no basefunctions.inc needed 
arg1 = command(3) 
if arg1 = "" then 
   arg1 = "<b>empty message!</b>\nLine2" 
end if 

foo=xwin_screensize() 
width=foo[0]-5 
height=foo[1]-5 

'print width , height 

//-- load  file and show the window 
gins_glade("project.glade") 
gins_main() 

//-- hiding the window while changing the label allows get_size to return 
//-- the corect new window size immediately 
gtk("gtk_widget_hide" ,  "window1" , 0 , 0 , 0 , 0 , 0) 
gtk("gtk_label_set_label" ,  "label1" , arg1 , 0 , 0 , 0 , 0) 
gdk_flush() 
gtk("gtk_window_get_size" ,  "window1" , "&x" , "&y" , 0 , 0 , 0) 

w = gtk_returnpointervalue("1") 
h = gtk_returnpointervalue("2") 
gtk("gtk_widget_show" ,  "window1" , 0 , 0 , 0 , 0 , 0) 
counter = 0 
'note that b is a string but you can do maths on it to get numeric output 
final=h+1 

//-- loop window slide with no eventhandling 
uc=0
while counter < final 

   gtk("gtk_window_move" ,  "window1" , (width-w) , (height-counter) , 0 , 0 , 0) 
   uc +=1
   if uc=9 then

     gtk("gtk_widget_hide" ,  "label2" , 0 , 0 , 0 , 0 , 0) 
     gtk("gtk_widget_show" ,  "label2" , 0 , 0 , 0 , 0 , 0) 
     uc=0
    end if
     gdk_flush() 

   counter = counter + 1 
 
   'print width-a , height-counter 

xwin_usleep(40000) 
wend 

//-- loop display entire window with eventhandling 
for i = 1 to 10000 
  widget , event , pdata = gins_event() 
  if widget != Nothing then 
    'print widget, event, pdata 
    if event = "GDK_DELETE" then 
      gins_exit() 
      end 
    end if 

    if event = "GDK_BUTTON_RELEASE" then 
      gins_exit() 
      end    
    end if 
  end if 
  xwin_usleep(2000) 
next i 

gins_exit() 
end
project.glade

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.0.3 on Tue Aug 26 05:26:24 2008 by root@puppypc-->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="visible">True</property>
    <property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_PROPERTY_CHANGE_MASK</property>
    <property name="type">GTK_WINDOW_POPUP</property>
    <property name="title" translatable="yes">GtkBasic</property>
    <property name="type_hint">GDK_WINDOW_TYPE_HINT_NOTIFICATION</property>
    <child>
      <widget class="GtkFrame" id="frame1">
        <property name="visible">True</property>
        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
        <child>
          <widget class="GtkHBox" id="hbox1">
            <property name="visible">True</property>
            <child>
              <widget class="GtkLabel" id="label1">
                <property name="visible">True</property>
                <property name="label" translatable="yes"><b>hello</b>, here is the message I am to deliver</property>
                <property name="use_markup">True</property>
                <property name="wrap">True</property>
              </widget>
            </child>
            <child>
              <widget class="GtkLabel" id="label2">
                <property name="width_request">1</property>
                <property name="visible">True</property>
              </widget>
              <packing>
                <property name="expand">False</property>
                <property name="position">1</property>
              </packing>
            </child>
          </widget>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>
Last edited by MU on Tue 26 Aug 2008, 04:48, edited 3 times in total.
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#9 Post by HairyWill »

thanks again, I used this successfuly

Code: Select all

gtk( "gtk_text_view_get_buffer" , "textview1", 0 , 0 , 0 , 0 , 0 )
gtk_setobjectname("BUF")
gtk("gtk_text_buffer_create_tag", "BUF" ,"mycolor" , "foreground" , "green" , 0, 0)
gtk( "gtk_text_buffer_set_text"  , "BUF" , "Hello there you monkey." , -1 ,  0 ,  0 ,  0 )
gtk( "gtk_text_buffer_get_iter_at_offset"  , "BUF" , "123" , 6 ,  0 ,  0 ,  0 )
gtk( "gtk_text_buffer_get_iter_at_offset"  , "BUF" , "456" , 11 ,  0 ,  0 ,  0 )
gtk( "gtk_text_buffer_apply_tag_by_name"  , "BUF" , "mycolor" , "123" , "456" ,  0 ,  0 )
the most dificult part of this to understand was that the iterators for the bounds are given integer names ie 123 456. To be fair this is made clear in in the sample stub in StructureEd which specifes
gtk( "gtk_text_buffer_get_iter_at_offset" , "OBJECT" , "NUMBER" , "NUMBER" , 0 , 0 , 0 )
The first iterator seems to work with any string but the second must be a number. I suppose the loose variable typing also caught me as the NUMBER can be inside quotes or not.

In addition I am a little confused by this which successfully changes the text colour. Considering that I have commented out the returnpointervalue I presume that the colour pointer is pulled from the top of a list of pointers.

Code: Select all

myint = gtk( "gdk_color_parse"  , "red" , "junk" ,  0 ,  0 ,  0 ,  0 )
'r1 = gtk_returnpointervalue("1")
gtk( "gtk_widget_modify_text"  , "textview1" , "foo" , "bar",  0 ,  0 ,  0 )
I see you have made a couple more posts so I will continue.
Interesting that I can use 456 as an iter when you have only defined 1-6.

I see what you mean about label3, I didn't understand what it was doing there but now it makes sense.
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#10 Post by HairyWill »

Ok here is a small example which runs ldd on its first argument and displays the output formatted with colours. It is trivial but gives an illustration of using tags.

project.glade

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.0.3 on Fri Aug 29 02:14:54 2008 by root@puppypc-->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="visible">True</property>
    <property name="title" translatable="yes">gtb-ldd</property>
    <property name="default_width">65</property>
    <property name="default_height">37</property>
    <child>
      <widget class="GtkScrolledWindow" id="scrolledwindow1">
        <property name="visible">True</property>
        <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
        <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
        <child>
          <widget class="GtkTextView" id="textview1">
            <property name="visible">True</property>
          </widget>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>
ldd.gtb

Code: Select all

#!/usr/bin/gtkbasic003

includeenv "ENMO"
includeenv "INTMO"

HERE = xwin_getdir(command(2))
HERE &= "/resource" 
xwin_cd(HERE)

//-- this shows the first argument, no basefunctions.inc needed
arg1 = command(3)
if arg1 = "" then
   arg1 = "/bin/bash"
end if
//store output from ldd
xwin_system("ldd " & arg1 & " > /tmp/ldd-output")

//-- load  file and show the window
gins_glade("project.glade")
gins_main()
gtk( "gtk_window_resize"  , "window1" , 600 , 200 ,  0 ,  0 ,  0 )
gdk_flush()

//get the text buffer and set all the text to black
gtk( "gtk_text_view_get_buffer" , "textview1", 0 , 0 , 0 , 0 , 0 )
gtk_setobjectname("buf1")
myint = gtk( "gdk_color_parse"  , "black" , 0 ,  0 ,  0 ,  0 ,  0 )
r1 = gtk_returnpointervalue("1")

//create tags
gtk("gtk_text_buffer_create_tag", "buf1" ,"tag1" , "foreground" , "gray" , 0, 0 )
gtk("gtk_text_buffer_create_tag", "buf1" ,"tag2" , "font" , "14" , 0, 0 )
gtk("gtk_text_buffer_create_tag", "buf1" ,"tag3" , "foreground" , "blue" , 0, 0 )
gtk("gtk_text_buffer_create_tag", "buf1" ,"tag4" , "foreground" , "green" , 0, 0 )
gtk("gtk_text_buffer_create_tag", "buf1" ,"tag5" , "foreground" , "red" , 0, 0 )

//read in the output from ldd that was stored earlier
handle = fopen("/tmp/ldd-output","r")
n=0
while not eof(handle)

text=ltrim(fgets(handle))

//find the important points in the string
point1 = instr(text,"=") - 1
point2 = point1 + 2
if (point1<0) then
point1 = 0
point2 = 0
end if
point3=instr(text,"(") -1

//the ones and twos below are iterators that point to locations in the textbuffer
//only two iterators are used but their values are changed alternately
//as we walk along the line selecting sections of text
gtk( "gtk_text_buffer_get_end_iter"  , "buf1", 1 ,  0 ,  0 ,  0 ,  0 )
gtk( "gtk_text_buffer_insert"  , "buf1" , 1 , (text&"\n") , -1 ,  0 ,  0 )
gtk( "gtk_text_buffer_get_iter_at_line"  , "buf1" , 1 , n ,  0 ,  0 ,  0 )
gtk( "gtk_text_buffer_get_iter_at_line_offset"  , "buf1" , 2 , n ,  point1 ,  0 ,  0 )
gtk( "gtk_text_buffer_apply_tag_by_name"  , "buf1" , "tag5" , 1 , 2 ,  0 ,  0 )
gtk( "gtk_text_buffer_apply_tag_by_name"  , "buf1" , "tag2" , 1 , 2 ,  0 ,  0 )
gtk( "gtk_text_buffer_get_iter_at_line_offset"  , "buf1" , 1 , n ,  point2 ,  0 ,  0 )
gtk( "gtk_text_buffer_apply_tag_by_name"  , "buf1" , "tag1" , 2 , 1 ,  0 ,  0 )
gtk( "gtk_text_buffer_get_iter_at_line_offset"  , "buf1" , 2 , n ,  point3 ,  0 ,  0 )
gtk( "gtk_text_buffer_apply_tag_by_name"  , "buf1" , "tag4" , 1 , 2 ,  0 ,  0 )
gtk( "gtk_text_buffer_get_end_iter"  , "buf1", 1 ,  0 ,  0 ,  0 ,  0 )
gtk( "gtk_text_buffer_apply_tag_by_name"  , "buf1" , "tag3" , 2 , 1 ,  0 ,  0 )
n=n+1
end while
fclose(handle)

//-- mainloop with eventhandling
while 1
  checkclose()
  widget , event , pdata = gins_event()

  if widget != Nothing then
    'print widget, event, pdata

    if event = "GDK_DELETE" then
      gins_exit()
      end
    end if
  end if
  xwin_usleep(2000)
wend
sub checkclose()
	a=gins_get("window1" , "name" , "<str>")
	if a = Nothing then
		print "window was closed, exiting..."
		gins_exit()
		end
	end if
end sub
I am now working on converting the psip interface to gtkbasic. I have all the buttons and have integrated a colour formatted chatlog viewer. The next task is to get the buddies list working. This uses a tree in gtkdialog. I would like to have multiple columns of name,status-icon...

Do trees work in gtkbasic or would it be more sensible to follow the clist examples?
Last edited by HairyWill on Fri 29 Aug 2008, 08:31, edited 1 time in total.
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#11 Post by Lobster »

The next task is to get the buddies list working.
Have added enhanced buddies list to main wiki here
May be of use :)
http://www.puppylinux.org/node/2535
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#12 Post by MU »

I have not used the tree widget yet, so I have no idea, how far it is usable.
Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#13 Post by HairyWill »

I'm stuck and I can't find an example

I would like to create a multi-columned list that can contain icons and text.
I need to be able to query the list to find out which row is selected and then retrieve the text from a particular row in the column.

I don't need it but I wonder if multiple selection is possible.

I have tried this which does not work, I presume this is why you have the custom constructor
dim titles[1]
titles[0]="eee"
titles[1]="qqqq"
gtk( "gtk_clist_new_with_titles" , 2 , titles , 0 , 0 , 0 , 0 )
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#14 Post by MU »

ehm yes, clists are difficult to handle.
I could modify my constructor to use more colums, but I have no time before thursday.
So maybe next weekend, but I cannot promise :roll:

It would be better to use treeviews though, as clists will be removed from Gtk 3 in 2009/2010 :cry:

But as I said, no idea, if they work.
It might be worth to try Freebasic instead.
I think it has better Gtk wrappers, so for more complex projects it is the better choice.

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

John Doe
Posts: 1681
Joined: Mon 01 Aug 2005, 04:46
Location: Michigan, US

#15 Post by John Doe »

if anyone has a moment (and if it's possible), can someone please tell me how to add mouse over text to '"code" like this' using gtkdialog?

Code: Select all

<text>
<label>my text</label>
</text>

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#16 Post by MU »

Will: clists with multiple columns:
http://murga-linux.com/puppy/viewtopic. ... 525#228525

John:

I'd suggest, to start a new thread.
This thread here will become very confusing, if GtkBasic and Gtkdialog code is mixed. Both are very different.

Thanks, Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

Post Reply