manabu-desktop 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,51 @@
1
1
  require_relative 'base'
2
2
  require_relative 'login'
3
+ require_relative '../sessions'
4
+ require_relative '../windows'
3
5
 
4
6
  module ManabuDesktop
5
7
  module Screens
6
8
  class MainMenu < ManabuDesktop::Screens::Base
7
9
  def initialize()
8
- super('main_menu')
10
+ if ManabuDesktop::Windows.set_main_menu(self) == false
11
+ # TODO: handle multiple main menus..
12
+ STDERR.puts 'Tried to initialize multiple Main Menus!'
13
+ end
14
+
15
+ super('main_menu', :c)
9
16
 
10
- connect_button = @builder.get_object('connect.button')
17
+ connect_button = @builder.get_object('connect.Button')
11
18
  connect_button.set_label(I18n.t('main_menu.connect'))
12
- connect_button.signal_connect('clicked') { ManabuDesktop::Screens::Login.new }
19
+ connect_button.signal_connect('clicked') { ManabuDesktop::Screens::Login.new() }
13
20
 
14
- settings_button = @builder.get_object('settings.button')
21
+ settings_button = @builder.get_object('settings.Button')
15
22
  settings_button.set_label(I18n.t('main_menu.settings'))
16
23
  settings_button.signal_connect('clicked') { puts 'Settings coming soon' }
17
24
 
18
- exit_button = @builder.get_object('exit.button')
25
+ exit_button = @builder.get_object('exit.Button')
19
26
  exit_button.set_label(I18n.t('main_menu.exit'))
20
27
  exit_button.signal_connect('clicked') do |_widget|
28
+ ManabuDesktop::Windows.destroy_all()
21
29
  Gtk.main_quit()
22
- @window.destroy()
23
30
  end
31
+
32
+ @connections_list = @builder.get_object('connections.ListBox')
33
+
34
+ @status_bar = @builder.get_object('status.Statusbar')
35
+ @status_bar_context_id = @status_bar.get_context_id('Connection Status')
36
+
37
+ set_connections_status(ManabuDesktop::Sessions.session_count)
38
+
24
39
  _show()
25
40
  end
41
+
42
+ def set_status(status_text)
43
+ @status_bar.push(@status_bar_context_id, status_text)
44
+ end
45
+
46
+ def set_connections_status(num)
47
+ set_status("#{I18n.t('main_menu.num_connections')}: #{num}")
48
+ end
26
49
  end
27
50
  end
28
51
  end
@@ -7,31 +7,36 @@ module ManabuDesktop
7
7
  module Screens
8
8
  class Roster < ManabuDesktop::Screens::Base
9
9
 
10
- COLUMN_SELECT = 0
11
- COLUMN_ID = 1
12
- COLUMN_SURNAME = 2
13
- COLUMN_NAME = 3
14
- COLUMN_DOB = 4
15
- COLUMN_SEX = 5
10
+ attr_reader :column_order
16
11
 
17
12
  def initialize(client)
18
13
  @client = client
19
14
  super('roster')
20
15
 
21
- treeview = @builder.get_object('roster.treeview')
22
- toolbar = @builder.get_object('roster.toolbar')
16
+ setup_columns()
23
17
 
24
- _create_model()
25
- treeview.set_model(@model)
26
- _create_columns(treeview)
27
-
28
- _setup_toolbar(toolbar)
18
+ _setup_toolbar()
19
+ _setup_search_filters()
29
20
 
30
21
  @window.show_all
31
22
  _show()
32
23
  end
33
24
 
25
+ # Set the order of the columns
26
+ # Possible columns:
27
+ # :id, :surname, :name, :middle_name, :surname_reading, :name_reading,
28
+ # :middle_name_reading, :gender, :dob, :enrollment
29
+ def setup_columns(order = [:id, :surname, :name, :gender, :dob, :enrollment])
30
+ @column_order = {select: 0}
31
+ order.each do |item|
32
+ @column_order[item] = @column_order.count
33
+ end
34
+ # @column_order << :controls # TODO: setup control column
35
+ _create_columns()
36
+ end
37
+
34
38
  def _create_model()
39
+ # TODO: dynamically generate model based on selected columns/order
35
40
  @model = Gtk::ListStore.new(TrueClass, Integer, String, String, String, String)
36
41
 
37
42
  students = Manabu::Students.new(@client)
@@ -43,63 +48,98 @@ module ManabuDesktop
43
48
  end
