Forum: Ruby-Gnome 2 save window position

2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2011-02-26 15:13
(Received via mailing list)
How do I get window position?
I want to save/restore position of window so then
when I call my program again, it will display where it was closed

window.position always give me the same result, no matter where I move
the
form
perhaps because i set my window to run initially at center of screen

if you know, also restoring size also helpful
since I stuck with position
I don't feel like doing save/restore size
C4a836af7263f84a4f7cc91ed6f3ae77?d=identicon&s=25 Vincent Carmona (vinc-mai)
on 2011-02-27 01:14
(Received via mailing list)
2011/2/26 hendra kusuma <penguinroad@gmail.com>:
> I don't feel like doing save/restore size
>
> --
> Suka linux?
> Kunjungi blog saya http://penguinroad.blogspot.com
>

I do use Gtk::Window#position an d Gtk::Window#move to save and
restore position. Do you have a small example that is not working ?



--
Vincent Carmona
2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2011-02-27 02:42
(Received via mailing list)
> I do use Gtk::Window#position an d Gtk::Window#move to save and
> restore position. Do you have a small example that is not working ?
>
>
I know you use that from Zik source, that's why I don't understand the
reason it is not working with mine. Or perhaps because the ruby-gnome2
library I use? I use the one comes with my repository because I hate
compiling something

Too bad I don't have any small example, because I use some kind of
self-made
framework
to build gtk application, while it's make it easier for me, it also
includes
alot of files

I'll try to dig some more, meanwhile if you don't mind me asking
something
else
in Zik, how do you monitor song progress to update the label and
progress
bar?
7f28f9db46bfe8e9b8b5fcd90b2f1302?d=identicon&s=25 J. K. (j_k)
on 2011-02-27 05:42
hendra kusuma wrote in post #984167:

> ...how do you monitor song progress to update the label and
> progress bar?

hi hendra, jk here -

  in my simple player, the progress bar works like this:
#first, i create a progbar when i initialize the class
   @progBar = Gtk::ProgressBar.new
#then, in my "playTrack" method, i start a thread
   @prog = Thread.new{self.progress}
#my "progress" method looks like this (i use the gem mp3info for the
total duration at the moment - trying to get rid of that - and gst for
the rest

   def progress
   Mp3Info.open(@atBat){|data| @dur = data.length}
   while Gst::STATE_PLAYING
  q = Gst::QueryPosition.new(Gst::Format::TIME)
        @pipeline.query(q)
        pos = q.parse[1] / 1000000
  position = pos.to_f
  duration = @dur * 1000
  position = 1.0 if position < 1.0
  ratio = position/duration
  @progBar.fraction=(ratio)
  end
end #progress

#then i use these two methods to seek with the progress bar:

   def position=(position_in_ms)
  @pipeline.send_event(Gst::EventSeek.new(1.0,
  Gst::Format::Type::TIME,
  Gst::Seek::FLAG_FLUSH.to_i | Gst::Seek::FLAG_KEY_UNIT.to_i,
  Gst::Seek::TYPE_SET, position_in_ms * 1000000,
Gst::Seek::TYPE_NONE, -1))
   end

   def seekToPointer
  Mp3Info.open(@atBat){|data| @dur = data.length}
  pointer = @progBox.pointer[0]  ###
  width = (@progBox.window.size[0]) * 0.97
  pos = ((@dur * pointer) / width) * 1000
  self.position= pos
  self.position= pos
   end
### (@progBox is a Gtk::EventBox which the Gtk::Progress bar is inside,
@atBat is the current track file) ###

  in the more complex player, i use an image (the tone arm of the record
player) to show progress, so i wrote a custom "progress bar" rather than
use the Gtk::ProgressBar - but it works basically the same way.

  hope that helps some,

  have fun,

  j
2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2011-02-27 09:02
(Received via mailing list)
On Sun, Feb 27, 2011 at 12:42 PM, J. K.
<ruby-forum-incoming@andreas-s.net>wrote:

> rack" method, i start a thread
>   @prog = Thread.new{self.progress}
>

Thanks J.K.
I basically solve this issue by following method used in Zik player
by using Glib::Timeout instead of Thread
the rest is similar with yours

