Created
February 6, 2011 02:14
-
-
Save loganrosen/813035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#require 'fox16' | |
#include Fox | |
# | |
#puts "Welcome to ELM." | |
# | |
## regexp for bold text: <\*\w*\*> | |
## italic text: \</\w*\/> | |
## underline: <_\w*_> | |
# | |
#randomstring = "Logan _underlines_ stuff and is kind of /italic/ and he *bolds* stuff." | |
# | |
#if randomstring.chr==">" && randomstring.chr.chr=="*" && randomstring.reverse.chr=="<" && randomstring.reverse.chr.chr=="*" | |
# randomstring.gsub(/\w/) | |
# #(however you bold stuff in FXRuby) | |
#end | |
# | |
#if randomstring.chr==">" && randomstring.chr.chr=="/" && randomstring.reverse.chr=="<" && randomstring.reverse.chr.chr=="/" | |
# randomstring.gsub(/\w/) | |
# #(however you italicize stuff in FXRuby) | |
#end | |
# | |
#if randomstring.chr==">" && randomstring.chr.chr=="_" && randomstring.reverse.chr=="<" && randomstring.reverse.chr.chr=="_" | |
# randomstring.gsub(/\w/) | |
# #(however you underline stuff in FXRuby) | |
#end | |
require 'fox16' | |
include Fox | |
class SampleWindow < FXMainWindow | |
def initialize(app) | |
super(app, "Interpret Window", :width => 640, :height => 480) | |
interpret_btn = FXButton.new(self, "Interpret...") | |
h_frame = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y) | |
left_txt = FXText.new(h_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y) | |
inputbox = FXTextField.new(h_frame, 50, nil) | |
inputbox.text = "Enter the text file you want interpreted (write entire file path)" | |
right_txt = FXText.new(h_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|TEXT_READONLY) | |
right_txt.styled = true # turn on styles | |
# create the bold style | |
bold_style = FXHiliteStyle.from_text(right_txt) | |
bold_style.style = FXText::STYLE_BOLD | |
right_txt.hiliteStyles = [bold_style] # add additional styles here | |
interpret_btn.connect(SEL_COMMAND) do |sender, sel, event| | |
file = inputbox.text | |
f = File.open(file, 'rb') | |
left_txt.text = f.read | |
right_txt.text = left_txt.text | |
first, last = right_txt.findText("<\\*[a-zA-Z]+\\*>", :flags => SEARCH_REGEX) # use a regex to find the first mark-up | |
while first != nil | |
start_pos = first[0] # find the start of the mark-up | |
end_pos = last[0] - 1 | |
length = last[0] - first[0] # find the length of the mark-up | |
inner_text = right_txt.text[start_pos..end_pos].gsub("<*", "").gsub("*>", "") # find the text inside the mark-up | |
right_txt.replaceStyledText(start_pos, length, inner_text, 1) # replace the mark up with just the text and set the style to 1 | |
first, last = right_txt.findText("<\\*[a-zA-Z]+\\*>", :flags => SEARCH_REGEX) # use a regex to find the next mark-up | |
end | |
end | |
end | |
def create | |
super | |
self.show(PLACEMENT_SCREEN) | |
end | |
end | |
app = FXApp.new | |
SampleWindow.new(app) | |
app.create | |
app.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
require 'fox16'
include Fox
class SampleWindow < FXMainWindow
def initialize(app)
super(app, "Matt and Logan's Interpreter © 2011. All rights reserved.", :width => 900, :height => 500)
v_frame = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
h_frame = FXHorizontalFrame.new(v_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
h2_frame = FXHorizontalFrame.new(v_frame, :opts => LAYOUT_FILL_X)
v2_frame = FXVerticalFrame.new(h2_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
v3_frame = FXVerticalFrame.new(h2_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
h3_frame = FXHorizontalFrame.new(v2_frame, :opts => LAYOUT_FILL_X)
h4_frame = FXHorizontalFrame.new(v2_frame, :opts => LAYOUT_FILL_X)
left_txt = FXText.new(h_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
right_txt = FXText.new(h_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|TEXT_READONLY)
inputbox = FXTextField.new(h3_frame, 50, nil)
interpret_btn = FXButton.new(h3_frame, "Interpret")
inputbox.text = "Enter the text file you want interpreted (write entire file path)"
inputbox2 = FXLabel.new(h4_frame, "Or type in your own text and press this Interpret button")
interpret_btn2 = FXButton.new(h4_frame, "Interpret")
clear_frame = FXHorizontalFrame.new(v3_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
clearbutton = FXButton.new(clear_frame, "Clear all input", :padLeft => 100, :padRight => 100, :padTop => 40, :padBottom => 40)
clearbutton.connect(SEL_COMMAND) do |sender, sel, event|
left_txt.text = ""
right_txt.text = ""
button2count = 0
end
right_txt.styled = true # turn on styles
# create the bold, strikeout, and underline style
bold_style = FXHiliteStyle.from_text(right_txt)
bold_style.style = FXText::STYLE_BOLD
strikeout_style = FXHiliteStyle.from_text(right_txt)
strikeout_style.style = FXText::STYLE_STRIKEOUT
underline_style = FXHiliteStyle.from_text(right_txt)
underline_style.style = FXText::STYLE_UNDERLINE
f = File.open(file, 'rb')
g = File.open(file, 'rb')
left_txt.text = "Original text:\n\n" + f.read
right_txt.text = "Formatted text:\n\n" + g.read
#convert text into bold
#convert text into strikeout
#convert text into underline
end
button2count = 0
interpret_btn2.connect(SEL_COMMAND) do |sender, sel, event| #If user wants self-inputted text interpreted instead
button2count = button2count+1
#convert text into bold
#convert text into strikeout
#convert text into underline
end
# convert text into strikethrough
right_txt.hiliteStyles = [bold_style, strikeout_style, underline_style] # add additional styles here
interpret_btn.connect(SEL_COMMAND) do |sender, sel, event|
end
# convert text into underline
right_txt.hiliteStyles = [bold_style, strikeout_style, underline_style] # add additional styles here
interpret_btn.connect(SEL_COMMAND) do |sender, sel, event|
end
end
def create
super
self.show(PLACEMENT_SCREEN)
end
end
end
app = FXApp.new
SampleWindow.new(app)
app.create
app.run