Class: QDA::GUI::CategoryWindow

Inherits:
InspectorWindow show all
Includes:
Subscriber
Defined in:
lib/weft/wxgui/inspectors/category.rb

Constant Summary

Constants inherited from InspectorWindow

InspectorWindow::INSPECTOR_NB_STYLE

Constants inherited from WorkAreaWindow

WorkAreaWindow::W_WINDOW_DEF_SIZE

Instance Attribute Summary

Attributes inherited from InspectorWindow

#client

Instance Method Summary collapse

Methods included from Subscriber

#notify, #subscribe

Methods inherited from InspectorWindow

#associated_subscribers, #get_current_category, #on_activate, #on_code, #on_key_down, #on_uncode, #receive_text_font_changed

Methods inherited from WorkAreaWindow

#active?, #layout, #layout=, #on_focus

Constructor Details

#initialize(cat, client, workarea, layout) ⇒ CategoryWindow

Returns a new instance of CategoryWindow.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/weft/wxgui/inspectors/category.rb', line 6

def initialize(cat, client, workarea, layout)
		@cat = cat
		@client = client

     super(workarea, @cat.name, layout) do | parent | 
       text_box = CompositeText.new(parent, '', 0, @client)
       text_box.populate( @client.app.get_text_at_category(@cat) )
       text_box
     end

     construct_details_panel()
     if false # ! @cat.children.empty?
       construct_explore_panel()
     end

     @notebook.evt_notebook_page_changing(@notebook.get_id) do | e | 
       on_change_page(e)
     end

     set_icon( client.fetch_icon("category") )

     subscribe(@client, 
               :document_deleted, :category_changed, :category_deleted)
end

Instance Method Details

#construct_details_panelObject

just a mucky method to reduce the length of the initializer - ideally i guess this would be done using XRC



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/weft/wxgui/inspectors/category.rb', line 37

def construct_details_panel()
  panel2 = Wx::Panel.new(@notebook, -1)
  sizer2 = Wx::BoxSizer.new(Wx::VERTICAL)

  # the text entry box for the category's name
  name_box_label = Wx::StaticBox.new(panel2, -1, 'Name')
  name_box_sizer = Wx::StaticBoxSizer.new(name_box_label, Wx::VERTICAL)
  @name_field = Wx::TextCtrl.new(panel2, -1, @cat.name) 
  name_box_sizer.add(@name_field, 0, 
                     Wx::ADJUST_MINSIZE|Wx::ALL|Wx::GROW, 4)
  sizer2.add(name_box_sizer,0, Wx::ADJUST_MINSIZE|Wx::ALL|Wx::GROW, 4)
  
  # Create the statistics panel
  info_panel = Wx::Panel.new(panel2, -1)
  info_box_label = Wx::StaticBox.new(info_panel, -1, 'Statistics')
  info_box_sizer = Wx::StaticBoxSizer.new(info_box_label,
                                          Wx::VERTICAL)

  info_sizer = Wx::FlexGridSizer.new(3, 2, 5, 6)
  info_sizer.add( Wx::StaticText.new(info_panel, -1, 'Documents:') )
  @num_docs_label = Wx::StaticText.new(info_panel, -1, 
                                      @cat.num_of_docs.to_s) 
  info_sizer.add( @num_docs_label )

  info_sizer.add( Wx::StaticText.new(info_panel, -1, 'Passages:') )
  @num_codes_label = Wx::StaticText.new(info_panel, -1, 
                                        @cat.num_of_codes.to_s)
  info_sizer.add( @num_codes_label )

  info_sizer.add( Wx::StaticText.new(info_panel, -1, 'Characters:') )

  @num_chars_label =  Wx::StaticText.new(info_panel, -1, 
                                         @cat.num_of_chars.to_s)
  info_sizer.add(@num_chars_label)
  info_box_sizer.add(info_sizer, 0, 
                     Wx::GROW|Wx::ADJUST_MINSIZE|Wx::ALL, 4)
  info_panel.set_sizer(info_box_sizer)
  sizer2.add(info_panel, 0, Wx::GROW|Wx::ADJUST_MINSIZE|Wx::ALL, 2)


  memo_label = Wx::StaticBox.new(panel2, -1, 'Memo')
  memo_sizer = Wx::StaticBoxSizer.new(memo_label, Wx::VERTICAL)

  @memo_box = Wx::TextCtrl.new(panel2, -1, @cat.memo, 
                               Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 
                               Wx::TE_MULTILINE|Wx::TE_NOHIDESEL)

  @memo_box.evt_enter_window do | e | 
    set_cursor Wx::Cursor.new(Wx::CURSOR_IBEAM)
  end

  @memo_box.evt_leave_window do | e | 
    set_cursor Wx::Cursor.new(Wx::CURSOR_ARROW)
  end
  memo_sizer.add(@memo_box, 10, Wx::GROW|Wx::ALL|Wx::ADJUST_MINSIZE, 4)
  sizer2.add(memo_sizer, 1, Wx::GROW|Wx::ADJUST_MINSIZE, 4)

  
  button = Wx::Button.new(panel2, -1, 'Apply')
		button.evt_button(button.get_id) { | e | on_save_memo(e) }
  sizer2.add(button, 0, Wx::ALL|Wx::ALIGN_RIGHT|Wx::ADJUST_MINSIZE, 4)
  panel2.set_sizer( sizer2 )


  @notebook.add_page(panel2, 'details')
