Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 31 Jul 2014, 13:48
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
Questions re: programming with gtkbasic
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [16 Posts]   Goto page: 1, 2 Next
Author Message
HairyWill


Joined: 26 May 2006
Posts: 2949
Location: Southampton, UK

PostPosted: Fri 22 Aug 2008, 10:59    Post subject:  Questions re: programming with gtkbasic  

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:
#!/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: community website, screenshots, puplets, wiki, rss
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Fri 22 Aug 2008, 12:32    Post subject:  

Notify.gtb

Code:
#!/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:
<?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

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
HairyWill


Joined: 26 May 2006
Posts: 2949
Location: Southampton, UK

PostPosted: Sat 23 Aug 2008, 15:31    Post subject:  

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:
#!/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:
<?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">&lt;b&gt;hello&lt;/b&gt;, 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: community website, screenshots, puplets, wiki, rss
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sun 24 Aug 2008, 01:13    Post subject:  

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

The xwin_functions:
http://noforum.de/wxBasicscript-documentation/wxbasicscript/xwin.htm

Most are listed there, but not all.
This is the current list:
Quote:
# 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/viewtopic.php?p=226497#226497

Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
HairyWill


Joined: 26 May 2006
Posts: 2949
Location: Southampton, UK

PostPosted: Mon 25 Aug 2008, 17:57    Post subject:  

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:
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:
(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: community website, screenshots, puplets, wiki, rss
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 25 Aug 2008, 22:30    Post subject:  

*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:
       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:
      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 Smile
This will be good to enhance my simple demos.

Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 25 Aug 2008, 22:52    Post subject:  

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:
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:
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:
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:
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

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 25 Aug 2008, 23:30    Post subject:  

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 Smile

Notify.gtb
Code:
#!/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:
<?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">&lt;b&gt;hello&lt;/b&gt;, 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>

_________________
my recommended links

Last edited by MU on Tue 26 Aug 2008, 00:48; edited 3 times in total
Back to top
View user's profile Send private message Visit poster's website 
HairyWill


Joined: 26 May 2006
Posts: 2949
Location: Southampton, UK

PostPosted: Tue 26 Aug 2008, 00:05    Post subject:  

thanks again, I used this successfuly
Code:
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:
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: community website, screenshots, puplets, wiki, rss
Back to top
View user's profile Send private message 
HairyWill


Joined: 26 May 2006
Posts: 2949
Location: Southampton, UK

PostPosted: Thu 28 Aug 2008, 22:40    Post subject:  

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:
<?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:
#!/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?

_________________
Will
contribute: community website, screenshots, puplets, wiki, rss

Last edited by HairyWill on Fri 29 Aug 2008, 04:31; edited 1 time in total
Back to top
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Fri 29 Aug 2008, 02:40    Post subject:  

Quote:
The next task is to get the buddies list working.


Have added enhanced buddies list to main wiki here
May be of use Smile
http://www.puppylinux.org/node/2535

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Fri 29 Aug 2008, 06:37    Post subject:  

I have not used the tree widget yet, so I have no idea, how far it is usable.
Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
HairyWill


Joined: 26 May 2006
Posts: 2949
Location: Southampton, UK

PostPosted: Sat 30 Aug 2008, 00:27    Post subject:  

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: community website, screenshots, puplets, wiki, rss
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sun 31 Aug 2008, 02:31    Post subject:  

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 Rolling Eyes

It would be better to use treeviews though, as clists will be removed from Gtk 3 in 2009/2010 Crying or Very sad

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

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
John Doe

Joined: 01 Aug 2005
Posts: 1689
Location: Michigan, US

PostPosted: Sun 31 Aug 2008, 02:50    Post subject:  

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:
<text>
<label>my text</label>
</text>
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [16 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

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
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1920s ][ Queries: 12 (0.0052s) ][ GZIP on ]