Created
November 19, 2010 14:05
-
-
Save rdp/706548 to your computer and use it in GitHub Desktop.
Error when doing an eval
This file contains hidden or 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
| #!/usr/bin/ruby | |
| puts 'Welcome to Sensible Cinema...' | |
| require 'java' | |
| module SensibleSwing | |
| include_package 'javax.swing' | |
| [JButton, JFrame, JLabel, JPanel, JOptionPane, | |
| JFileChooser, JComboBox, JDialog] # grab these constants (http://jira.codehaus.org/browse/JRUBY-5107) | |
| include_package 'java.awt' | |
| [FlowLayout, Font] | |
| include_class 'java.awt.event.ActionListener' | |
| JFile = java.io.File | |
| class JButton | |
| def initialize *args | |
| super *args | |
| set_font Font.new("Tahoma", Font::PLAIN, 11) | |
| end | |
| def on_clicked &block | |
| raise unless block | |
| add_action_listener do |e| | |
| block.call | |
| end | |
| self | |
| end | |
| end | |
| class JFrame | |
| def close | |
| dispose # sigh | |
| end | |
| end | |
| class JFileChooser | |
| # returns nil on failure... | |
| def execute | |
| success = show_open_dialog nil | |
| raise "did not choose one" unless success == Java::javax::swing::JFileChooser::APPROVE_OPTION | |
| get_selected_file.get_absolute_path | |
| end | |
| end | |
| end | |
| module SensibleSwing | |
| class MainWindow < JFrame | |
| def initialize | |
| super | |
| setDefaultCloseOperation JFrame::EXIT_ON_CLOSE | |
| panel = JPanel.new | |
| panel.set_layout nil | |
| setSize 350,400 | |
| add panel # why can't I just slap these down? | |
| jlabel = JLabel.new 'Welcome to Sensible Cinema' | |
| happy = Font.new("Tahoma", Font::PLAIN, 11) | |
| jlabel.setFont(happy) | |
| jlabel.set_bounds(44,44,136,14) | |
| panel.add jlabel | |
| c=JButton.new( "Save local copy of an edited DVD" ) | |
| c.on_clicked { | |
| drive = get_disk_name | |
| =begin | |
| fc = JFileChooser.new | |
| fc.setFileSelectionMode(nil) | |
| fc.set_dialog_title "Please pick a DVD descriptor file" | |
| fc.set_current_directory(JFile.new( __dir__ + "/../zamples/scene_lists/dvds")) | |
| descriptor = fc.execute | |
| fc = JFileChooser.new | |
| # TODO allow for spaces in save to file | |
| fc.set_dialog_title "Pick a location to save it to (like 'my_dvd')" | |
| fc.setCurrentDirectory(JFile.new("c:\\")) | |
| save_to = fc.execute | |
| p [drive, descriptor, save_to] | |
| descriptors = YAML.load_file descriptor | |
| bat_file = VLCProgrammer.convert_to_full_xspf(descriptors, save_to, drive) | |
| temp_dir = Dir.tmpdir | |
| temp_file = temp_dir + '/' + 'convert_it.bat' | |
| File.write(temp_file, bat_file) | |
| p 'running', temp_file | |
| p 'got', system(temp_file) | |
| JOptionPane.showMessageDialog(nil, " Done--you may now watch file #{save_to}.ps in VLC player", "Done!", JOptionPane::ERROR_MESSAGE) | |
| self.close | |
| =end | |
| } | |
| c.set_bounds(44,180,200,23) | |
| panel.add c | |
| reload = JButton.new( "reload code" ).on_clicked { | |
| eval File.read(__FILE__), nil, __FILE__ | |
| p 're-evaled it' | |
| } | |
| reload.set_bounds(44,280,200,23) | |
| panel.add reload # if ARGV.find{|a| a == '--test'} | |
| end | |
| def exit_and_close | |
| JOptionPane.showMessageDialog(nil, "exiting", "exiting", JOptionPane::ERROR_MESSAGE) | |
| close | |
| exit | |
| end | |
| def get_disk_name | |
| disks = WMI::Win32_LogicalDisk.find(:all) | |
| opticals = disks.select{|d| d.Description =~ /CD-ROM/} | |
| opticals.map!{|d| [d.Name + "\\", d.VolumeName]} | |
| p opticals | |
| p 'showing dialog' | |
| dialog = GetDisk.new(self, opticals) | |
| p 'done showing dialog' | |
| return opticals[0][0] | |
| end | |
| end | |
| class GetDisk < JDialog | |
| def initialize parent, options_array | |
| super parent, true | |
| box = JComboBox.new | |
| box.add_action_listener do |e| | |
| p 'chosen perhaps?', e, box.get_selected_index, e.get_source, get_selected_item | |
| #dispose if | |
| end | |
| box.add_item "Select DVD drive" | |
| box.add_item "halloo" | |
| add box | |
| pack | |
| end | |
| end | |
| end | |
| SensibleSwing::MainWindow.new.set_visible true | |
| puts 'Please see the Sensible Cinema window' |
This file contains hidden or 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
| C:\dev\ruby\sensible-cinema\bin\isolate>C:\installs\jruby-1.5.5\bin\jruby sensible-cinema-hit-reload-twice-then-save-copy-of-for-death-take-2 | |
| Welcome to Sensible Cinema... | |
| Please see the Sensible Cinema window | |
| Welcome to Sensible Cinema... | |
| Exception in thread "AWT-EventQueue-0" sensible-cinema-hit-reload-twice-then-save-copy-of-for-death-take-2:51:in `initialize': uninitialized constant SensibleSwing::MainWindow::SensibleSwing::JFrame::EXIT_ON_CLOSE (NameError) | |
| from sensible-cinema-hit-reload-twice-then-save-copy-of-for-death-take-2:143:in `new' | |
| ...internal jruby stack elided... | |
| from SensibleSwing::MainWindow::SensibleSwing::MainWindow.initialize(sensible-cinema-hit-reload-twice-then-save-copy-of-for-death-take-2:143) | |
| from (unknown).new(sensible-cinema-hit-reload-twice-then-save-copy-of-for-death-take-2:143) | |
| from SensibleSwing::MainWindow.initialize(sensible-cinema-hit-reload-twice-then-save-copy-of-for-death-take-2:23) | |
| from Kernel.eval(sensible-cinema-hit-reload-twice-then-save-copy-of-for-death-take-2:93) | |
| from SensibleSwing::MainWindow.initialize(sensible-cinema-hit-reload-twice-then-save-copy-of-for-death-take-2:23) | |
| from Proc.call(sensible-cinema-hit-reload-twice-then-save-copy-of-for-death-take-2:23) | |
| from Java::JavaxSwing::JButton.on_clicked(:1) | |
| from (unknown).(unknown)(:1) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Anybody know if this is a bug:
https://gist.github.com/706548 (to reproduce run the code, then hit "reload code" button)
Basically it's
module S
include_package 'javax.swing'
[JButton, JFrame, JLabel, JPanel, JOptionPane,
JFileChooser, JComboBox, JDialog]
...
jframe.add JButton.new.on_clicked {
eval(File.read(FILE))
}
end
and running that block results in
uninitialized constant SensibleSwing::MainWindow::SensibleSwing::JFrame::EXIT_ON_CLOSE
like it's nested...is the nesting expected? Shouldn't it use the
Turns out this is expected. You don't pass in a binding, but I guess it still preserved the context for defining new modules, et al