end

#construct_explore_panelObject

cf construct_details_panel



105
106
107
108
109
110
111
112
113
114
# File 'lib/weft/wxgui/inspectors/category.rb', line 105

def construct_explore_panel()
  panel = Wx::Panel.new(@notebook, -1)
  sizer = Wx::BoxSizer.new(Wx::VERTICAL)
  # create a local locked copy
		@tree_list = CategoryTree.new(@client, panel, true)
		@tree_list.populate([@cat])
  sizer.add(@tree_list, 10, Wx::GROW|Wx::ALL, 4)
  panel.set_sizer( sizer )
  @notebook.add_page(panel, 'explore')
end

#objectObject



31
32
33
# File 'lib/weft/wxgui/inspectors/category.rb', line 31

def object()
  @cat
end

#on_change_page(e) ⇒ Object



122
123
124
125
126
127
128
129
130
# File 'lib/weft/wxgui/inspectors/category.rb', line 122

def on_change_page(e)
  # relying on the fact we've only got two tabs - so if the
  # previously selected is 0 (The first page) we should update
  # the stats as we're going to that page
  if e.get_selection == 0
    update_stats()
  end
  e.allow()
end

#on_save_memo(e) ⇒ Object



116
117
118
119
120
# File 'lib/weft/wxgui/inspectors/category.rb', line 116

def on_save_memo(e)
  @cat.memo = @memo_box.value
  @cat.name = @name_field.value
  Wx::BusyCursor.busy { @client.app.save_category( @cat ) }
end

#receive_category_changed(category) ⇒ Object



152
153
154
155
156
157
# File 'lib/weft/wxgui/inspectors/category.rb', line 152

def receive_category_changed(category)
  if category.dbid == @cat.dbid
    @cat = category
    refresh()
  end
end

#receive_category_deleted(category) ⇒ Object



159
160
161
# File 'lib/weft/wxgui/inspectors/category.rb', line 159

def receive_category_deleted(category)
  close() if category.dbid == @cat.dbid
end

#receive_document_deleted(doc) ⇒ Object



163
164
165
# File 'lib/weft/wxgui/inspectors/category.rb', line 163

def receive_document_deleted(doc)
  refresh if @cat.codes.codes?(doc)
end

#refreshObject

updates the display from teh currently stored value for @cat, and refetches the displayed text from the database



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/weft/wxgui/inspectors/category.rb', line 140

def refresh()
  set_title( @cat.name )
  @text_box.value = ''
  @text_box.populate( @client.app.get_text_at_category(@cat) )
  @name_field.value = @cat.name
  @memo_box.value = @cat.memo
  if curr_category = @drop_down.current_category()
    @text_box.highlight_codingtable(curr_category.codes)
  end
  update_stats()
end

#update_statsObject



132
133
134
135
136
# File 'lib/weft/wxgui/inspectors/category.rb', line 132

def update_stats()
  @num_docs_label.set_label( @cat.num_of_docs.to_s )
  @num_codes_label.set_label( @cat.num_of_codes.to_s )
  @num_chars_label.set_label( @cat.num_of_chars.to_s )
end