44
49
  end
45
50
 
46
- def _create_columns(treeview)
51
+ def _create_columns()
52
+ treeview = @builder.get_object('roster.TreeView')
53
+ _create_model()
54
+ treeview.set_model(@model)
47
55
  renderer = Gtk::CellRendererToggle.new
48
56
  renderer.signal_connect("toggled") { |_cell, path| _student_select(path) }
49
57
  column = Gtk::TreeViewColumn.new(I18n.t("g.select"), renderer,
50
- "active" => COLUMN_SELECT)
51
- column.sort_column_id = COLUMN_SELECT
58
+ "active" => @column_order[:select])
59
+ column.sort_column_id = @column_order[:select]
52
60
  treeview.append_column(column)
53
61
 
54
62
  renderer = Gtk::CellRendererText.new()
55
63
  column = Gtk::TreeViewColumn.new(I18n.t("student.id"), renderer,
56
- "text" => COLUMN_ID)
57
- column.sort_column_id = COLUMN_ID
64
+ "text" => @column_order[:id])
65
+ column.sort_column_id = @column_order[:id]
58
66
  treeview.append_column(column)
59
67
 
60
68
  renderer = Gtk::CellRendererText.new()
61
69
  column = Gtk::TreeViewColumn.new(I18n.t("student.surname"), renderer,
62
- "text" => COLUMN_SURNAME)
63
- column.sort_column_id = COLUMN_SURNAME
70
+ "text" => @column_order[:surname])
71
+ column.sort_column_id = @column_order[:surname]
64
72
  treeview.append_column(column)
65
73
 
66
74
  renderer = Gtk::CellRendererText.new()
67
75
  column = Gtk::TreeViewColumn.new(I18n.t("student.name"), renderer,
68
- "text" => COLUMN_NAME)
69
- column.sort_column_id = COLUMN_NAME
76
+ "text" => @column_order[:name])
77
+ column.sort_column_id = @column_order[:name]
70
78
  treeview.append_column(column)
71
79
 
72
80
  renderer = Gtk::CellRendererText.new()
73
81
  column = Gtk::TreeViewColumn.new(I18n.t("student.dob"), renderer,
74
- "text" => COLUMN_DOB)
75
- column.sort_column_id = COLUMN_DOB
82
+ "text" => @column_order[:dob])
83
+ column.sort_column_id = @column_order[:dob]
76
84
  treeview.append_column(column)
77
85
 
78
86
  renderer = Gtk::CellRendererText.new()
79
- column = Gtk::TreeViewColumn.new(I18n.t("student.sex"), renderer,
80
- "text" => COLUMN_SEX)
81
- column.sort_column_id = COLUMN_SEX
87
+ column = Gtk::TreeViewColumn.new(I18n.t("student.gender"), renderer,
88
+ "text" => @column_order[:gender])
89
+ column.sort_column_id = @column_order[:gender]
82
90
  treeview.append_column(column)
83
91
  end
84
92
 
85
93
  def _student_select(path_str)
86
94
  path = Gtk::TreePath.new(path_str)
87
95
  iter = @model.get_iter(path)
88
- fixed = iter[COLUMN_SELECT]
96
+ selected = iter[@column_order[:select]]
89
97
  # TODO: get student record and put in or remove from collection
90
- fixed ^= 1
91
- iter[COLUMN_SELECT] = fixed
98
+ selected ^= 1
99
+ iter[@column_order[:select]] = fixed
92
100
  end
93
101
 
94
- def _setup_toolbar(toolbar)
102
+ def _setup_toolbar()
103
+ toolbar = @builder.get_object('roster.Toolbar')
104
+ # new button
95
105
  register_student_button = Gtk::ToolButton.new(:stock_id => Gtk::Stock::NEW)
96
106
  register_student_button.label = I18n.t('student.register')
97
- register_student_button.signal_connect "clicked" do
107
+ register_student_button.signal_connect('clicked') do
98
108
  ManabuDesktop::Screens::Student::Registration.new(@client, self)
99
109
  end
100
- sep = Gtk::SeparatorToolItem.new
110
+
111
+ # separator
112
+ sep = Gtk::SeparatorToolItem.new()
113
+
114
+ # search/filtering box
115
+ # search_container = Gtk::Box.new(:horizontal, 10)
116
+ # search_entry = Gtk::SearchEntry.new()
117
+ # search_bar = Gtk::SearchBar.new()
118
+ # search_bar.connect_entry(search_entry)
119
+ # search_bar.add(search_container)
120
+
101
121
  toolbar.insert(register_student_button, 0)
