lib/legion/ui.rb in legion_mastodon_client-0.1.1 vs lib/legion/ui.rb in legion_mastodon_client-0.1.2
- old
+ new
@@ -29,22 +29,17 @@
class TootFrame
def initialize(window, mastodon)
@tootFrame = TkFrame.new(window)
- @visibility = TkVariable.new('public')
- @sensitive = TkVariable.new('false')
- @spoiler_text = TkVariable.new("")
+ @options = Hash[:visibility => "public", :sensitive => 'false', :spoiler_text => '']
+ @visibility = ['public', 'unlisted', 'private', 'direct']
@text = text = TkText.new(@tootFrame, 'width' => '50', 'height'=> '30')
- @button = TkButton.new(@tootFrame, 'text' => 'toot', 'command' => proc{mastodon.Toot(@text.value, @visibility.value, @sensitive.value, @spoiler_text.value);@text.value=""})
+ @button = TkButton.new(@tootFrame, 'text' => 'toot', 'command' => proc{mastodon.Toot(@text.value, @options);@text.value=""})
@mediabutton = TkButton.new(@tootFrame, 'text' => 'media', 'command' => proc{mastodon.MediaUpload(Tk.getOpenFile)})
- @public_button = TkButton.new(@tootFrame, 'text' => 'public', 'command' => proc{@visibility.value = 'public' })
- @unlisted_button = TkButton.new(@tootFrame, 'text' => 'unlisted', 'command' => proc{@visibility.value = 'unlisted' })
- @private_button = TkButton.new(@tootFrame, 'text' => 'private', 'command' => proc{@visibility.value = 'private' })
- @direct_button = TkButton.new(@tootFrame, 'text' => 'direct', 'command' => proc{@visibility.value = 'direct' })
- @nsfw_button = TkButton.new(@tootFrame, 'text' => 'nsfw', 'command' => proc{@sensitive.value == 'true' ? @sensitive.value = 'false' : @sensitive.value = 'true' })
- @cw_button = TkButton.new(@tootFrame, 'text' => 'cw', 'command' => proc{@spoiler_text.value == "" ? @spoiler_text.value = "Contents Warning!" : @spoiler_text.value = ""; @sensitive.value == 'true' ? @sensitive.value = 'false' : @sensitive.value = 'true' })
+ @nsfw_button = TkButton.new(@tootFrame, 'text' => 'nsfw', 'command' => proc{@options[:sensitive] == 'true' ? @options[:sensitive] = 'false' : @options[:sensitive] = 'true' })
+ @cw_button = TkButton.new(@tootFrame, 'text' => 'cw', 'command' => proc{@options[:spoiler_text] == "" ? @options[:spoiler_text] = "Contents Warning!" : @options[:spoiler_text] = ""; @options[:sensitive] == 'true' ? @options[:sensitive] = 'false' : @options[:sensitive] = 'true' })
@quitbutton = TkButton.new(@tootFrame, 'text' => 'quit', 'command' => proc{exit})
end
def TootFrame_pack
@tootFrame.pack('side' => 'left', 'fill' => 'both')
@@ -60,24 +55,43 @@
def MediaButton_pack
@mediabutton.pack('side' => 'left', 'fill' => 'both')
end
- def PubilcButton_pack
- @public_button.pack('side' => 'left', 'fill' => 'both')
- end
+ def AccountMenu(window, streaming)
- def UnlistedButton_pack
- @unlisted_button.pack('side' => 'left', 'fill' => 'both')
+ Dotenv.load
+
+ menu = TkMenu.new(window)
+ url = ENV["MASTODON_URL"].split(",")
+ procArray = Array.new
+
+ url.each do |address|
+ menu.add('command', 'label' => "#{address}", 'command' => proc{streaming.num = url.index(address);}, 'underline' => 0)
+ end
+
+ return menu
end
- def PrivateButton_pack
- @private_button.pack('side' => 'left', 'fill' => 'both')
+ def VisibilityMenu(window)
+
+ menu = TkMenu.new(window)
+
+ @visibility.each do |visibility|
+ menu.add('command', 'label' => "#{visibility}", 'command' => proc{@options[:visibility] = visibility;})
+ end
+
+ return menu
end
- def DirectButton_pack
- @direct_button.pack('side' => 'left', 'fill' => 'both')
+ def MenuBar_pack(window, streaming)
+ menubar = TkMenu.new(window)
+
+ menubar.add('cascade', 'menu' => self.AccountMenu(window, streaming), 'label' => 'Accounts')
+ menubar.add('cascade', 'menu' => self.VisibilityMenu(window), 'label' => 'Visibility')
+
+ window.menu(menubar)
end
def NsfwButton_pack
@nsfw_button.pack('side' => 'left', 'fill' => 'both')
end
@@ -88,18 +102,15 @@
def Quitbutton_pack
@quitbutton.pack('side' => 'right', 'fill' => 'both')
end
- def set
+ def set(window, streaming)
self.TootFrame_pack
self.Text_pack
self.Button_pack
- self.PubilcButton_pack
self.MediaButton_pack
- self.UnlistedButton_pack
- self.PrivateButton_pack
- self.DirectButton_pack
+ self.MenuBar_pack(window, streaming)
self.NsfwButton_pack
self.CwButton_pack
self.Quitbutton_pack
end
end
\ No newline at end of file