If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Editing RubyEdit class
24 posts
• Page 2 of 3 • 1, 2, 3
Re: Editing RubyEdit class
trogluddite wrote:Exo wrote:To work we would need to copy the original code as a new string object and append the number to the beginning of each line manually and then this could be displayed.
Yes, and there is a sneaky way to do it.
Systems are down at home at the moment for some home improvements, but I have it working and can post later.
The trick is to hijack a RubyEdit method called "parse" - it gets called every time the code is edited. IIRC, I intercepted the input arguments by doing something like this...
- Code: Select all
def parse(*args, &block)
@code_string = args[0] # May not be the right index!
super(*args, &block) # Hand control back to the original method
end
@Exo - take a look in the code tracer prototype I sent you. it is in there somewhere.
Thanks Trog will take a look
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
Re: Editing RubyEdit class
@exo oh, ok, thanks for clearing this
i knew there would be a way with this parse methode but its out of my skills, the code tracer sounds very interesting
btw in the original parse methode you can find
just was asking myself what these are : "parent","caption","alert" ?
trogluddite wrote:The trick is to hijack a RubyEdit method called "parse" - it gets called every time the code is edited. IIRC, I intercepted the input arguments by doing something like this...
i knew there would be a way with this parse methode but its out of my skills, the code tracer sounds very interesting
btw in the original parse methode you can find
- Code: Select all
# Set up our own commands
schemCmds = ["output","input","watch","releaseMouse","captureMouse",
"redraw","time","parent","caption","alert","showCursor"]
just was asking myself what these are : "parent","caption","alert" ?
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Editing RubyEdit class
The only way you can insert line numbers, is to draw the code token by token to a view. This ends up in a massive code because you have to measure each tokens "printed" size and then move the drawing offset for the next token by the "printed" size of the previous token.
The code in the system.fsm is just a tokenizer that at the end pushes to an array the colors for the chars in a structure something like that:
From char 1 to char 5 use color X
From char 6 to char 8 use color Y
...
So the text itself is readonly and the return (array with char colors) is used by FlowStone to draw the text that it provided to the parse method
The code in the system.fsm is just a tokenizer that at the end pushes to an array the colors for the chars in a structure something like that:
From char 1 to char 5 use color X
From char 6 to char 8 use color Y
...
So the text itself is readonly and the return (array with char colors) is used by FlowStone to draw the text that it provided to the parse method
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Editing RubyEdit class
i found a solution to get the written code as text, for this i made a little easy methode in the system.fsm
like this you can do
but i think that this is not a very beautiful solution, can we do this to use @ variables in another class methode?
but i don't know how else to get whats typed in...
- Code: Select all
#return the encoded v input from the parse methode which is called by FS when typing
def getTxt
return @v
end
def parse v,f
sourceLines = Array.new
v.each_line {|s| sourceLines.push s}
startIndex=0
lineStartIndeces=[0]
startIndex=v.index("\n",0)
while startIndex
lineStartIndeces<<(startIndex+1)
startIndex=v.index("\n",startIndex+2)
end
v.force_encoding "utf-8"
@v=v #make v avaliable for the getTxt methode
.
.
.
like this you can do
- Code: Select all
codeStr = self.getTxt
but i think that this is not a very beautiful solution, can we do this to use @ variables in another class methode?
but i don't know how else to get whats typed in...
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Editing RubyEdit class
ok, here is a more or less well working solution which shows the code including linenr, like described above you would need to add the small methode and the @v variable in the parse methode to work,
as you can see i did some changes in the getTxt methode in the system.fsm to prepend the linenr
so all you need to do is to call self.getTxt and output it to a text window
- Code: Select all
#define the getTxt methode including linenr prepend
def getTxt
x = 'code with line numbers:'
@v.split("\n").each_with_index do |l,ln|
x += l.prepend("\n"+"%03d"%ln.to_s+' ')
end
return x
end
def parse v,f
sourceLines = Array.new
v.each_line {|s| sourceLines.push s}
startIndex=0
lineStartIndeces=[0]
startIndex=v.index("\n",0)
while startIndex
lineStartIndeces<<(startIndex+1)
startIndex=v.index("\n",startIndex+2)
end
v.force_encoding "utf-8"
@v=v
as you can see i did some changes in the getTxt methode in the system.fsm to prepend the linenr
so all you need to do is to call self.getTxt and output it to a text window
- Attachments
-
- show code with linenr.fsm
- (3.65 KiB) Downloaded 890 times
Last edited by Nubeat7 on Fri Aug 22, 2014 9:24 pm, edited 1 time in total.
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Editing RubyEdit class
Good stuff Nubeat7
I think that is a fine solution, of course no syntax colouring but that doesn't matter. At least we can see the line numbers for debugging.
I think a minor improvement would be to just send self to the output and call getTxt within the prepend linenr module saves a bit of typing
My only concern is with modifying the system.fsm , because when we update FS this will be overridden. The only other way would be to include it in the schematic basically just redefine RubyEdit, which would also be a bit of a pain if it isn't parsed first.
But at least it is working
Edit.. You changed the file yes sending text straight out like that is even better I think.
I think that is a fine solution, of course no syntax colouring but that doesn't matter. At least we can see the line numbers for debugging.
I think a minor improvement would be to just send self to the output and call getTxt within the prepend linenr module saves a bit of typing
My only concern is with modifying the system.fsm , because when we update FS this will be overridden. The only other way would be to include it in the schematic basically just redefine RubyEdit, which would also be a bit of a pain if it isn't parsed first.
But at least it is working
Edit.. You changed the file yes sending text straight out like that is even better I think.
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
Re: Editing RubyEdit class
Exo wrote:I think a minor improvement would be to just send self to the output and call getTxt within the prepend linenr module saves a bit of typing
just edited the post from before - i included the linenr prepending directly in the getTxt methode in the system.fsm...
yes, if fs updates to the next version it would get overriden, but maybe they like the idea and provide some similar stuff!? or include the linenr in the editor anyway one day
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Editing RubyEdit class
Exo wrote: yes sending text straight out like that is even better I think.
yes! good idea now you can also use
- Code: Select all
watch 'code with linenr', self.getTxt
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Editing RubyEdit class
Nubeat7 wrote:Exo wrote: yes sending text straight out like that is even better I think.
yes! good idea now you can also use
- Code: Select all
watch 'code with linenr', self.getTxt
Good point! that is definitely a better way for debugging
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
Re: Editing RubyEdit class
You can do that a lot easier, without having to modify the system.fsm. See attached file... just copy the blue module at the top into the schematic where you want to use that feature. Or just open that Schematic once and edit another file (all schematics in the same FlowStone instance get modified)
- Attachments
-
- RubyEdit Code Output (MyCo).fsm
- (1.13 KiB) Downloaded 929 times
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
24 posts
• Page 2 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 55 guests