102
122
  toolbar.insert(sep, 1)
123
+ #toolbar.insert(search_container, 2)
124
+ end
125
+
126
+ def _setup_search_filters()
127
+ clear_filters_button = @builder.get_object('clear_filters.Button')
128
+ clear_filters_button.set_label(I18n.t('g.clear'))
129
+
130
+ enrollment_status_filters_toggleButton = \
131
+ @builder.get_object('enrollment_status_filters.ToggleButton')
132
+ enrollment_status_filters_toggleButton.set_label(I18n.t('enrollment.filter'))
133
+ enrollment_status_filters_popover = \
134
+ @builder.get_object('enrollment_status_filters.Popover')
135
+
136
+ enrollment_status_filters_popover.signal_connect('closed') {
137
+ enrollment_status_filters_toggleButton.active = false
138
+ }
139
+ enrollment_status_filters_toggleButton.signal_connect('toggled') {
140
+ enrollment_status_filters_popover.visible =
141
+ enrollment_status_filters_toggleButton.active?
142
+ }
103
143
  end
104
144
  end
105
145
  end
@@ -1,6 +1,8 @@
1
1
  require_relative '../base'
2
+ require_relative '../../tools'
2
3
  require 'manabu/client'
3
4
  require 'manabu/student'
5
+ require 'manabu/students'
4
6
 
5
7
  module ManabuDesktop
6
8
  module Screens
@@ -12,30 +14,89 @@ module ManabuDesktop
12
14
  @parent = parent
13
15
 
14
16
  super('student_registration')
