Class: ArcadiaProblemsShower

Inherits:
Object
  • Object
show all
Defined in:
lib/a-core.rb

Instance Method Summary collapse

Constructor Details

#initialize(_arcadia) ⇒ ArcadiaProblemsShower

Returns a new instance of ArcadiaProblemsShower.



1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
# File 'lib/a-core.rb', line 1954

def initialize(_arcadia)
  @arcadia = _arcadia
  @showed = false
  @initialized = false
  #@visible = false
  @problems = Array.new
  @seq = 0
  @dmc=0
  @rec=0
  Arcadia.attach_listener(self, ArcadiaProblemEvent)
  Arcadia.attach_listener(self, InitializeEvent)
end

Instance Method Details

#append_problem(e) ⇒ Object



2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
# File 'lib/a-core.rb', line 2096

def append_problem(e)
  parent_node='root'
  case e.type
  when ArcadiaProblemEvent::DEPENDENCE_MISSING_TYPE
    parent_node='dependences_missing_node'
    text = Arcadia.text("main.ps.dependences_missing")
    if !@tree.exist?(parent_node)
      @tree.insert('end', 'root' ,parent_node, {
        'text' =>  text ,
        'helptext' => text,
        'drawcross'=>'auto',
        'deltax'=>-1,
        'image'=> Arcadia.image_res(BROKEN_GIF)
      }.update(Arcadia.style('treeitem'))  #.update({'fill'=>Arcadia.conf('inactiveforeground')}))
      )

    end
    @dmc+=1
    @tree.itemconfigure('dependences_missing_node','text'=>"#{text} (#{@dmc})" )
  when ArcadiaProblemEvent::RUNTIME_ERROR_TYPE
    parent_node='runtime_error_node'
    text = Arcadia.text("main.ps.runtime_errors")
    if !@tree.exist?(parent_node)
      @tree.insert('end', 'root' ,parent_node, {
        'text' =>  text ,
        'helptext' => text,
        'drawcross'=>'auto',
        'deltax'=>-1,
        'image'=> Arcadia.image_res(ERROR_GIF)
      }.update(Arcadia.style('treeitem'))  #.update({'fill'=>Arcadia.conf('inactiveforeground')}))
      )
    end
    @rec+=1
    @tree.itemconfigure('runtime_error_node','text'=>"#{text} (#{@rec})" )
  end
  title_node="node_#{new_sequence_value}"
  detail_node="detail_of_#{title_node}"

  @tree.insert('end', parent_node ,title_node, {
    'text' =>  e.title ,
    'helptext' => e.title,
    'drawcross'=>'auto',
    'deltax'=>-1,
    'image'=> Arcadia.image_res(ITEM_GIF)
  }.update(Arcadia.style('treeitem'))  #.update({'fill'=>Arcadia.conf('inactiveforeground')}))
  )
  if e.detail.kind_of?(Array)
    e.detail.each_with_index{|line,i|
      @tree.insert('end', title_node , "#{detail_node}_#{i}" , {
        'text' =>  line ,
        'helptext' => i.to_s,
        'drawcross'=>'auto',
        'deltax'=>-1,
        'image'=> Arcadia.image_res(ITEM_DETAIL_GIF)
      }.update(Arcadia.style('treeitem'))  #.update({'fill'=>Arcadia.conf('inactiveforeground')}))
      )

    }
  else
    @tree.insert('end', title_node , detail_node , {
      'text' =>  e.detail ,
      'helptext' => e.title,
      'drawcross'=>'auto',
      'deltax'=>-1,
      'image'=> Arcadia.image_res(ITEM_DETAIL_GIF)
    }.update(Arcadia.style('treeitem'))  #.update({'fill'=>Arcadia.conf('inactiveforeground')}))
    )
  end


end

#button_textObject



2016
2017
2018
# File 'lib/a-core.rb', line 2016

def button_text
  @problems.count > 1 ? Arcadia.text("main.ps.problems", [@problems.count]) : Arcadia.text("main.ps.problem", [@problems.count])
end

#initialize_guiObject



2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
# File 'lib/a-core.rb', line 2021

def initialize_gui
  # float_frame
  args = {'width'=>600, 'height'=>300, 'x'=>400, 'y'=>100}
  @ff = @arcadia.layout.add_float_frame(args).hide
  @ff.title(Arcadia.text("main.ps.title"))

  #tree
  @tree = BWidgetTreePatched.new(@ff.frame, Arcadia.style('treepanel')){
    showlines false
    deltay 22
    # opencmd do_open_folder_cmd
    # closecmd do_close_folder_cmd
    # selectcommand do_select_item
    # crosscloseimage  TkPhotoImage.new('dat' => PLUS_GIF)
    # crossopenimage  TkPhotoImage.new('dat' => MINUS_GIF)
  }
  @tree.extend(TkScrollableWidget).show(0,0)

  do_double_click = proc{
    _selected = @tree.selected
    _selected_text = @tree.itemcget(_selected, 'text')
    if _selected_text
      _file, _row, _other = _selected_text.split(':')
      if File.exist?(_file)
        begin
          r = _row.strip.to_i
          integer = true
        rescue Exception => e
          integer = false
        end
        if integer
          OpenBufferTransientEvent.new(self,'file'=>_file, 'row'=>r).go!
        end
      end
    end
  }
  @tree.textbind_append('Double-1',do_double_click)


  # call button
  command = proc{
    if @ff.visible?
      @ff.hide
      #@visible = false
    else
      @ff.show
      #@visible = true
    end
  }

  b_style = Arcadia.style('toolbarbutton')
  b_style["relief"]='groove'
  #    b_style["borderwidth"]=2
  b_style["highlightbackground"]='red'

  b_text = button_text

  @b_err = Tk::BWidget::Button.new(@arcadia['toolbar'].frame, b_style){
    image  Arcadia.image_res(ALERT_GIF)
    compound 'left'
    padx  2
    command command if command
    #width 100
    #height 20
    #helptext  _hint if _hint
    text b_text
  }.pack('side' =>'left','before'=>@arcadia['toolbar'].items.values[0].item_obj, :padx=>2, :pady=>0)

end

#new_sequence_valueObject



2092
2093
2094
# File 'lib/a-core.rb', line 2092

def new_sequence_value
  @seq+=1
end

#on_after_initialize(_event) ⇒ Object



1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
# File 'lib/a-core.rb', line 1979

def on_after_initialize(_event)
  @initialized = true
  if @problems.count > 0
    show_problems
    Thread.new do
      num_sleep = 0
      while TkWinfo.viewable(Arcadia.layout.root) == false && num_sleep < 20
        sleep(1)
        num_sleep += 1
      end
      @ff.show
    end
#      p TkWinfo.viewable(Arcadia.layout.root)
#      Tk.after(1000, proc{@ff.show; p TkWinfo.viewable(Arcadia.layout.root)})
    
  end
end

#on_arcadia_problem(_event) ⇒ Object



1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
# File 'lib/a-core.rb', line 1967

def on_arcadia_problem(_event)
  @problems << _event
  if @initialized
    if !@showed
      show_problems
    else
      append_problem(_event)
      @b_err.configure('text'=> button_text)
    end
  end
end

#show_problemsObject



1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
# File 'lib/a-core.rb', line 1997

def show_problems
  begin
    initialize_gui
    @problems.each{|e|
      append_problem(e)
    }
    if @tree.exist?('dependences_missing_node')
      @tree.open_tree('dependences_missing_node', true)
    end
    if @tree.exist?('runtime_error_node')
      @tree.open_tree('runtime_error_node', true)
    end
    @showed=true
  rescue RuntimeError => e
    Arcadia.detach_listener(self, ArcadiaProblemEvent)
    Arcadia.detach_listener(self, InitializeEvent)
  end
end