Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

beginnings of a smart TV file renamer

  • Loading branch information...
commit 7c638bcd78bfbf1b538a5f2c4045dfcf1bdae431 1 parent 17a24d4
@jacobwgillespie authored
View
1  .gitignore
@@ -1,3 +1,4 @@
+*.log
*.mkv
*.avi
*.mp4
View
260 bin/erename
@@ -0,0 +1,260 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'highline/import'
+require 'fileutils'
+require 'tvdb_party'
+require 'pp'
+
+EXTS = %w(avi mpeg xvid mp4 m4v mkv wmv mpg)
+
+QUALITIES = [
+ 'cam', 'camrip',
+ 'ts', 'telesync',
+ 'scr', 'screener', 'dvdscr', 'dvdscreener',
+ 'r5',
+ 'ppvrip', 'ppv',
+ 'dvdrip',
+ 'dvdr', 'dvd',
+ 'hdtv', 'pdtv', 'dsr', 'dvb', 'tvrip', 'stv', 'dth',
+ 'bdrip', 'brrip', 'bluray', 'mkv', 'bdr', 'bd5', 'bd9'
+]
+
+FORMATS = [
+ 'divx', 'xvid', 'x264', '264', 'mpeg', 'wmv'
+]
+
+def similarity(str1, str2)
+ str1 = str1.dup
+ str2 = str2.dup
+ str1.downcase!
+ pairs1 = (0..str1.length-2).collect {|i| str1[i,2]}.reject {
+ |pair| pair.include? " "}
+ str2.downcase!
+ pairs2 = (0..str2.length-2).collect {|i| str2[i,2]}.reject {
+ |pair| pair.include? " "}
+ union = pairs1.size + pairs2.size
+ intersection = 0
+ pairs1.each do |p1|
+ 0.upto(pairs2.size-1) do |i|
+ if p1 == pairs2[i]
+ intersection += 1
+ pairs2.slice!(i)
+ break
+ end
+ end
+ end
+ (2.0 * intersection) / union
+end
+
+def most_similar file, episodes
+ sim = episodes.first
+ sim_score = similarity(file, episodes.first.name)
+
+ episodes.each do |episode|
+ score = similarity(file, episode.name)
+ #puts "#{score} - #{episode.name}"
+ if score > sim_score
+ sim = episode
+ sim_score = score
+ end
+ end
+ [sim, sim_score]
+end
+
+def find_numbers string
+ guess_one = string.scan /S(\d{1,2})E(\d{1,2})([a-z])?/i
+
+ # Format: 001x001
+ guess_two = string.scan /(\d{1,3})x(\d{1,3})([a-z])?/i
+
+ # Format: S001
+ guess_three = string.scan /S(\d{1,2})/i
+
+ # Format: 001
+ guess_four = string.scan /(\d{1,2})([a-z])?/i
+
+ [guess_one, guess_two, guess_three, guess_four]
+
+end
+
+def lcs_size(s1, s2)
+
+ num=Array.new(s1.size){Array.new(s2.size)}
+ len,ans=0
+
+ s1.scan(/./).each_with_index do |l1,i |
+ s2.scan(/./).each_with_index do |l2,j |
+
+ unless l1==l2
+ num[i][j]=0
+ else
+ (i==0 || j==0)? num[i][j]=1 : num[i][j]=1 + num[i-1][j-1]
+ len = ans = num[i][j] if num[i][j] > len
+ end
+ end
+ end
+
+ ans
+
+end
+def lcs(s1, s2)
+ res=""
+ num=Array.new(s1.size){Array.new(s2.size)}
+ len,ans=0
+ lastsub=0
+ s1.scan(/./).each_with_index do |l1,i |
+ s2.scan(/./).each_with_index do |l2,j |
+ unless l1==l2
+ num[i][j]=0
+ else
+ (i==0 || j==0)? num[i][j]=1 : num[i][j]=1 + num[i-1][j-1]
+ if num[i][j] > len
+ len = ans = num[i][j]
+ thissub = i
+ thissub -= num[i-1][j-1] unless num[i-1][j-1].nil?
+ if lastsub==thissub
+ res+=s1[i,1]
+ else
+ lastsub=thissub
+ res=s1[lastsub, (i+1)-lastsub]
+ end
+ end
+ end
+ end
+ end
+ res
+end
+
+def dups_with_count array
+ hash = Hash.new(0)
+ array.each {|v| hash[v] += 1}
+ hash.reject! { |key, value| value == 1 }
+ hash
+end
+
+
+
+tvdb = TvdbParty::Search.new(ENV['TVDB_KEY'])
+
+begin
+
+ #show_id = ask("What is the TMDb show ID? ")
+ #season = ask("What is the season number? ")
+
+ show_id = 75886
+
+ show = tvdb.get_series_by_id(show_id)
+ show.episodes
+
+ files = []
+ EXTS.each do |ext|
+ new_files = Dir.glob("*.#{ext}")
+ next if new_files.empty?
+ files += new_files
+ end
+
+ files.sort!
+
+ puts "#{files.length} Media Files Found"
+
+ parts_array = files.map do |f|
+ f.split(/[ ,\-\.\(\)]/).compact.reject(&:empty?)
+ end
+
+ parts_array.map! do |f|
+ f.reject { |p| QUALITIES.include? p.downcase }
+ end
+ parts_array.map! do |f|
+ f.reject { |p| FORMATS.include? p.downcase }
+ end
+ parts_array.map! do |f|
+ f.reject { |p| EXTS.include? p.downcase }
+ end
+
+ flat_parts_array = parts_array.flatten
+ parts_duplicates = dups_with_count flat_parts_array.map!(&:downcase)
+
+ puts parts_duplicates
+
+ files.each do |file|
+ puts file
+ episode, score = most_similar(file, show.episodes)
+
+ parts = file.split(/[ ,\-\.\(\)]/).compact.reject(&:empty?)
+ parts.reject! { |p| QUALITIES.include? p.downcase }
+ parts.reject! { |p| EXTS.include? p.downcase }
+ parts.reject! { |p| FORMATS.include? p.downcase }
+ puts "Filename in parts is #{parts}"
+
+ parts_plus_numbers = []
+
+ parts.each_index do |idx|
+ guess_one, guess_two, guess_three, guess_four = find_numbers parts[idx]
+ guess_episode = nil
+ guess_part = nil
+ guess_finder = -1
+
+ unless guess_four.empty?
+ guess_episode = guess_four.first[0].to_i
+ guess_part = guess_four.first[1]
+ guess_finder = 4
+ end
+
+ unless guess_three.empty?
+ guess_episode = -1
+ guess_finder = 3
+ end
+
+ unless guess_two.empty?
+ guess_episode = guess_two.first[1]
+ guess_part = guess_two.first[2]
+ guess_finder = 2
+ end
+
+ unless guess_one.empty?
+ guess_episode = guess_one.first[1]
+ guess_part = guess_one.first[2]
+ guess_finder = 1
+ end
+
+ parts_plus_numbers << {
+ :idx => idx,
+ :guess_finder => guess_finder,
+ :guess_episode => guess_episode.to_i,
+ :guess_part => guess_part
+ }
+ end
+
+ parts_plus_numbers.sort! { |a,b| b[:guess_finder] <=> a[:guess_finder] }
+
+ ep = parts_plus_numbers.first[:guess_episode]
+ pt = parts_plus_numbers.first[:guess_part]
+
+ unless parts_plus_numbers.first[:idx] == -1
+ guess_title = parts[(parts_plus_numbers.first[:idx] + 1)..-1].join ' '
+ episode, score = most_similar(guess_title, show.episodes)
+ puts "The guessed episode title is #{guess_title}"
+ end
+
+ puts "Similar (#{score}) to #{episode.name}"
+
+ if ep == -1
+ puts "Unable to find an episode number in the filename"
+ print "Using matched episode number #{episode.number}"
+ else
+ print "Guessed episode number is #{ep}"
+ end
+ print " part #{pt}" unless pt.nil?
+ puts
+ puts "This does NOT match the title" unless ep == episode.number
+
+
+ puts "\n\n"
+ end
+
+rescue EOFError
+ abort "\n^D"
+rescue Interrupt
+ abort "\n^C"
+end
View
3  test/Gemfile
@@ -0,0 +1,3 @@
+source 'http://rubygems.org'
+
+gem 'rbcurse-core', :require => false, :git => 'https://github.com/rkumar/rbcurse-core.git'
View
22 test/Gemfile.lock
@@ -0,0 +1,22 @@
+GIT
+ remote: https://github.com/rkumar/rbcurse-core.git
+ revision: 0d91c52780f967bfebf9c83772fefa42963a94b8
+ specs:
+ rbcurse-core (0.0.3)
+ ffi-ncurses (>= 0.4.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ ffi (1.0.11)
+ ffi-locale (1.0.1)
+ ffi (>= 1.0.9)
+ ffi-ncurses (0.4.0)
+ ffi (>= 1.0.9)
+ ffi-locale (>= 1.0.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rbcurse-core!
View
9 test/data/README.markdown
@@ -0,0 +1,9 @@
+I've put some data here to use in programs as text for textareas, textviews or lists.
+
+brew.txt - single list, use in listboxes
+color.2 - ANSI formatted text, use in formatted textview
+gemlist.txt - single column list
+lotr.txt - running text for text views
+ports.txt - 3 column list, use in tables, tabular
+unix1.txt - running text
+unix2.txt - running text
View
38 test/data/brew.txt
@@ -0,0 +1,38 @@
+ack
+aqua-less
+atool
+bash-completion
+calcurse
+cmake
+coreutils
+curl
+elinks
+findutils
+gawk
+gettext
+git
+gnu-sed
+grep
+htop
+jed
+libevent
+moreutils
+most
+msmtp
+multitail
+mysql
+oniguruma
+pcre
+pidof
+pigz
+pkg-config
+pv
+readline
+rlwrap
+s-lang
+sqlite
+tal
+task
+tig
+tmux
+wget
View
37 test/data/color.2
@@ -0,0 +1,37 @@
+Showing all items...
+ (8b0dbf) #enh view with table, text, list, tree, fields hash
+ (3ef256) #fix clearing/hiding widget
+ (df584b) %menu list place cursor firstchar match
+ (749828) %menu RT_ARROW if none go left
+ (ed1515) %vimsplit when adding, put grabbar cmd in system_commands
+ (b3102b) %listbox reduce repaint, only if change, or selection
+ (344ad2) %form dn_arrow to lower field, rt_arrow to right field
+ (35bed1) %tabularwidget ask_select and ask_unselect
+ (7c24e7) check other widgets for color changes
+ (f864fe) check for #UTF-8 errors where match method used #fix
+ (4bef44) testdir returns path wrong if i use ../ #fix
+ (2171c9) %TabularWidget example scrollbar showing white space at end #fix
+ (ed7b0a) search in tabular does not take offset of header into account #fix
+ (fc95e4) #enh widgets can have %keylabels, so mode gets taken care of auto
+ (c538e9) app_header assumes root_window, shd take window width into acount
+ (e22c8e) menu in dbdemo one column short (ony after F4 closes) #fix
+ (83dfff) additional footer text in text view area #hold
+ (891157) maybe selected and focussed should be shown same so no confusion
+ (dd5f96) calculate color_pair once, and not so many times #fix
+ (2406f8) listcellrenderer is horribly complicated - simplify
+ (f42383) reduce #repaint in #textarea and #tree
+ (543b53) dock through div by zero if row Ncurses.Lines-1 #fix
+ (c48a48) The view in #dbdemo should allow sorting on header. and maybe select one row
+ (85461c) common routine tabular(headings,content)
+ (9b3501) sort on tabularwidget with resultset sometimes gives error ofcomparison
+ (31f476) put comopnent traversal into traversal module
+ (5be1c4) popuplist: space in single selection should select?
+ (330928) system shell etc menu items should be available somehow ifwe want
+ (3663dc) install mysql and gem and test resultset with that too
+ (745c3f) remove multiform
+
+==================== TODAY ====================
+ (d56b4d) alert dialog overflow on data, shd have increased in size #fix #today
+
+==================== URGENT ====================
+ (140d16) #fix %testvimsplit not sizing STACK correctly #urgent
View
60 test/data/gemlist.txt
@@ -0,0 +1,60 @@
+activesupport (3.1.0, 3.0.10)
+arrayfields (4.7.4)
+bond (0.4.1)
+bugzyrb (0.3.8)
+bundler (1.0.18)
+cheat (1.3.0)
+chronic (0.6.4, 0.3.0)
+colored (1.2)
+dooby (0.3.1)
+fattr (2.2.0)
+ffi (1.0.9)
+ffi-locale (1.0.1)
+ffi-ncurses (0.4.0)
+gem-man (0.3.0)
+gemcutter (0.7.0)
+gemedit (1.0.1)
+git (1.2.5)
+gmail (0.4.0)
+gmail_xoauth (0.3.0)
+growl (1.0.3)
+highline (1.6.2, 1.6.1)
+hoe (2.12.3)
+i18n (0.6.0)
+interactive_editor (0.0.10)
+jeweler (1.6.4)
+json_pure (1.6.1)
+lightning (0.4.0)
+live_console (0.2.1)
+mail (2.3.0)
+main (4.7.7, 4.2.0)
+map (4.3.0)
+maruku (0.6.0)
+mime (0.1)
+mime-types (1.16)
+multi_json (1.0.3)
+ncurses (1.2.4)
+nokogiri (1.5.0)
+oauth (0.4.5)
+optiflag (0.7)
+polyglot (0.3.2)
+qwandry (0.1.4)
+rake (0.9.2, 0.8.7)
+random_data (1.5.2)
+rbcurse (1.4.0)
+rubyforge (2.0.4)
+rubygems-update (1.8.10)
+sequel (3.27.0)
+snipplr (0.0.9)
+spoon (0.0.1)
+sqlite3 (1.3.4)
+sqlite3-ruby (1.3.3)
+subcommand (1.0.6)
+syntax (1.0.0)
+terminal-table (1.4.2)
+thor (0.14.6)
+todorb (1.2.3)
+treetop (1.4.10)
+tzinfo (0.3.29)
+vmail (2.3.2)
+yard (0.7.2)
View
12 test/data/lotr.txt
@@ -0,0 +1,12 @@
+I amar prestar aen. The world is changed. Han matho ne nen. I feel it in the water. Han mathon ned cae. I feel it in the earth. A han noston ned gwilith. I smell it in the air. Much that once was is lost, for none now live who remember it.
+
+It began with the forging of the Great Rings. Three were given to the Elves, immortal, wisest and fairest of all beings. Seven to the Dwarf-Lords, great miners and craftsmen of the mountain halls. And nine, nine rings were gifted to the race of Men, who above all else desire power. For within these rings was bound the strength and the will to govern each race. But they were all of them deceived, for another ring was made. Deep in the land of Mordor, in the Fires of Mount Doom, the Dark Lord Sauron forged in secret a master ring to control all others, and into this ring he poured his cruelty, his malice and his will to dominate all life. One ring to rule them all.
+
+One by one, the free lands of Middle-Earth fell to the power of the Ring, but there were some who resisted. A last alliance of Men and Elves marched against the armies of Mordor, and on the very slopes of Mount Doom, they fought for the freedom of Middle-Earth. Victory was near, but the power of the ring could not be undone.
+It was in this moment, when all hope had faded, that Isildur, son of the king, took up his father's sword.
+
+Sauron, the enemy of the free peoples of Middle-Earth, was defeated. The Ring passed to Isildur, who had this once chance to destroy evil forever. But the hearts of Men are easily corrupted. And the ring of power has a will of its own. It betrayed Isildur, to his death. And some things that should not have been forgotten were lost. History became legend, legend became myth. And for two and a half thousand years, the ring passed out of all knowledge. Until, when chance came, it ensnared a new bearer.
+
+The Ring came to the creature Gollum, who took it deep into the tunnels of the Misty Mountains. And there it consumed him. The ring brought to Gollum unnatural long life. For five hundred years it poisoned his mind, and in the gloom of Gollum's cave, it waited. Darkness crept back into the forests of the world. Rumor grew of a shadow in the East, whispers of a nameless fear, and the Ring of Power percieved its time had now come. It abandoned Gollum. But something happened then that the Ring did not intend. It was picked up by the most unlikely creature imaginable: a Hobbit, Bilbo Baggins, of the Shire.
+
+For the time will soon come when hobbits will shape the fortunes of all.
View
136 test/data/ports.txt
@@ -0,0 +1,136 @@
+alpine @2.00 mail/alpine
+apr @1.4.5 devel/apr
+apr-util @1.3.12 devel/apr-util
+autoconf @2.68 devel/autoconf
+automake @1.11.1 devel/automake
+bash @4.2.10 shells/bash
+bash-completion @1.3 sysutils/bash-completion
+bison @2.5 devel/bison
+boost @1.47.0 devel/boost
+boost-jam @3.1.18 devel/boost-jam
+bzip2 @1.0.6 archivers/bzip2
+coreutils @8.14 sysutils/coreutils
+cppunit @1.12.1 devel/cppunit
+ctags @5.8 devel/ctags
+curl @7.22.0 net/curl
+curl-ca-bundle @7.22.0 net/curl-ca-bundle
+cyrus-sasl2 @2.1.23 security/cyrus-sasl2
+db46 @4.6.21 databases/db46
+dirac @1.0.2 multimedia/dirac
+elvis @2.2_0 editors/elvis
+expat @2.0.1 textproc/expat
+expat @2.0.1 textproc/expat
+faac @1.28 audio/faac
+faad2 @2.7 audio/faad2
+ffmpeg @0.7.6 multimedia/ffmpeg
+file @5.09 sysutils/file
+findutils @4.4.2 sysutils/findutils
+flex @2.5.35 devel/flex
+gawk @4.0.0 lang/gawk
+gdbm @1.9.1 databases/gdbm
+gettext @0.18.1.1 devel/gettext
+gettext @0.18.1.1 devel/gettext
+git-core @1.7.7 devel/git-core
+glib2 @2.28.8 devel/glib2
+gmake @3.82 devel/gmake
+gmp @5.0.2 devel/gmp
+gnupg @1.4.11 mail/gnupg
+gperf @3.0.4 devel/gperf
+gperf @3.0.4 devel/gperf
+grep @2.9 sysutils/grep
+groff @1.21 sysutils/groff
+gsed @4.2.1 textproc/gsed
+gzip @1.4 archivers/gzip
+help2man @1.40.4 textproc/help2man
+icu @4.8.1 devel/icu
+irssi @0.8.15 irc/irssi
+joe @3.7 editors/joe
+lame @3.99 audio/lame
+lame @3.99 audio/lame
+libao @1.1.0 audio/libao
+libiconv @1.14 textproc/libiconv
+libiconv @1.14 textproc/libiconv
+libid3tag @0.15.1b audio/libid3tag
+libidn @1.22 mail/libidn
+libmad @0.15.1b audio/libmad
+libmp3splt @0.5.7a audio/libmp3splt
+libogg @1.3.0 multimedia/libogg
+liboil @0.3.17 devel/liboil
+libpng @1.4.8 graphics/libpng
+libsdl @1.2.14 devel/libsdl
+libtheora @1.1.1 multimedia/libtheora
+libtool @2.4.2 devel/libtool
+libusb @1.0.8 devel/libusb
+libvorbis @1.3.2 audio/libvorbis
+libxml2 @2.7.8 textproc/libxml2
+links @2.3 www/links
+lzmautils @4.32.7 archivers/lzmautils
+m4 @1.4.16 devel/m4
+macutil @2.0b3 sysutils/macutil
+mc @4.7.5.2 sysutils/mc
+mp3splt @2.2.6a audio/mp3splt
+mp3wrap @0.5 audio/mp3wrap
+mp4v2 @1.9.1 multimedia/mp4v2
+mpack @1.6 mail/mpack
+mpg321 @0.2.10 audio/mpg321
+ncftp @3.2.5 net/ncftp
+ncurses @5.9 devel/ncurses
+ncurses @5.9 devel/ncurses
+ncursesw @5.8 devel/ncursesw
+ncursesw @5.8 devel/ncursesw
+neon @0.29.6 www/neon
+netcat @1.10 net/netcat
+openldap @2.4.21 databases/openldap
+openssl @1.0.0e devel/openssl
+p5-compress-raw-bzip2 @2.37.0 perl/p5-compress-raw-bzip2
+p5-compress-raw-zlib @2.35.0 perl/p5-compress-raw-zlib
+p5-crypt-ssleay @0.580.0 perl/p5-crypt-ssleay
+p5-error @0.170.160 perl/p5-error
+p5-html-parser @3.680.0 perl/p5-html-parser
+p5-html-tagset @3.200.0 perl/p5-html-tagset
+p5-io-compress @2.35.0 perl/p5-io-compress
+p5-libwww-perl @6.20.0 perl/p5-libwww-perl
+p5-locale-gettext @1.50.0 perl/p5-locale-gettext
+p5-svn-simple @0.280.0 perl/p5-svn-simple
+p5-term-readkey @2.300.0 perl/p5-term-readkey
+p5-uri @1.580.0 perl/p5-uri
+pcre @8.12 devel/pcre
+perl5 @5.12.3 lang/perl5
+perl5.8 @5.8.9 lang/perl5.8
+pkgconfig @0.26 devel/pkgconfig
+popt @1.16 devel/popt
+pv @1.2.0 sysutils/pv
+readline @6.2.000 devel/readline
+rsync @3.0.8 net/rsync
+schroedinger @1.0.10 multimedia/schroedinger
+serf @0.7.2 www/serf
+slang2 @2.2.3 lang/slang2
+source-highlight @3.1.4 textproc/source-highlight
+sqlite3 @3.7.8 databases/sqlite3
+subversion @1.7.0 devel/subversion
+subversion-perlbindings @1.7.0 devel/subversion-perlbindings
+surfraw @2.2.1 net/surfraw
+vim @7.3.286 editors/vim
+wget @1.13.4 net/wget
+x264 @20110628 multimedia/x264
+xorg-bigreqsproto @1.1.1 x11/xorg-bigreqsproto
+xorg-inputproto @2.0.2 x11/xorg-inputproto
+xorg-kbproto @1.0.5 x11/xorg-kbproto
+xorg-libX11 @1.4.4 x11/xorg-libX11
+xorg-libXau @1.0.6 x11/xorg-libXau
+xorg-libXdmcp @1.1.0 x11/xorg-libXdmcp
+xorg-libXext @1.3.0 x11/xorg-libXext
+xorg-libXrandr @1.3.2 x11/xorg-libXrandr
+xorg-randrproto @1.3.2 x11/xorg-randrproto
+xorg-renderproto @0.11.1 x11/xorg-renderproto
+xorg-util-macros @1.15.0 x11/xorg-util-macros
+xorg-xcmiscproto @1.2.1 x11/xorg-xcmiscproto
+xorg-xextproto @7.2.0 x11/xorg-xextproto
+xorg-xf86bigfontproto @1.2.0 x11/xorg-xf86bigfontproto
+xorg-xproto @7.0.22 x11/xorg-xproto
+xorg-xtrans @1.2.6 x11/xorg-xtrans
+xrender @0.9.6 x11/xrender
+XviD @1.3.2 multimedia/XviD
+xz @5.0.3 archivers/xz
+yasm @1.1.0 lang/yasm
+zlib @1.2.5 archivers/zlib
View
37 test/data/table.txt
@@ -0,0 +1,37 @@
+69|C-u not available for textpad and view. how to|P2|open
+85|combo symbol when label, see newmessagebox|P2|open
+86|combo let caller suggest width and use if longer than longest item|P2|open
+88|keep working on wsshortcuts as in testws..2.rb|P2|open
+89|messagebox, see about background for zterm-256 as in header|P2|open
+97|binding to KEY_ENTER doesn't work, have to bid to 13|P2|open
+98|if list not binding ENTER then dont consume it|P2|open
+22|widget hide (visible false) does not hide|P3|open
+65|clean up window.rb prv_printstring etc|P3|open
+74|list and others should just calculate longest in list|P3|open
+79|cleanup button getpaint etc|P3|open
+80|use @focusable in form to simplify|P3|open
+87|praps global setting lists etc use SPC for scroll or selection|P3|open
+92|messagebox: if text longer than display then can we split|P3|open
+95|window.refresh required after alert of messagebox closes|P3|open
+99|button option to set mnemo for keys without alt|P3|open
+10|combo keys|P4|open
+17|selected_item of list broken|P4|open
+20|cannot bind_key using Alt key and another. |P4|open
+27|#fix testvimsplit not sizing STACK correctly|P4|open
+32| #tree many empty methods in #treemodel|P4|open
+37|simplify #vimsplit calculation|P4|open
+52|%label set_label may have to calculate at repaint esp in app|P4|open
+55|Have a module Expandable for those that are multiline|P4|open
+56|DRY up titles and borders|P4|open
+60|fields width, display_len is for input area, not label plus input|P4|open
+61|test2.rb color change not affecting text objects|P4|open
+70|confusion between renderer and color_parser|P4|open
+75|textpad to allow append << at some stage|P4|open
+93|messagebox conform and choice whith single key getch|P4|open
+8|container keep repainting all|P5|open
+26|App to have a layout abject |P5|open
+39|tabularwidget truncate needed left_margin|P5|open
+42|append_to_kill, yank not working in %listbox|P5|open
+49|resultsetview needs way to specify key fields|P5|open
+50|sort on tabularwidget with resultset error sometimes|P5|open
+96|configure confirm quit etc through a file|P5|open
View
88 test/data/tasks.csv
@@ -0,0 +1,88 @@
+1|clo|bug|X3|messagebox label print overlaps left border
+2|clo|enh|P4|Field: methods not chainable
+3|clo|bug|P3|button crash if mnemo not in text
+4|clo|enh|P3|link mnemo should not have Alt
+8|ope|bug|P5|container keep repainting all
+9|clo|enh|P3|menu bar keys
+10|ope|enh|P4|combo keys
+11|clo|bug|X3|hand written DSL defs dont fire prop handler
+12|clo|bug|X4|textview on_enter
+13|clo|enh|P3|traversal of listboxes
+14|clo|enh|P3|check keys Alt-Sh-O, Alt-[. Add some missing
+15|clo|bug|P3|2 keys simulaneously with Alt-O or Alt-[
+16|clo|enh|P3|put key combins in arrays and match
+17|ope|bug|P4|selected_item of list broken
+18|clo|enh|P3|valid_range for Field
+19|clo|bug|X2|tree can print beyond right margin
+20|ope|bug|P4|cannot bind_key using Alt key and another.
+21|sta|enh|P2|make code from App common so reusable in other examples
+22|ope|bug|P3|widget hide (visible false) does not hide
+23|clo|bug|P3|listbox color changes not reflecting in cell_renderer
+24|clo|bug|P3|Table: delete row should reflect focussed_index.
+25|clo|enh|X3|#cleanup add_cols rows_panned #urgent
+26|ope|fea|P5|App to have a layout abject
+27|ope|bug|P4|#fix testvimsplit not sizing STACK correctly
+28|clo|enh|P1|FieldValidationException should rollback change,
+29|clo|enh|X1|return self from dsl_prop and dsl_accessor,
+30|can|bug|P3|on_leave has validations that should be separated,
+31|clo|enh|X1|#listbox data more accessible from LB class,
+32|ope|enh|P4| #tree many empty methods in #treemodel
+33|clo|enh|X3|display_menu shd furhter glob on tab
+34|clo|enh|X3|display_menu large list need scrolling
+35|clo|bug|X3|alert message getting truncated after 2 lines
+36|clo|fea|X3|use j k h l for navigation if unused by a button of widget
+37|ope|enh|P4|simplify #vimsplit calculation
+38|clo|bug|X3|#tabbedpane when fire, state of old tab discrep
+39|ope|bug|P5|tabularwidget truncate needed left_margin
+40|clo|bug|X3|%textarea C-e goes to last char, not one after that
+41|clo|bug|X3|M-2 did not work in textarea
+42|ope|bug|P5|append_to_kill, yank not working in %listbox
+43|clo|bug|X1|rt arrow and backspace issue ask(), dbdemo save #urgent
+44|clo|bug|P1|need to hide window after ask(), dbdemo save
+45|clo|bug|X3|directory list, after pressing Enter on ../ focus on header
+46|clo|enh|X3|textview repaints all even when no scrolling
+47|ope|enh|P4|vieditable and io.rb need to create statuswindow and take input
+48|clo|bug|X3|say not working after ask hides window
+49|ope|enh|P5|resultsetview needs way to specify key fields
+50|ope|bug|P5|sort on tabularwidget with resultset error sometimes
+51|clo|bug|X2|TabbedPane's TabbedButtons rely on window being 0,0
+52|ope|bug|P4|%label set_label may have to calculate at repaint esp in app
+53|clo|bug|X3|%App. if shortcut used outside stack or flow, dont attach form or set
+54|clo|bug|X3|inside newtabbedpane button mnemonic and underline not happening #fix
+55|ope|enh|P4|Have a module Expandable for those that are multiline
+56|ope|enh|P4|DRY up titles and borders
+57|clo|enh|X2|dont put default for color and bg in init of Wid or field
+58|clo|enh|X2|Fields display_length should be width or made alias
+60|ope|enh|P4|fields width, display_len is for input area, not label plus input
+61|ope|bug|P4|test2.rb color change not affecting text objects
+62|clo|bug|X2|when using chunks, movement crashes C-e etc
+63|clo|bug|X2|chunks in textview, when scrolling earlier lines shown
+64|clo|enh|X2|abstract chunk and parse into Format class
+65|ope|enh|P3|clean up window.rb prv_printstring etc
+66|clo|bug|X2|colorparser needs to carryover, and :reset
+67|clo|enh|X3|several places doing attrib conversion in window, use get_attrib
+68|clo|bug|X4|move chunk parsing from window.rb to chunk as in textview
+69|ope|bug|P2|C-u not available for textpad and view. how to
+70|ope|enh|P4|confusion between renderer and color_parser
+71|clo|enh|X1|redo combo with basiclist or new popup
+72|clo|enh|X2|redo label simplify, one line only
+73|clo|bug|X2|rbasiclist needs to reduce selected symbol
+74|ope|enh|P3|list and others should just calculate longest in list
+75|ope|enh|P4|textpad to allow append << at some stage
+76|clo|enh|X3|appmethods.rb may need to go into lib/common or somewhere else
+77|clo|enh|X2|switch messagebox old and new and change rdialog
+78|clo|enh|X1|switch tabbedpane classes and update examples
+79|ope|enh|P3|cleanup button getpaint etc
+80|ope|enh|P3|use @focusable in form to simplify
+81|clo|bug|X2|field label mnemonic not being set
+82|ope|bug|P2|new messagebox need default_button option
+83|clo|enh|X2|check statusline usage, should use formatted only
+84|clo|bug|X2|dbdemo M-z not doing anything
+85|ope|bug|P2|combo symbol when label, see newmessagebox
+86|ope|bug|P2|combo let caller suggest width and use if longer than longest item
+87|ope|enh|P3|praps global setting lists etc use SPC for scroll or selection
+88|ope|enh|P2|keep working on wsshortcuts as in testws..2.rb
+89|ope|bug|P2|messagebox, see about background for zterm-256 as in header
+90|clo|bug|X2|messagebox: message sets width, even if user has specified
+91|clo|enh|X2|messagebox: default row col cannot be 0,0
+92|ope|enh|P3|messagebox: if text longer than display then can we split
View
27 test/data/tasks.txt
@@ -0,0 +1,27 @@
+Field to have history which pops up
+App to have layout objects @1.6
+F2 menu to have context sensitive items
+SL and Dock events Hide. Move ...
+Stack and Flow to be objects @1.5
+ability to share directory options and functions across dir apps
+add event to form, key_resize
+app: add popup @1.5
+app: widgets can register with dock @1.5
+can use textpad in resultsetdb view to make things simpler
+colored module that allows row-wise coloring for all multirow wids
+find_file like microemacs @1.5
+motion options in textview and lists gg G cYcEcDcB zz zt zb etc
+registering command with Alt-X SL and Dock
+schemes (color) @1.5
+textview etc can have source. also module to recog file type,fmt
+use textpad for lists etc
+window.close can have a event so cleanup of any widget can be done
+Backward char search using F
+add progress bar to StatusWindow
+bottomline options global @1.5
+catch_alt_digits maybe at form level not global
+widgets needs to expose mapped keys in some easy way
+color_pair as :red_on_black
+confirm quit option, and call a proc before quitting
+elusive error if row not given in button
+rpopupmenu and rmenu share same class names
View
10 test/data/todo.txt
@@ -0,0 +1,10 @@
+ 2. Show key mappings to user
+ 3. how to override +- * a and others for listbox - need to call before super()
+ 4. app to contain window close and confirm close
+ 4. when sorting cursor on old row but curr changed
+ 5. app needs to pass up exceptions to user app
+ 5. test out vieditable and listeditable with core
+.3. Make keylabels more rubyesque - later
+x5. convert testlistbox to core
+x5. messagebox default button - done but current button should show default char
+x5. messagebox to catch YN keys also
View
28 test/data/todocsv.csv
@@ -0,0 +1,28 @@
+FIXME,MSGBOX,5,Confirm dialog: box vertical line overwritten in 2 spots,TODO
+FIXME,MSGBOX,5,Confirm dialog: use normal key as hotkey also,TODO,Tue Jan 20 11:44:49 +0530 2009
+FIXME,MSGBOX,5,Confirm dialog: arrow keys not navigating anylonger,TODO,Tue Jan 20 11:45:27 +0530 2009
+FIXME,GEN,9,Message Box sizing,TODO,Thu Jan 22 20:39:21 +0530 2009
+DONE,LIST,5,case insensitive char search in list and combo,TESTED,Sat Feb 21 20:43:05 +0530 2009
+DONE,TABLE,5,increase the maxlen of this field please. Let us see how it goes.,TESTED
+DONE,TABLE,5,Can we disable down arrow in Chkbox in table?,TESTED,Mon Jan 19 00:00:00 +0530 2009
+DONE,TABLE,0,editing on enter,TESTED,Mon Jan 19 01:37:00 +0530 2009
+DONE,TABLE,5,cell editors pcol is not being reset each time,TESTED,Mon Jan 19 17:47:00 +0530 2009
+DONE,TABLE,5,Use TAB for intercell navig. use M-TAB for next f,TESTED,Tue Jan 20 00:38:19 +0530 2009
+DONE,TABLE,5,Searching,TESTED,Sat Feb 21 20:42:10 +0530 2009
+DONE,TABLE,3,Columns editable or not,TESTED,Sat Feb 21 20:43:10 +0530 2009
+DONE,TABLE,1,Any way to start a table with no data and pop late,TODO,Sat Feb 21 20:43:33 +0530 2009
+DONE,GEN,5,Make widget of Keylabelprinter,TESTED,Tue Jan 20 00:38:43 +0530 2009
+DONE,GEN,5,Added Action class shared by Button Menuitem ,TESTED,Thu Jan 22 18:08:28 +0530 2009
+DONE,GEN,5,Added PopupMenu 2009-01-22 18:09 ,TESTED,Thu Jan 22 18:09:34 +0530 2009
+DONE,LIST,0,call on_enter and on_leave of component,TOTEST,Sun Feb 22 12:19:38 +0530 2009
+DONE,FIELD,5,Field: OVERWRITE Mode,TESTED,2010-09-13 11:24:35 +0530
+DONE,GEN,5,"Modified should check if value changed, not UP etc",TOTEST,2010-09-13 11:25:18 +0530
+TODO,TABLE,1,table.set_data should check if models already created.,TODO
+TODO,TABLE,5,"Set column_class in TableColumn, to avoid hassles",TODO
+TODO,TABLE,2,Table sorting and filtering is required - using VIEW,TODO
+TODO,TABLE,5,Table height and col widths auto sizing or FILLING extra space.,TODO
+TODO,TEXTAREA,9,"Textarea: wrap options NONE, COLUMN",TODO,Tue Jan 20 01:04:15 +0530 2009
+TODO,GEN,5,Give a decent FileChooser and FileSaver,TODO
+TODO,GEN,5,Focus Traversable vs focusable,TODO
+TODO,GEN,5,Action class: fire event for listeners,TODO,Thu Jan 22 20:09:50 +0530 2009
+TODO,FIELD,5,Field: Auto-skip when reaching end of maxlen,TODO
View
21 test/data/unix1.txt
@@ -0,0 +1,21 @@
+Eric S. Raymond, in his book The Art of Unix Programming,[2] summarizes the Unix philosophy as the widely-used KISS Principle of "Keep it Simple, Stupid."[3] He also provides a series of design rules:
+
+* Rule of Modularity: Write simple parts connected by clean interfaces.
+* Rule of Clarity: Clarity is better than cleverness.
+* Rule of Composition: Design programs to be connected to other programs.
+* Rule of Separation: Separate policy from mechanism; separate interfaces from engines.
+* Rule of Simplicity: Design for simplicity; add complexity only where you must.
+* Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do.
+* Rule of Transparency: Design for visibility to make inspection and debugging easier.
+* Rule of Robustness: Robustness is the child of transparency and simplicity.
+* Rule of Representation: Fold knowledge into data so program logic can be stupid and robust.[4]
+* Rule of Least Surprise: In interface design, always do the least surprising thing.
+* Rule of Silence: When a program has nothing surprising to say, it should say nothing.
+* Rule of Repair: When you must fail, fail noisily and as soon as possible.
+* Rule of Economy: Programmer time is expensive; conserve it in preference to machine time.
+* Rule of Generation: Avoid hand-hacking; write programs to write programs when you can.
+* Rule of Optimization: Prototype before polishing. Get it working before you optimize it.
+* Rule of Diversity: Distrust all claims for "one true way".
+* Rule of Extensibility: Design for the future, because it will be here sooner than you think.
+
+
View
11 test/data/unix2.txt
@@ -0,0 +1,11 @@
+1. Small is beautiful.
+2. Make each program do one thing well.
+3. Build a prototype as soon as possible.
+4. Choose portability over efficiency.
+5. Store data in flat text files.
+6. Use software leverage to your advantage.
+7. Use shell scripts to increase leverage and portability.
+8. Avoid captive user interfaces.
+9. Make every program a filter.
+
+
View
212 test/test.rb
@@ -0,0 +1,212 @@
+require "rubygems"
+require "bundler/setup"
+Bundler.require(:default)
+
+require 'pp'
+
+string = ARGV.join ' '
+puts "called with #{string}"
+
+# Format: S01E01
+guess_one = string.scan /S(\d{1,2})E(\d{1,2})([a-z])?/i
+
+# Format: 001x001
+guess_two = string.scan /(\d{1,3})x(\d{1,3})([a-z])?/i
+
+# Format: S001
+guess_three = string.scan /S(\d{1,2})([a-z])?/i
+
+# Format: 001
+guess_four = string.scan /(\d{1,2})([a-z])?/i
+
+puts "Guess 1"
+pp guess_one
+
+puts "Guess 2"
+pp guess_two
+
+puts "Guess 3"
+pp guess_three
+
+puts "Guess 4"
+pp guess_four
+
+require 'rbcurse/core/util/app'
+require 'rbcurse/core/include/appmethods'
+require 'rbcurse/core/widgets/rlist'
+
+ def my_help_text
+ <<-eos
+ abasiclist.rb
+ =========================================================================
+ Basic Usage
+
+ This simple example shows 2 lists inside a "flow". Each takes 50 percent
+ of the screen's width.
+
+ If you have brew installed, you can refresh the list to show actual
+ brew packages on your system, using ':r'. Then you can view info, edit,
+ or see the man page for that program.
+
+ In the second list, you can refresh the list with your gems using ":r".
+ Place cursor on any gem, and execute any of the ":" commands to see the
+ output. "edit" shells out to your EDITOR.
+
+ You can try multiple selection using <space> and <ctrl-space> for range
+ select. Check the general help screen for more _list_ commands. The selections
+ are not mapped to any command.
+
+ =========================================================================
+ :n or Alt-n for next buffer. 'q' to quit.
+
+ eos
+ end
+
+
+
+# just a simple test to ensure that rbasiclistbox is running inside a container.
+App.new do
+ def disp_menu
+ # ideally this shuld get action_manager and add_action so these are added to widgets actions
+ f = @form.get_current_field
+
+ if f.name == "lb1"
+ menu = PromptMenu.new self do
+ item :r, :refresh
+ item :i, :info
+ item :m, :brew_man
+ item :e, :edit
+ end
+ else
+ menu = PromptMenu.new self do
+ item :r, :refresh
+ item :e, :edit
+ item :d, :dependency
+ item :s, :specification
+ item :w, :which
+ end
+ end
+ menu.display_new :title => "Menu"
+ end
+ # fill list with actual gems available on your system
+ def refresh
+ f = @form.get_current_field
+ if f.name == "lb2"
+ l = %x[gem list --local].split("\n")
+ w = @form.by_name['lb2']
+ w.list l
+ else
+ l = %x[brew list].split("\n")
+ w = @form.by_name['lb1']
+ w.list l
+ end
+ end
+ def specification
+ w = @form.by_name['lb2']
+ name = w.text.split()[0]
+ textdialog(%x[ gem specification #{name} ].split("\n") , :title => 'Specification')
+ end
+
+ # execute just man for the brew package
+ def brew_man
+ w = @form.by_name['lb1']
+ name = w.text.split()[0]
+ shell_out "man #{name}"
+ end
+
+ # using gem which to get path, and then shelling out to EDITOR
+ def edit
+ f = @form.get_current_field
+ if f.name == "lb2"
+ name = f.text.split()[0]
+ shell_out "gem edit #{name}"
+ else
+ name = f.text.split()[0]
+ shell_out "brew edit #{name}"
+ end
+ return
+
+ # this is our own home-cooked version which opens the actual file in your editor
+ res = %x[ gem which #{name} ].split("\n")
+ res = res[0]
+ if File.exists? res
+ require './common/file.rb'
+ file_edit res
+ end
+ end
+ #
+ # general purpose command to catch miscellaneous actions that can be
+ # executed in the same way. Or even take complex command lines
+ # such as what vim has.
+ def execute_this *cmd
+ f = @form.get_current_field
+ if f.name == "lb2"
+ m = "gem"
+ else
+ m = "brew"
+ end
+ w = f
+ name = w.text.split()[0]
+ cmd = cmd[0].to_s
+ res = %x[ #{m} #{cmd} #{name}].split("\n")
+ res ||= "Error in command [#{cmd}] [#{name}] "
+ textdialog( res, :title => cmd ) if res
+ end
+ # handle resizing, sadly I am not sure flow and stack can do a resize, i am sure the xperimental one can.
+ def resize
+ lb1 = @form.by_name["lb1"]
+ lb2 = @form.by_name["lb2"]
+ maxc = Ncurses.COLS
+ maxr = Ncurses.LINES
+ lb1.height = maxr-2
+ lb2.height = maxr-2
+ lb1.width = ((lb1.width_pc * maxc) / 100).floor
+ lb2.width = ((lb2.width_pc * maxc) / 100).floor
+ lb2.col = lb1.col + lb1.width
+ lab = @form.by_name["lab"]
+ lab.row = maxr-1
+ end
+
+ colors = Ncurses.COLORS
+ back = :blue
+ back = 234 if colors >= 256
+ header = app_header "rbcurse #{Rbcurse::VERSION}", :text_center => "Basic List Demo", :text_right =>"New Improved!", :color => :white, :bgcolor => back #, :attr => :bold
+ message "Press F10 to escape from here"
+ #install_help_text my_help_text
+ #@form.help_manager.help_text = my_help_text
+
+ @form.define_prefix_command :csmap, :scope => self
+ #@form.define_key(:csmap, "r", 'refresh') { refresh }
+ @form.define_key(:csmap, "r", 'refresh', :refresh )
+ @form.define_key(:csmap, "s", 'specification') { specification }
+ @form.bind_key ?\C-s, :csmap
+ #pm = PrefixCommand.new :csmap, self do |p|
+ #p.key("r", 'refresh', :refresh )
+ #p.key("s", 'specification'){ specification }
+ #end
+ #@form.bind_key(?\C-x){ pm.call }
+
+ alist = File.open("data/brew.txt",'r').readlines
+ list2 = File.open("data/gemlist.txt",'r').readlines
+ lb = nil
+
+ flow :margin_top => 1, :height => FFI::NCurses.LINES-2 do
+ lb = listbox :list => alist, :suppress_borders => false, :title => "[ brew packages ]",
+ :left_margin => 1, :width_pc => 50, :name => 'lb1'
+ lb.show_selector = false
+
+ lb2 = listbox :list => list2, :justify => :left, :title => "[ gems ]", :suppress_borders => false,
+ :left_margin => 1, :width_pc => 50, :name => 'lb2'
+ end
+
+
+ label({:text => "F1 Help, F10 Quit. : for menu. Press F4 and F5 to test popup, space or enter to select", :row => Ncurses.LINES-1, :col => 0, :name => 'lab'})
+
+ @form.bind(:RESIZE) { resize() }
+ @form.bind_key(FFI::NCurses::KEY_F4) { row = lb.current_index+lb.row; col=lb.col+lb.current_value.length+1; ret = popuplist(%w[ andy berlioz strauss tchaiko matz beethoven], :row => row, :col => col, :title => "Names", :bgcolor => :blue, :color => :white) ; alert "got #{ret} "}
+
+ @form.bind_key(FFI::NCurses::KEY_F5) { list = %x[ls].split("\n");ret = popuplist(list, :title => "Files"); alert "Got #{ret} #{list[ret]} " }
+
+ @form.bind_key(?:) { disp_menu;
+ }
+end # app
Please sign in to comment.
Something went wrong with that request. Please try again.