15
-
16
- @builder.get_object('surname.label').set_label(
17
+
18
+ # Name
19
+ @builder.get_object('surname.Label').set_label(
17
20
  I18n.t('student.surname'))
18
- @builder.get_object('name.label').set_label(
21
+ @surname_entry = @builder.get_object('surname.Entry')
22
+ @builder.get_object('name.Label').set_label(
19
23
  I18n.t('student.name'))
20
- @builder.get_object('middle_name.label').set_label(
24
+ @name_entry = @builder.get_object('name.Entry')
25
+ @builder.get_object('middle_name.Label').set_label(
21
26
  I18n.t('student.middle_name'))
27
+ @middle_name_entry = @builder.get_object('middle_name.Entry')
22
28
 
23
- @builder.get_object('surname_reading.label').set_label(
29
+ # Name readings
30
+ @builder.get_object('surname_reading.Label').set_label(
24
31
  I18n.t('student.surname_reading'))
25
- @builder.get_object('name_reading.label').set_label(
32
+ @surname_reading_entry = @builder.get_object('surname_reading.Entry')
33
+ @builder.get_object('name_reading.Label').set_label(
26
34
  I18n.t('student.name_reading'))
27
- @builder.get_object('middle_name_reading.label').set_label(
35
+ @name_reading_entry = @builder.get_object('name_reading.Entry')
36
+ @builder.get_object('middle_name_reading.Label').set_label(
28
37
  I18n.t('student.middle_name_reading'))
38
+ @middle_name_reading_entry = @builder.get_object('middle_name_reading.Entry')
39
+
40
+ # Gender
41
+ @builder.get_object('gender.Label').set_label(I18n.t('student.gender'))
42
+ gender_comboBoxText = @builder.get_object('gender.ComboBoxText')
43
+ gender_comboBoxText.append_text(' ')
44
+ gender_comboBoxText.append_text(I18n.t('student.male'))
45
+ gender_comboBoxText.append_text(I18n.t('student.female'))
29
46
 
47
+ # Birth date
48
+ @builder.get_object('birth_date.Label').set_label(I18n.t('student.dob'))
49
+ birth_date_picker_toggleButton = @builder.get_object('birth_date_picker.ToggleButton')
50
+ pixbuf = GdkPixbuf::Pixbuf.new(
51
+ file: ManabuDesktop::Tools.emojidex.emoji[:calendar].paths[:png][:hdpi])
52
+ @builder.get_object('birth_date_picker.Image').set_pixbuf(pixbuf)
53
+ birth_date_picker_popover = @builder.get_object('birth_date_picker.Popover')
54
+ birth_date_picker_popover.signal_connect('closed') {
55
+ birth_date_picker_toggleButton.active = false
56
+ }
57
+ birth_date_picker_calendar = @builder.get_object('birth_date_picker.Calendar')
58
+ birth_date_picker_calendar.signal_connect('day-selected') {
59
+ puts birth_date_picker_calendar.date
60
+ }
61
+ birth_date_picker_toggleButton.signal_connect('toggled') {
62
+ birth_date_picker_popover.visible = birth_date_picker_toggleButton.active?
63
+ }
30
64
 
31
- @builder.get_object('sex.label').set_label(I18n.t('student.sex'))
32
- sex_comboboxtext = @builder.get_object('sex.comboboxtext')
33
- sex_comboboxtext.append_text(I18n.t('student.male'))
34
- sex_comboboxtext.append_text(I18n.t('student.female'))
35
- @builder.get_object('birth_date.label').set_label(I18n.t('student.dob'))
65
+
66
+ # Registration
67
+ register_button = @builder.get_object('register.Button')
68
+ register_button.set_label(I18n.t('g.register'))
69
+ register_button.signal_connect('clicked') {
70
+ _register(@surname_entry.text, @name_entry.text, @middle_name_entry.text,
71
+ @surname_reading_entry.text, @name_reading_entry.text,
72
+ @middle_name_reading_entry.text,
73
+ nil, nil, nil, nil)
74
+ }
36
75
 
37
76
  _show()
38
77
  end
78
+
79
+ # Compose and send a registration request
80
+ def _register(surname, name, middle_name,
81
+ surname_reading, name_reading, middle_name_reading,
82
+ gender, dob, enrollment_status, picture_path)
83
+ student = Manabu::Student.new(@client)
84
+ student.surname = surname
85
+ student.name = name
86
+ student.middle_name = middle_name
87
+ student.surname_reading = surname_reading
88
+ student.name_reading = name_reading
89
+ student.middle_name_reading = middle_name_reading
90
+ # TODO: gender
91
+ # TODO: DOB
92
+ # TODO: enrollment_status
93
+ # TODO: picture
94
+
95
+ students = Manabu::Students.new(@client)
96
+ students.register(student)
97
+
98
+ @window.destroy
99
+ end
39
100
  end
40
101
  end
41
102
  end
@@ -1,8 +1,7 @@
1
1
  require_relative 'base'
2
2
  require_relative 'roster'
3
+ require_relative '../tools'
3
4
  require 'manabu/client'
4
- require 'emojidex-rasters'
5
- require 'emojidex/data/utf'
6
5
 
7
6
  module ManabuDesktop
8
7
  module Screens
@@ -19,7 +18,7 @@ module ManabuDesktop
19
18
 
20
19
  @activities = [:Roster, :Courses, :Exams, :Administration]
21
20
 
22
- icon_view = @builder.get_object('tools.icons')
21
+ icon_view = @builder.get_object('tools.IconView')
23
22
  icon_view.set_pixbuf_column(ICON_COL)
24
23
  icon_view.set_text_column(LABEL_COL)
25
24
  list = Gtk::ListStore.new(GdkPixbuf::Pixbuf, String, String)
@@ -41,18 +40,22 @@ module ManabuDesktop
41
40
  end
42
41
 
43
42
  def _create_ability_icon(ability, list, icon_view)
44
- emojidex = Emojidex::Data::UTF.new
45
43
  case ability
46
44
  when :Roster
47
- pixbuf = GdkPixbuf::Pixbuf.new(file: emojidex.emoji[:student].paths[:png][:px64])
45
+ pixbuf = GdkPixbuf::Pixbuf.new(
46
+ file: ManabuDesktop::Tools.emojidex.emoji[:student].paths[:png][:px64])
48
47
  when :Courses
49
- pixbuf = GdkPixbuf::Pixbuf.new(file: emojidex.emoji[:notebook].paths[:png][:px64])
48
+ pixbuf = GdkPixbuf::Pixbuf.new(
49
+ file: ManabuDesktop::Tools.emojidex.emoji[:notebook].paths[:png][:px64])
50
50
  when :Exams
51
- pixbuf = GdkPixbuf::Pixbuf.new(file: emojidex.emoji[:white_check_mark].paths[:png][:px64])
51
+ pixbuf = GdkPixbuf::Pixbuf.new(
52
+ file: ManabuDesktop::Tools.emojidex.emoji[:white_check_mark].paths[:png][:px64])
52
53
  when :Administration
53
- pixbuf = GdkPixbuf::Pixbuf.new(file: emojidex.emoji[:wrench].paths[:png][:px64])
54
+ pixbuf = GdkPixbuf::Pixbuf.new(
55
+ file: ManabuDesktop::Tools.emojidex.emoji[:wrench].paths[:png][:px64])
54
56
  else
55
- pixbuf = GdkPixbuf::Pixbuf.new(file: emojidex.emoji[:question].paths[:png][:px64])
57
+ pixbuf = GdkPixbuf::Pixbuf.new(
58
+ file: ManabuDesktop::Tools.emojidex.emoji[:question].paths[:png][:px64])
56
59
  end
57
60
 
58
61
  iter = list.append
data/lib/sessions.rb CHANGED
@@ -1,4 +1,24 @@
1
+ require_relative 'windows'
2
+
1
3
  module ManabuDesktop
2
4
  class Sessions
5
+ @@active_sessions = []
6
+
7
+ def self.get_sessions()
8
+ @@active_sessions
9
+ end
10
+
11
+ def self.session_count
12
+ @@active_sessions.length
13
+ end
14
+
15
+ def self.add_session(session_handle)
16
+ @@active_sessions << session_handle
17
+ main_menu = ManabuDesktop::Windows.get_main_menu()
18
+ main_menu.set_connections_status(session_count) unless main_menu == nil
19
+ end
20
+
21
+ def self.remove_session(session_identifier)
22
+ end
3
23
  end
4
24
  end
data/lib/tools.rb CHANGED
@@ -1,12 +1,35 @@
1
1
  require 'i18n'
2
+ require 'emojidex-rasters'
3
+ require 'emojidex/data/utf'
2
4
 
3
- I18n.load_path = Dir["#{__dir__}/../locales/*.yml"]
5
+ module ManabuDesktop
6
+ class Tools
7
+ @@_initialized = false
8
+ @@_emojidex = nil
4
9
 
5
- # TODO there must be a better way to determine language
6
- @lang = (ENV['LANG'][0..1]).to_sym
7
- if I18n.available_locales.include? @lang
8
- I18n.locale = @lang
9
- else
10
- I18n.locale = :en
11
- @lang = :en
10
+ def self.init()
11
+ return if @@_initialized
12
+
13
+ I18n.load_path = Dir["#{__dir__}/../locales/*.yml"]
14
+
15
+ # TODO there must be a better way to determine language
16
+ @lang = (ENV['LANG'][0..1]).to_sym
17
+ if I18n.available_locales.include? @lang
18
+ I18n.locale = @lang
19
+ else
20
+ I18n.locale = :en
21
+ @lang = :en
22
+ end
23
+
24
+ @@_initialized = true
25
+ end
26
+
27
+ def self.emojidex()
28
+ return @@_emojidex if @@_emojidex
29
+ @@_emojidex = Emojidex::Data::UTF.new
30
+ @@_emojidex
31
+ end
32
+ end
12
33
  end
34
+
35
+ ManabuDesktop::Tools.init()
data/lib/windows.rb ADDED
@@ -0,0 +1,26 @@
1
+ module ManabuDesktop
2
+ class Windows
3
+ @@main_menu = nil
4
+ @@window_list = []
5
+
6
+ def self.set_main_menu(handle)
7
+ return false if @@main_menu != nil
8
+ @@main_menu = handle
9
+ true
10
+ end
11
+
12
+ def self.get_main_menu()
13
+ @@main_menu
14
+ end
15
+
16
+ def self.add_window(handle)
17
+ @@window_list << handle
18
+ end
19
+
20
+ def self.destroy_all()
21
+ @@window_list.each do |window|
22
+ window.destroy()
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'manabu-desktop'
3
- s.version = '0.0.2'
3
+ s.version = '0.0.3'
4
4
  s.licenses = ['GPL-3.0']
5
5
  s.summary = 'GTK based GUI client for Manabu/GAKU Engine'
6
6
  s.description = 'Manabu Desktop is a GTK front end for the Manabu client.'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manabu-desktop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rei Kagetsuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-21 00:00:00.000000000 Z
11
+ date: 2018-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: manabu
@@ -106,6 +106,7 @@ files:
106
106
  - lib/sessions.rb
107
107
  - lib/tools.rb
108
108
  - lib/util/cache.rb
109
+ - lib/windows.rb
109
110
  - manabu-desktop.gemspec
110
111
  homepage: http://www.gakuengine.com
111
112
  licenses: