datatec
2008-Apr-17 20:04 UTC
[fxruby-users] does anyone know how to get fxtext clear correctly between styled writes?
Windows XP, ruby 1.8.6, fxruby 1.6.6 Basically I have text in a FXText window, placed there by code triggered by a dropdown. The text is coloured using three different FXHiliteStyle''s I setup the styles then set the text.styled=true Then I scan the text and style it based on searches when user clicks on a button (code similar to the styledtext.rb demo) In my project style 1 sets all text to grey (background to white) style 2 sets target text to grey and underlined (background to white) style 3 sets target text to red and underlined (background to white) 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. -- View this message in context: http://www.nabble.com/does-anyone-know-how-to-get-fxtext-clear-correctly-between-styled-writes--tp16753508p16753508.html Sent from the FXRuby Users mailing list archive at Nabble.com.
Lyle Johnson
2008-Apr-17 23:42 UTC
[fxruby-users] does anyone know how to get fxtext clear correctly between styled writes?
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)?
datatec
2008-Apr-18 17:58 UTC
[fxruby-users] does anyone know how to get fxtext clear correctly between styled writes?
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.
Lyle Johnson
2008-Apr-18 19:37 UTC
[fxruby-users] does anyone know how to get fxtext clear correctly between styled writes?
On Apr 18, 2008, at 12:58 PM, datatec wrote:> 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.Ah! So we just aren''t initializing the FXHiliteStyle#style value to zero in FXHiliteStyle.new? That''s easy enough to fix. I''ll add a bug report about it.
datatec
2008-Apr-20 23:38 UTC
[fxruby-users] does anyone know how to get fxtext clear correctly between styled writes?
Lyle Johnson-4 wrote:> > > On Apr 18, 2008, at 12:58 PM, datatec wrote: > >> 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. > > Ah! So we just aren''t initializing the FXHiliteStyle#style value to > zero in FXHiliteStyle.new? That''s easy enough to fix. I''ll add a bug > report about it. > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users > >Interesting. I was able to try this proof of issue application on ubuntu 7.10 and although it reproduces the issue 100% of the time on windows xp, it does not happen on linux. (as far as I know I am using same version of ruby and fxruby) Does this mean it is a windows port bug? -- View this message in context: http://www.nabble.com/does-anyone-know-how-to-get-fxtext-clear-correctly-between-styled-writes--tp16753508p16800292.html Sent from the FXRuby Users mailing list archive at Nabble.com.
Lyle Johnson
2008-Apr-21 00:36 UTC
[fxruby-users] does anyone know how to get fxtext clear correctly between styled writes?
On Apr 20, 2008, at 6:38 PM, datatec wrote:> Interesting. > > I was able to try this proof of issue application on ubuntu 7.10 > and although it reproduces the issue 100% of the time on windows xp, > it does not happen on linux. (as far as I know I am using same > version of > ruby and fxruby) > > Does this mean it is a windows port bug?In the current release of FXRuby, when you type: h = FXHiliteStyle.new it calls the default constructor the the C++ struct: FXHiliteStyle *h = new FXHiliteStyle(); Now, that struct doesn''t actually have a constructor defined, and so it''s possible that some compilers will (be default) initialize h- >style to zero while other compilers will leave that data in an undefined state. What I will probably do to fix it is just add some code that explicitly initializes the struct''s values, so that we won''t be subject to the whims of a particular C++ compiler. --- "FXRuby: Create Lean and Mean GUIs with Ruby" Now available from the Pragmatic Bookshelf! http://www.pragprog.com/titles/fxruby