Guest User

Untitled

a guest
Jul 28th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'gtk2'
  4.  
  5. module NNTPManager
  6. class MainWindow
  7. def initialize
  8. window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
  9. window.set_title "NNTP-manager main"
  10. window.signal_connect("delete_event") { Gtk.main_quit }
  11.  
  12. new_post_button = Gtk::Button.new("New Post")
  13. view_posts_button = Gtk::Button.new("View Posts")
  14. preferences_button = Gtk::Button.new("Preferences")
  15.  
  16. new_post_button.signal_connect("clicked") {
  17. NewPostForm.new
  18. }
  19.  
  20. view_posts_button.signal_connect("clicked") {
  21. ViewPostsWindow.new
  22. }
  23.  
  24. preferences_button.signal_connect("clicked") {
  25. PreferencesFormWindow.new
  26. }
  27.  
  28. buttonbox = Gtk::HBox.new
  29.  
  30. buttonbox.pack_start(new_post_button, false, false, 0)
  31. buttonbox.pack_start(view_posts_button, false, false, 0)
  32. buttonbox.pack_start(preferences_button, false, false, 0)
  33. window.add(buttonbox)
  34. window.signal_connect("destroy") { Gtk.main_quit }
  35. window.show_all
  36. Gtk.main
  37. end
  38. end
  39.  
  40. class PreferencesFormWindow
  41. attr_accessor :host, :port, :user, :password
  42.  
  43. def initialize
  44. window = Gtk::Window.new
  45. window.set_title "NNTP server host info"
  46. window.border_width = 20
  47. window.signal_connect("delete_event") { Gtk.main_quit }
  48.  
  49. host_label = Gtk::Label.new("Host: ")
  50. port_label = Gtk::Label.new("Port: ")
  51. user_label = Gtk::Label.new("User: ")
  52. password_label = Gtk::Label.new("Password: ")
  53.  
  54. host = Gtk::Entry.new
  55. port = Gtk::Entry.new
  56. user = Gtk::Entry.new
  57. password = Gtk::Entry.new
  58. password.visibility = false
  59.  
  60. submit_button = Gtk::Button.new("Save")
  61. submit_button.signal_connect("clicked") {
  62. @host = host.text
  63. @port = port.text.to_i
  64. @user = user.text
  65. @password = password.text
  66. puts "loading following information into library file: "
  67. puts "host: #{@host}"
  68. puts "port: #{@port}"
  69. puts "user: #{@user}"
  70. puts "password: #{@password}"
  71. # write_lib_file({ :info => { :host => @host,
  72. # :port => @port,
  73. # :user => @user,
  74. # :password => @password
  75. # }
  76. # })
  77. }
  78.  
  79. host_field = Gtk::HBox.new(false, 0)
  80. host_field.pack_start(host_label, true, true, 0)
  81. host_field.pack_start(host, true, true, 0)
  82.  
  83. port_field = Gtk::HBox.new(false, 0)
  84. port_field.pack_start(port_label, true, true, 0)
  85. port_field.pack_start(port, true, true, 0)
  86.  
  87. user_field = Gtk::HBox.new(false, 0)
  88. user_field.pack_start(user_label, true, true, 0)
  89. user_field.pack_start(user, true, true, 0)
  90. password_field = Gtk::HBox.new(false, 0)
  91. password_field.pack_start(password_label, true, true, 0)
  92. password_field.pack_start(password, true, true, 0)
  93.  
  94. form = Gtk::VBox.new(false, 0)
  95. form.add(host_field)
  96. form.add(port_field)
  97. form.add(user_field)
  98. form.add(password_field)
  99. form.pack_start(submit_button, true, true, 0)
  100.  
  101. window.add(form)
  102. window.show_all
  103. Gtk.main
  104. end
  105.  
  106. # def write_lib_file(hash)
  107. # hash.each do |key, value|
  108.  
  109. end
  110.  
  111. class ViewPostsWindow
  112. def initialize
  113.  
  114. end
  115.  
  116. mainapp = MainWindow.new
Add Comment
Please, Sign In to add comment