[fxruby-users] does anyone know how to get fxtext clear correctly between styled writes?

datatec datatec at gmail.com
Fri Apr 18 13:58:53 EDT 2008



Lyle Johnson-4 wrote:
> 
> 
> On Apr 17, 2008, at 3:04 PM, datatec wrote:
> 
>> First time button is hit works as expected, however
>>
>> A. If hit button several times, occasionally text styles are all  
>> messed up*
>> B  If I set different text using the dropdown then click button text  
>> style
>> is frequently messed up*
>> *(selections is still the same but with styles I have not defined
>> -strikethroughts, darkbackgrounds etc)
>>
>> I have tried turning off the style between button presses, and used  
>> the
>> .repaint method, but am just gussing since I really don't know the  
>> reasion
>> this is happening.
>>
>> If anyone could help me out, I really would appreciate it.
> 
> Can you post the code (or a small example that reproduces the problem)?
> _______________________________________________
> fxruby-users mailing list
> fxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/fxruby-users
> 
> 

Yes, and in making the example I found the cause when styling a text it
appears that 
if 'hilight.style=o' is missing
the original write works correctly but writes after begin to fail.

Below is the example program.

Useage:
Choose a item from the dropdown
Click on the analize button multiple times
(text display will start to show the redraw issue)

Select the checkbox (which enables the hilight.style=0 in the hilight
definition)
Click on the analize button multiple times
(text should always repaint correctly)


Perhaps this should be in the API ref somwhere?
(or more likely it is and I just couldn't find it)
:-/


#!/usr/bin/env ruby
require 'fox16'
include Fox

TEXTVERSIONS = {
  "Text 1" => 'We the people of the United States, in order to form a more
perfect union,
establish justice, insure domestic tranquility, provide for the common
defense,
promote the general welfare, and secure the blessings of liberty to
ourselves and
 our posterity, do ordain and establish this Constitution for the United
States of America.',
  "Text 2" => 'The United States, in order to form a more perfect union,
establish justice, insure domestic tranquility, provide for the common
defense,
promote the general welfare, and secure the blessings of liberty to
ourselves,
 do ordain and establish this Constitution for the United States of
America.',
  "Text 3" => 'Order to form a more perfect union,
establish domestic tranquility, provide for the common defense,
promote the general welfare, and secure the blessings of liberty to
ourselves and
our posterity, do ordain and establish this Constitution for the United
States of America.'
}

class StyledTextWindow < FXMainWindow
  def initialize(app)
    # Call the base class initialize() first
    super(app, "Styled Text Test")
    self.width = 450
    self.height = 300

    # Menu bar, along the top
    menubar = FXMenuBar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X)
         
    #Dropdown
 FXLabel.new(menubar, "  Choose Text to analize:")
     @textchoice = FXComboBox.new(menubar, 15, :opts =>
COMBOBOX_STATIC|FRAME_SUNKEN|FRAME_THICK)
     @textchoice.numVisible = 3
    TEXTVERSIONS.keys.each do |key|
      @textchoice.appendItem(key, TEXTVERSIONS[key])
      @textchoice.connect(SEL_COMMAND) do
			 writetext
      end
    end   

#checkbox    
checkbox = FXCheckButton.new(menubar, "hilight.sytle=0 enabled      ")
checkbox.setCheck(false, notify=true)   
checkbox.connect(SEL_COMMAND) do |sender, sel, checked|
      if checked
           @checked=true
      else
          @checked=false
      end
    end   
    
    # Analize button
	@analize = FXButton.new(menubar, "Analize")
	@analize.enabled=false
          @analize.connect(SEL_COMMAND) do
            analizetext
          end   
 
    # The frame takes up the rest of the space
    textframe = FXHorizontalFrame.new(self,
      LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK)
   
    # Text window
   @text = FXText.new(textframe, nil, 0,
      TEXT_READONLY|TEXT_WORDWRAP|LAYOUT_FILL_X|LAYOUT_FILL_Y)
  
   @text.text = "Choose an Item from the dropdown" 
  end
 
def analizetext
 
    # Construct some hilite styles
    hs1 = FXHiliteStyle.new
    hs1.normalForeColor = FXRGBA(0,255,0,255)
    hs1.normalBackColor =  FXRGBA(255,255,255,255)       # FXColor::White
    if @checked==true
        hs1.style = 0
    end	
    # Construct some hilite styles
    hs2 = FXHiliteStyle.new
    hs2.normalForeColor = FXRGBA(255,0,0,255) #FXColor::Red
    hs2.normalBackColor = FXRGBA(255,255,255,255)   # FXColor::White
    if @checked==true
        hs2.style = 0
    end	

    hs3 = FXHiliteStyle.new
    hs3.normalForeColor = FXRGBA(0,0,255,255) #FXColor::Blue
    hs3.normalBackColor = FXRGBA(255,255,255,255)   # FXColor::White
    hs3.style = FXText::STYLE_UNDERLINE
   
    # Enable the style buffer for this text widget
   @text.styled = true
   
    # Set the styles
    @text.hiliteStyles = [hs1, hs2, hs3]
      @text.text = $chosen_text

    # Change the style for this phrase to hs1 [index 1]
	phrase = $chosen_text
    @text.changeStyle($chosen_text.index(phrase), phrase.length,1)
	
    # Change the style for this phrase to hs1 [index 2]
    phrase = "a more perfect union"
    @text.changeStyle($chosen_text.index(phrase), phrase.length, 2)

    # Change the style for this phrase to hs2 [index 3]
    phrase = "United States of America"
    @text.changeStyle($chosen_text.index(phrase), phrase.length, 3)
   
end 

def writetext
	      $chosen_text =@textchoice.getItemData(@textchoice.currentItem)
          @text.text =$chosen_text
		  @analize.enabled=true
end
		  
  def create
    super
    show(PLACEMENT_SCREEN)
  end
end

if __FILE__ == $0
  application = FXApp.new("StyledText", "FoxTest")
  StyledTextWindow.new(application)
  application.create
  application.run
end
-- 
View this message in context: http://www.nabble.com/does-anyone-know-how-to-get-fxtext-clear-correctly-between-styled-writes--tp16753508p16763986.html
Sent from the FXRuby Users mailing list archive at Nabble.com.



More information about the fxruby-users mailing list