[fxruby-users] Can't add text to FXCanvas

boxofsoxx-goognews@yahoo.com boxofsoxx-goognews at yahoo.com
Wed Nov 30 22:59:49 EST 2005


I have a ruby program that uses a FXCanvas, and I have attached a FXDCWindow 
to control it. It lets me draw lines, rectangles and ellipses, but not text. 
If I attempt to draw text, I get the following error

This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information.
>Exit code: 3

I also get this error if I try to set the font of the FXCanvas or the 
FXDCWindow.

I have a short sample program that shows this problem. Thanks for any help.


class PlotterWindow < FXMainWindow
  def initialize(app)
    # Invoke base class initialize first
    super(app, "Plotter", nil, nil, DECOR_ALL, 0, 0, 500, 700)
    @color4 = FXColor::LightBlue1
    @color5 = FXColor::Blue
    @font = FXFont.new(app,"times",14)
    dumpFontDesc("Initial Font", at font.getFontDesc)
    # @font.setFont("courier,140")
    # Dialogs for later use
    colorDialog = FXColorDialog.new(self, "Color Dialog")
    # Create a font dialog for later use
    @fontDialog = FXFontDialog.new(self, "Axis Font Dialog")
    # Create a tooltip so we get tool tips for things in this window
    FXToolTip.new(self.getApp())
    statusbar = FXStatusBar.new(self,
      LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|STATUSBAR_WITH_DRAGCORNER)

    #BUTTONS
    @rightFrame = FXVerticalFrame.new(self,
LAYOUT_SIDE_TOP|LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y)
    FXVerticalSeparator.new(self,
      LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y|SEPARATOR_GROOVE)
    colorButton = FXButton.new(@rightFrame,
      "&Colors\tOpen Color Dialog\tOpen a dialog for selecting colors",
      nil, colorDialog, FXWindow::ID_SHOW,
      FRAME_RAISED|FRAME_THICK|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT, 0,0, 70, 
30)
    fontButton = FXButton.new(@rightFrame,
      "&Axes\nFont\tChoose Axis Font\tSelect a font for the Axis Display",
      nil, @fontDialog, FXWindow::ID_SHOW,
      FRAME_RAISED|FRAME_THICK|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT,0, 0,70, 
30)
    quitButton = FXButton.new(@rightFrame,
      "&Quit\tExit the Program\tTerminate Ruby Plot Program",
      nil, nil, 0,
      FRAME_RAISED|FRAME_THICK|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT,0, 0,70, 
30)
    quitButton.connect(SEL_COMMAND) {
      getApp().exit(0)
    }

    #CANVAS FRAME
    canvasFrame = FXVerticalFrame.new(self,
      FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT,
      0, 0, 0, 0, 0,0,0,0)
    @canvas = FXCanvas.new(canvasFrame, nil, 0,
      FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT)
    @canvas.connect(SEL_PAINT) do |sender, sel, event|
      FXDCWindow.new(@canvas, event) do |dc|
        @canvas.backColor = @color4
        dc.foreground = @canvas.backColor
        dc.fillRectangle(event.rect.x, event.rect.y, 
event.rect.w,event.rect.h)
        dc.foreground = @color5
      dc.drawEllipse(100,100,100,200)
      #dc.setFont(@font)    #this generates an error
      #dc.drawText(100,100,"test")  #this generates an error
      end
    end
  end

  def dumpFontDesc(lab,fd)
    print "fontDesc #{lab} = #{fd.inspect}\n"
    print "#{fd.face}, #{fd.size},#{fd.weight},"
    print "#{fd.slant}, #{fd.setwidth},#{fd.encoding},"
    print "#{fd.flags}\n\n"
    STDOUT.flush
  end

def create
    super
    show(PLACEMENT_SCREEN)
  end
end

if __FILE__ == $0
  # Construct an application
  application = FXApp.new("Button", "FoxTest")

  # Construct the main window
  PlotterWindow.new(application)

  # Create the application
  application.create

  # Run it
  application.run
end 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20051130/3a66b33d/attachment.htm


More information about the fxruby-users mailing list