Slide 1

Slide 1 text

RUBY GUI APPS BEAUTIFUL INSIDE AND OUTSIDE JOSEP EGEA jes@josepegea.com

Slide 2

Slide 2 text

KICK OFF!!

Slide 3

Slide 3 text

THANKS FOR COMING!!! Thanks to members of Madrid.rb Thanks to people from outside of Madrid! Thanks to our Sponsors! We ❤ you!

Slide 4

Slide 4 text

WHO'S JOSEP Software developer & Entrepreneur jes@josepegea.com https://www.josepegea.com https://github.com/josepegea

Slide 5

Slide 5 text

ABOUT PLATFORM161 Right now working with Platform161.com And, yes! We're hiring! https://platform161.com

Slide 6

Slide 6 text

ABOUT TODAY

Slide 7

Slide 7 text

THIS IS NOT Professional desktop app development with Ruby (At least, what I'm going to show is far from professional grade quality)

Slide 8

Slide 8 text

EXPECTED TAKEWAYS You learn new ways to play with GUIs You fall in love (again) with Ruby You look beyond Rails, the Web and servers Maybe (only maybe) you learn something useful for your day-to-day work And, above all, you have some fun along the way!

Slide 9

Slide 9 text

IN THE BEGINNING…

Slide 10

Slide 10 text

MY FIRST COMPUTER Credits: CPCBox - RetroVM - https://www.retrovm.com/

Slide 11

Slide 11 text

SOME GUYS HAD BIGGER TOYS Alan Kay, creator of Smalltalk, at Xerox Parc

Slide 12

Slide 12 text

SOME ARE STILL PLAYING TODAY! Dan Ingalls, co-creator of Smalltalk, with a restored Xerox Alto

Slide 13

Slide 13 text

HOW DID THIS TOY LOOK LIKE? Smalltalk 78 running on a JS emulator Credits: Smalltalk Zoo - https://smalltalkzoo.thechm.org/HOPL-St78.html?base

Slide 14

Slide 14 text

WHAT DID THESE GUYS END UP BUILDING? The GUI, OOP, tablets and much more!! Credits: PARC - https://www.parc.com/about-parc/parc-history

Slide 15

Slide 15 text

HOW DID THEY BECOME SO PRODUCTIVE?

Slide 16

Slide 16 text

DID IT WORK? Alan Kay Our programs were 10x less ef cient than those of our colleagues from other teams, but our rate of innovation was 10x faster

Slide 17

Slide 17 text

THE WORLD AFTERWARDS

Slide 18

Slide 18 text

APPLE AND MICROSOFT POPULARIZED GUIS

Slide 19

Slide 19 text

BUT THEY FORGOT ABOUT OOP Steve Jobs about his visit to Xerox PARC One of the things they showed me was Object Oriented Programming. They showed me that but I didn’t even see it. I was so blinded by the rst thing they showed me, which was the GUI.

Slide 20

Slide 20 text

AND PROGRAMMING GUIS WAS HARD! Credits: Charles Petzold - http://www.charlespetzold.com/blog/2014/12/The-Infamous-Windows-Hello-World-Program.html

Slide 21

Slide 21 text

LATER, STEVE JOBS TRIED AGAIN The NeXT had a great GUI built on top of Objective-C, which was modelled after Smalltalk

Slide 22

Slide 22 text

AND TCL/TK MADE GUIS EASIER TO BUILD TCL was introduced around 1988 TK was added around 1990 It wasn't OOP, but it made GUIs easy Perl and Python got access to TK, too!!

Slide 23

Slide 23 text

SO, THE WORLD AFTER SMALLTALK OOP GUI for Users GUI for Devs Smalltalk Great Great Great Mac/Windows/X-Window No/Poor Good Hard NeXT Very Good Great Approachable-ish TCL/TK No Decent Very approachable

Slide 24

Slide 24 text

GUIS IN RUBY

Slide 25

Slide 25 text

ENTER RUBY Purely OOP, in the Smalltalk style Very good Standard Library Interpreted: Really fast feedback loop But…. No GUI ☹

Slide 26

Slide 26 text

A GUI, AT LAST! Ruby got TK, too, in 1999 Credits: https://magazine.rubyist.net/articles/0003/0003-RubyTkMovement.html

Slide 27

Slide 27 text

OTHER GUIS FOR RUBY With time, we got other GUIs GTK QT wxWindows libUI Others (Swing with JRuby, RubyMotion, …)

Slide 28

Slide 28 text

HOW GOOD IS TK? Pros Cons Powerful widgets Not native (but close) Multiplatform Not too OOP High level A little verbose

Slide 29

Slide 29 text

PLAY TIME!!

Slide 30

Slide 30 text

LET'S BUILD SOMETHING IN PLAIN RUBY TK Some resources Stack Over ow is your friend! When searching it helps to use "tkinter" Python will remind you of Ruby's beauty! Credits: Credits: TkDocs TutorialsPoint Ruby Tk Guide TkDocs - https://tkdocs.com TutorialsPoint - Ruby Tk Guide - https://www.tutorialspoint.com/ruby/rubytkguide.htm

Slide 31

Slide 31 text

SO, LET'S SAY HELLO WORLD Credits: Not too shabby!! require 'tk' require 'tkextlib/tile' root = TkRoot.new() button = Tk::Tile::TButton.new(root) {text "Hello World"}.grid Tk.mainloop() TkDocs - https://tkdocs.com

Slide 32

Slide 32 text

SOMETHING MORE ELABORATE? Credits: require 'tk' require 'tkextlib/tile' root = TkRoot.new {title "Feet to Meters"} content = Tk::Tile::Frame.new(root) {padding "3 3 12 12"}.grid( : TkGrid.columnconfigure root, 0, :weight => 1; TkGrid.rowconfigure $feet = TkVariable.new; $meters = TkVariable.new f = Tk::Tile::Entry.new(content) {width 7; textvariable $feet}.gr Tk::Tile::Label.new(content) {textvariable $meters}.grid( :column Tk::Tile::Button.new(content) {text 'Calculate'; command {calculat Tk::Tile::Label.new(content) {text 'feet'}.grid( :column => 3, :ro Tk::Tile::Label.new(content) {text 'is equivalent to'}.grid( :colu Tk::Tile::Label.new(content) {text 'meters'}.grid( :column => 3, TkDocs - https://tkdocs.com/tutorial/ rstexample.html

Slide 33

Slide 33 text

CAN WE BUILD SOMETHING USEFUL? Let's try to get back to mathematical functions!

Slide 34

Slide 34 text

CAN WE MAKE THE CODE LESS VERBOSE?

Slide 35

Slide 35 text

WEB DEVELOPMENT HAS SPOILED US A BIT… Nowadays, we're used to markup and components Could we use something similar with Tk? = simple_form_for :login, method: :post do |f| .panel.panel-primary .panel-heading %h1 the login form .panel-body = f.input :email = f.input :password = f.input :remember_me, as: :boolean, label: false .panel-footer = f.submit "Login", class: "btn btn-primary" = link_to 'Forgot Password?', new_password_reset_path

Slide 36

Slide 36 text

INSTEAD OF content = Tk::Tile::Frame.new(root) left_bar = Tk::Tile::Frame.new(content) Tk::Tile::Label.new(left_bar) { text 'Function:' } $function = TkVariable.new("Math.sin(x)") function_t = Tk::Tile::Entry.new(left_bar) { textvariable: $funct $canvas = TkCanvas.new(content) { width 200; height 200 } $canvas.bind("MouseWheel", mousewheel, '%D') $canvas.bind("B1-Motion", mouse_drag, '%x %y') $canvas.bind("B1-ButtonRelease", mouse_up, '%x %y')

Slide 37

Slide 37 text

COULD WE HAVE… root.hframe do |f| f.vframe do |vf| vf.label(text: "Function: ") vf.entry(value: "Math.sin(x)", on_change: :update ) end f.canvas(width: 200, height: 200) do |cv| cv.on_mouse_wheel ->(e) { mousewheel(e) } cv.on_mouse_drag ->(e) { mouse_drag(e) }, button: 1 cv.on_mouse_up ->(e) { mouse_up(e) }, button: 1 end end

Slide 38

Slide 38 text

INTRODUCING tk_component https://github.com/josepegea/tk_component

Slide 39

Slide 39 text

DIFFERENT CODE, SAME RESULTS ¯\_( ツ)_/¯

Slide 40

Slide 40 text

AND WHAT ABOUT THE COMPONENTS? It's good to build GUIs with markup-like syntax Now, could be create reusable GUI blocks?

Slide 41

Slide 41 text

COMPOSED WIDGETS IN ACTION!!

Slide 42

Slide 42 text

IS THAT ALL?

Slide 43

Slide 43 text

WHAT CAN WE USE THIS FOR? Today most UIs run on a browser What's the point of a GUI in Ruby? Well, there are things that cannot run in a browser (like anything that needs to touch les) But, the main point would be… Ruby itself!!

Slide 44

Slide 44 text

WHAT WAS SO GREAT ABOUT SMALLTALK IN THE 70'S GUI and objects empowered each other Objects created the GUI GUI manipulated the objects

Slide 45

Slide 45 text

CAN WE DO THE SAME FOR RUBY? We just gave a GUI to Ruby Can we give Ruby to our GUIs?

Slide 46

Slide 46 text

ENTER tk_inspect https://github.com/josepegea/tk_inspect

Slide 47

Slide 47 text

MMMMM… LOOKS FAMILIAR?

Slide 48

Slide 48 text

WELL, GETTING THERE… But we might be missing something…

Slide 49

Slide 49 text

WHAT ABOUT NOW?

Slide 50

Slide 50 text

OK COOL, BUT, WHAT'S IN IT FOR ME?

Slide 51

Slide 51 text

WHAT ABOUT BETTER DEBUGGING? Pry is a fantastic debugger But, sometimes, the terminal is a bit rough Maybe a GUI could help…

Slide 52

Slide 52 text

OR, A GUI FOR RAILS CONSOLE?

Slide 53

Slide 53 text

VOILA!

Slide 54

Slide 54 text

JUST THE BEGINNING

Slide 55

Slide 55 text

SO FAR, THESE ARE JUST TOYS I started wanting to build GUIs in Ruby But Ruby entices you to play, so I built toys! So far, it's work in progress (fun in progress?) Do you want to play, too?

Slide 56

Slide 56 text

COME AND PLAY! https://github.com/josepegea/tk_component https://github.com/josepegea/tk_inspect https://github.com/josepegea/tk_inspect_rails

Slide 57

Slide 57 text

RECAP

Slide 58

Slide 58 text

WHAT WE LEARNED… We owe a lot to the guys at PARC of 60-90s GUI's are not "just for users" OOP and GUI's supercharge each other You, too, can bene t from Ruby GUIs!

Slide 59

Slide 59 text

REFERENCES TkComponent, TkInspect and TkInspectRails Documentation for Tk with Ruby Emulators used in this talk Xerox PARC Heros in Action https://github.com/josepegea/tk_component https://github.com/josepegea/tk_inspect https://github.com/josepegea/tk_inspect_rails TkDocs TutorialsPoint Ruby Tk Guide CPCBox - RetroVM Smalltalk Zoo Dan Ingalls live demoing Smalltalk Alan Kay: The Power of Simplicity

Slide 60

Slide 60 text

BIG THANKS!! Hope you had some fun!! | jes@josepegea.com www.josepegea.com