From alex at pressure.to Wed Jul 1 11:30:41 2009 From: alex at pressure.to (Alex Fenton) Date: Wed, 01 Jul 2009 16:30:41 +0100 Subject: [wxruby-users] LoadError: No such file to load -- wx In-Reply-To: <22bcbef23a9f10732ad74b769c812f4c@ruby-forum.com> References: <22bcbef23a9f10732ad74b769c812f4c@ruby-forum.com> Message-ID: <4A4B8121.4070704@pressure.to> Michael Satterwhite wrote: > I have a program written with wxruby. If I try to execute it with > > timeclock.rb > > I get the error "`gem_original_require': no such file to load -- wx > (LoadError)" > > If I run it with > > ruby timeclock.rb > > it runs correctly. I *AM* aware of the need to load rubygems. Therefore > in my program, I have the explicit statements: > > require 'rubygems' > require 'wx' > > As a result, I'm not sure what could be the problem. Can anyone offer > any help? Do you have multiple different versions of Ruby installed on your system, one with wxRuby installed, and one without? Perhaps the ruby being used when you invoke it the first way (timeclock.rb) isn't the same as the ruby in PATH - what's the shebang line? alex From lists at ruby-forum.com Thu Jul 2 12:41:27 2009 From: lists at ruby-forum.com (Dimas Cyriaco) Date: Thu, 2 Jul 2009 18:41:27 +0200 Subject: [wxruby-users] MouseEvent#dragging Message-ID: <6f8b268773cd286b565fdf27c1ee8f8b@ruby-forum.com> I'm trying to use the dragging method of the MouseEvent, but with no success. Here is the code: require 'rubygems' require 'wx' include Wx class MyApp < App def on_init @frame = Frame.new(nil,-1, "Wx", DEFAULT_POSITION, Size.new(200,200)) evt_left_down() { | event | drag(event)} @frame.show end def drag(event) puts event.dragging end end app = MyApp.new.main_loop I always return false, even when i'm draging the mouse. I don't know what is wrong. Any help? Thanks -- Posted via http://www.ruby-forum.com/. From alex at pressure.to Sun Jul 5 13:15:15 2009 From: alex at pressure.to (Alex Fenton) Date: Sun, 05 Jul 2009 18:15:15 +0100 Subject: [wxruby-users] MouseEvent#dragging In-Reply-To: <6f8b268773cd286b565fdf27c1ee8f8b@ruby-forum.com> References: <6f8b268773cd286b565fdf27c1ee8f8b@ruby-forum.com> Message-ID: <4A50DFA3.7040207@pressure.to> Dimas Cyriaco wrote: > I'm trying to use the dragging method of the MouseEvent, but with no > success. > Here is the code: > > require 'rubygems' > require 'wx' > include Wx > > class MyApp < App > def on_init > @frame = Frame.new(nil,-1, "Wx", DEFAULT_POSITION, > Size.new(200,200)) > > evt_left_down() { | event | drag(event)} > > @frame.show > end > > def drag(event) > puts event.dragging > end > end > > app = MyApp.new.main_loop > > I always return false, even when i'm draging the mouse. I think it is because the event that you are capturing is evt_left_down - which happens as the mouse button is pressed. Dragging implies motion, so it it's not relevant. I would try capturing evt_motion and see if it works as you expect there. a From lists at ruby-forum.com Sun Jul 12 17:58:54 2009 From: lists at ruby-forum.com (Zhimin Zhan) Date: Sun, 12 Jul 2009 23:58:54 +0200 Subject: [wxruby-users] wxWebConnect - Web Browser Control Library for wxWidgets Message-ID: wxWebConnect Project - Web Browser Control Library for wxWidgets http://www.kirix.com/labs/wxwebconnect.html Found it from wxWidgets home page, downloaded the sample app, and impressed. Zhimin -- Posted via http://www.ruby-forum.com/. From alex at pressure.to Mon Jul 13 07:32:13 2009 From: alex at pressure.to (Alex Fenton) Date: Mon, 13 Jul 2009 12:32:13 +0100 Subject: [wxruby-users] form to save and load image to/from database In-Reply-To: <26dadb3d0907130049w25986f25k978ea0dedc1852dc@mail.gmail.com> References: <26dadb3d0907130049w25986f25k978ea0dedc1852dc@mail.gmail.com> Message-ID: <4A5B1B3D.7090809@pressure.to> hendra kusuma wrote: > I'm trying to save a bitmap into Postgresql > using wxruby as front end (you see, wxFilePickerCtrl, and wxStaticBitmap) > and bitmap is displayed on wxStaticBitmap after selecting file with > wxFilePickerCtrl > and saved into db with pressing save button > I'm using Ruby DBI to connect to database Use Wx::Image.read and Wx::Image#write plus ruby's in-built StringIO class to have image data in a recognised format (eg PNG, JPG) in a ruby string variable: img_str = StringIO.new('') wx_img.write(img_str, Wx::BITMAP_TYPE_PNG) # img_str now contains image data and can be saved to the database, probably in a BLOB column # row has been retrieved from the database, and column [2] contains the image data img_str = StringIO.new(column[2]) wx_img = Wx::Image.read(img_str, Wx::BITMAP_TYPE_PNG) Note that unlike normal file-based constructors for Wx::Image, the type declarations are mandatory for write and read, because the image file format can't be inferred from the file suffix. I don't know the exact DBI syntax, and the column type declaration needed for PostgreSQL but I expect you can figure this out. hth a From alex at pressure.to Mon Jul 13 07:42:46 2009 From: alex at pressure.to (Alex Fenton) Date: Mon, 13 Jul 2009 12:42:46 +0100 Subject: [wxruby-users] wxWebConnect - Web Browser Control Library for wxWidgets In-Reply-To: References: Message-ID: <4A5B1DB6.4030300@pressure.to> Zhimin Zhan wrote: > wxWebConnect Project - Web Browser Control Library for wxWidgets > http://www.kirix.com/labs/wxwebconnect.html > > Found it from wxWidgets home page, downloaded the sample app, and > impressed. Thanks for the link, I hadn't seen this. Kirix are the people who donated the AUI classes to the wxWidgets project so they have a history of significant contributions. I couldn't get the sample app to work but looking at the source it looks to be a really comprehensive wrapping of Gecko - it exposes a lot of internal classes eg for the DOM as well as the front-end browser component class. I looked into porting wxWebKit to Ruby a few months ago, but I couldn't even get it to compile from HEAD, so maybe this will offer a decent browser component for wxRuby. a From alex at pressure.to Tue Jul 14 03:42:39 2009 From: alex at pressure.to (Alex Fenton) Date: Tue, 14 Jul 2009 08:42:39 +0100 Subject: [wxruby-users] form to save and load image to/from database In-Reply-To: <26dadb3d0907132200p63bda1d7n5c2fc2af280ad8f6@mail.gmail.com> References: <26dadb3d0907130049w25986f25k978ea0dedc1852dc@mail.gmail.com> <4A5B1B3D.7090809@pressure.to> <26dadb3d0907132200p63bda1d7n5c2fc2af280ad8f6@mail.gmail.com> Message-ID: <4A5C36EF.9060609@pressure.to> hendra kusuma wrote: > Problem is, I don't find any widget to display the picture > (the doc says that wxStaticBitmap should only be used for displaying > small image such as icon) For more general drawing of images (and other things) draw the image as a Wx::Bitmap upon a Wx::Window. This is pretty easy, see the samples/drawing/image.rb for the model of this. PS - might you be able to alter your quoting settings when replying to messages, please, so it uses a recognised quoting character like '>'? Your emails show up with all the original, reply and new text looking identical, so it's hard to find your reply. alex From alex at pressure.to Thu Jul 23 12:43:13 2009 From: alex at pressure.to (Alex Fenton) Date: Thu, 23 Jul 2009 17:43:13 +0100 Subject: [wxruby-users] Printing plain text directly to receipt printer In-Reply-To: <1d8d4a860907230928n451a30f3ifafa14f49bbffa17@mail.gmail.com> References: <1d8d4a860907230928n451a30f3ifafa14f49bbffa17@mail.gmail.com> Message-ID: <4A689321.9090300@pressure.to> Arno Dirlam wrote: > I recently searched for ways printing plain (but formatted) text > directly to a receipt printer using ruby and stumbled upon wxruby, > which seems to be a nice framework that would meet my requirements > quite well. > > Using the printing.rb example and lots of tries I found a way to print > text without dialogues: Thank you for posting a follow-up to your earlier question (which I'm afraid I didn't know the answer to). Having a record of successful code snippets benefits everyone who uses the archives. It's much appreciated. > The "D" in font "Control" tells the receipt printer to open the cash > drawer, which is connected to it. The problem is that it additionally > prints a small slice of paper. The printer's driver software can > command the printer to just open the drawer without any printing, > which is what I want to do with wxruby. > I suppose that this is because of the hidden canvas that I use. And > the canvas is always present no matter what I print on it, which is > why an empty page is printed. > > The question is: Is there a way to send plain formatted text as a > stream directly to the printer? I mean, without using a hidden canvas > and submitting coordinates to draw text? I haven't used the Printing API in wxRuby enough to be sure if there is a way to do this - I suspect not if you haven't found it. It's based on a canvas-page model AFAIK. Other ways will depend on whether you're using Windows or Linux. If Windows I don't know. On Linux there are a set of command line tools to directly send print jobs to and view the printer queue (eg 'lpr'). You'll need the device name of the printer, and know how it receives data to print (since as you say you need to send formatted data). Some printers have in-built postscript interpreters so you could just send a raw postscript file containined "D" in font "Control" that way. Or if not, you can use GhostScript with a device descriptor to turn a PS file into raw data that your printer will understand. The Linux Printing Faq might be useful: http://www.tldp.org/HOWTO/Printing-Usage-HOWTO-2.html#ss2.2 http://www.tldp.org/HOWTO/Printing-Usage-HOWTO-3.html#ss3.2 hth alex From lists at ruby-forum.com Sat Jul 25 12:54:44 2009 From: lists at ruby-forum.com (Quan Nguyen) Date: Sat, 25 Jul 2009 18:54:44 +0200 Subject: [wxruby-users] Map Tk to WxRuby Message-ID: <84c585f42f11b1144f58d655c827edbf@ruby-forum.com> Hello, I try to map a Tk to Wx for the simple animation example below. The code for Wx is way too long. Can anyone help me to come up with the shorter code for wx? Either in WxRuby or WxPython would be fine. Wonder is there a script out there (or an easier or convenient way) to map Tk script to Wx script for both WxPython and WxRuby? -Quan Nguyen ############################################################################ Except from "Scipting Languages by Examples" " In the example of "sun_moving" in section 4.3.1, we have shown that we can create a simple moving object in Tk with only few lines of code. Yes, with a mere few lines of code we can create and emulate the moving circles to animate the sun coming toward us. The complete Ruby and Python code in Tk are re-displayed below. How can we repeat the same function in Wx? The example may not be fair for comparision purpose but it will highlight the different characteristics of Tk and Wx. One thing for sure is that it will take a lot more lines of code in Wx script. " ############################################################################## #!/usr/bin/python #Python: sun coming with Tk 4.3.1 from Tkinter import * mw=Tk() c=Canvas(mw,width=300,height=300) c.pack() for i in range(1000): x0,x1=i/2,i+i/2 c.create_oval(x0, x0, x1, x1, fill='red') c.update() mainloop() ############################################################################## #!/usr/bin/ruby #Ruby: sun coming with Tk 4.3.1 require 'tk' c,k = TkCanvas.new.pack,0 TkAfter.new(1,1000,proc{TkcOval.new(c,k*0.5,k*0.5,k*1.5,k*1.5,'fill'=>'red'); k+=1}).start Tk.mainloop -------------------------------------------------------------------------------- #!/usr/bin/ruby #wxRuby: sun coming with Wx require 'wx' # class MyApp < Wx::App # def on_init # frame = Wx::Frame.new(nil, :size => [300, 300]) # canvas = Wx::Panel.new(frame, :size => [300, 300]) # frame.show buffer = Wx::Bitmap.new(300, 300) #storage buffer canvas.evt_paint do |event| #evt_paint canvas.paint do |dc| # buffer.draw do |buf_dc| #dump buffer out dc.blit(0, 0, 300, 300, buf_dc, 0, 0) #start bitmap writing end # end # end # 100.times do |i| #timng loop buffer.draw do |dcx| #clear bg trails dcx.draw_rectangle(0, 0, 300, 300) # end # buffer.draw do |dcy| #drawing into buffer dcy.brush = Wx::RED_BRUSH # dcy.draw_circle(2*i,2*i, i) # end # canvas.refresh #refresh canvas.update # sleep 0.1 # end # end # end # app = MyApp.new # app.main_loop # ############################################################################# -- Posted via http://www.ruby-forum.com/. From alex at pressure.to Mon Jul 27 08:39:17 2009 From: alex at pressure.to (Alex Fenton) Date: Mon, 27 Jul 2009 13:39:17 +0100 Subject: [wxruby-users] Map Tk to WxRuby In-Reply-To: <84c585f42f11b1144f58d655c827edbf@ruby-forum.com> References: <84c585f42f11b1144f58d655c827edbf@ruby-forum.com> Message-ID: <4A6D9FF5.7060407@pressure.to> Quan Nguyen wrote: > I try to map a Tk to Wx for the simple animation example below. The code > for Wx is way too long. Can anyone help me to come up with the shorter > code for wx? Either in WxRuby or WxPython would be fine. Wonder is there > a script out there (or an easier or convenient way) to map Tk script to > Wx script for both WxPython and WxRuby? I wouldn't be surprised if the Wx version were a bit longer. Wx offers more flexibility at the expense of making simple things a bit longer - for simplistic apps, Tk, or Shoes, are often better choices. It would be useful to define what the script is expected to do so that a proper comparison could be made - for example, is the timing of the animation specified, b/c I can't see how this is done in the Python/Tk version. Anyway the version below does the same as your version in < 50% of the code. If I jammed lots of things onto one line, like the Tk/Ruby version it could be shorter... hth alex __ require 'wx' include Wx App.run do frame = Frame.new(nil, :title => 'Sun Rising', :size => [300, 300]) canvas = Panel.new(frame) canvas.background_colour = WHITE frame.show i = 0 Timer.every(100) do canvas.paint do | dc | dc.clear dc.brush = RED_BRUSH dc.draw_circle(i * 2, i * 2, i) end i += 1 exit if i == 100 end end