I nearly finish my player
I also implement the 2 playlist I write you about
Now the rest is handling playlist operations such as delete and add
multiple
files
should be easy enought if somehow tutorial of treeview over the net can
be
opened
C4a836af7263f84a4f7cc91ed6f3ae77?d=identicon&s=25 Vincent Carmona (vinc-mai)
on 2011-02-27 16:40
(Received via mailing list)
For the window position at what time do you call Gtk::Window#position
method ?
do you have try something like that ?
Gtk::Window#signal_connect("delete_event") {Gtk::Window#position}

Word of advice:
using Gtk methods and threads can be tricky. You should pay attention
at what you do that is why I have prefered Glib::Timeout.

--
Vincent Carmona
2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2011-02-28 06:54
(Received via mailing list)
On Sun, Feb 27, 2011 at 11:40 PM, Vincent Carmona
<vinc4mai@gmail.com>wrote:

> For the window position at what time do you call Gtk::Window#position
> method ?
> do you have try something like that ?
> Gtk::Window#signal_connect("delete_event") {Gtk::Window#position}
>


Yes, I put it there,
it gives me fixed value

if i have this line
set_window_position Gtk::Window::POS_CENTER
it return the posisiton center of screen
it I delete that line
it returns 0,0

is it library issue? or perhaps wm issue?
I'm using ubuntu 10.10 with openbox replacing metacity
I also use old ruby-gnome2 library since it comes with repository
C4a836af7263f84a4f7cc91ed6f3ae77?d=identicon&s=25 Vincent Carmona (vinc-mai)
on 2011-02-28 17:34
(Received via mailing list)
2011/2/28 hendra kusuma <penguinroad@gmail.com>:
>
> Yes, I put it there,
> it gives me fixed value
>
> if i have this line
> set_window_position Gtk::Window::POS_CENTER
> it return the posisiton center of screen
> it I delete that line
> it returns 0,0

Are you sure you call the position method on the top level gtk window
? Not on a gdk one.
You should really try to write a small code with just an empty window.
> ------------------------------------------------------------------------------
> https://lists.sourceforge.net/lists/listinfo/ruby-...
>
>



--
Vincent Carmona
2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2011-03-01 03:38
(Received via mailing list)
Attachment: test.zip (1 KB)
>
> Are you sure you call the position method on the top level gtk window
> ? Not on a gdk one.
> You should really try to write a small code with just an empty window.
> >
>
>
OK, here it is
the empty window
please see attachment

if you find something wrong please correct me
for most of code there created by my own code generator
that was made without firm understanding of GTK

Thanks
8616a8bf5c9ac0db67ac26f89d3b06b6?d=identicon&s=25 Mike Charlton (Guest)
on 2011-03-01 04:10
(Received via mailing list)
On 1 March 2011 11:36, hendra kusuma <penguinroad@gmail.com> wrote:
> if you find something wrong please correct me
> for most of code there created by my own code generator
> that was made without firm understanding of GTK

Looking at your code, it looks like a bug in ruby-gnome
to me.  It seems to be returning window_position from
the Window#position method.  I don't have the source
handy to check at the moment, though.

         MikeC
C4a836af7263f84a4f7cc91ed6f3ae77?d=identicon&s=25 Vincent Carmona (vinc-mai)
on 2011-03-01 05:05
(Received via mailing list)
2011/3/1 hendra kusuma <penguinroad@gmail.com>:
> OK, here it is
> the empty window
> please see attachment
>
> if you find something wrong please correct me
> for most of code there created by my own code generator
> that was made without firm understanding of GTK

As I said use
Gtk::Window#signal_connect("delete_event") {Gtk::Window#position}
and not
Gtk::Window#signal_connect("destroy") {Gtk::Window#position}

Calling methods on a destroyed object is not a good idea.

The code beneath should work.

w=Gtk::Window.new
w.signal_connect("delete_event") {w.position; false}
w.signal_connect("destroy") {Gtk.main_quit}

Check documentation for more infos on these signals.
>
> Thanks
>
> --
> Suka linux?
> Kunjungi blog saya http://penguinroad.blogspot.com
>
--
Vincent Carmona
2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2011-03-02 09:28
(Received via mailing list)
On Tue, Mar 1, 2011 at 12:04 PM, Vincent Carmona <vinc4mai@gmail.com>
wrote:

> Gtk::Window#signal_connect("delete_event") {Gtk::Window#position}
>
Wow, It really works
Thanks Vincent
I'll be sure to add this to my code generator so I won't forget next
time
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.