Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix about window on indicator and refactor codes #51

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 60 additions & 59 deletions src/BatteryMonitor/about_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,68 +43,69 @@


class AboutWindow():
"""GUI class for About Window.
"""GUI class for About Window.

This class displays the About window in where the user can see the information about Battery Monitor project.
"""
This class displays the About window in where the user can see the information about Battery Monitor project.
"""

def __init__(self):
authors = [
'Himadri Sekhar Basu <https://hsbasu.github.io>',
'Maksudur Rahman Maateen <https://maateen.me/>',
'Safwan Rahman <https://github.com/safwanrahman>',
'Abdelhak BOUGOUFFA <https://abougouffa.github.io/>'
]
copyrights = "Copyright \xa9 2016-2018 Maksudur Rahman Maateen\n \
Copyright \xa9 2021-2022 Himadri Sekhar Basu"
documenters = [
'Maksudur Rahman Maateen <https://maateen.me/>'
]
mainatainers = [
'Himadri Sekhar Basu <https://hsbasu.github.io>'
]
def __init__(self, widget):
authors = [
'Himadri Sekhar Basu <https://hsbasu.github.io>',
'Maksudur Rahman Maateen <https://maateen.me/>',
'Safwan Rahman <https://github.com/safwanrahman>',
'Abdelhak BOUGOUFFA <https://abougouffa.github.io/>'
]
copyrights = "Copyright \xa9 2016-2018 Maksudur Rahman Maateen\n \
Copyright \xa9 2021-2022 Himadri Sekhar Basu"
documenters = [
'Maksudur Rahman Maateen <https://maateen.me/>'
]
mainatainers = [
'Himadri Sekhar Basu <https://hsbasu.github.io>'
]

# initiaing about dialog and params
self.about_dialog = Gtk.AboutDialog()

self.about_dialog.set_icon_name("battery-monitor")
self.about_dialog.set_title(_("About"))

self.about_dialog.set_logo_icon_name("battery-monitor")
self.about_dialog.set_program_name(_('Battery Monitor'))
self.about_dialog.set_version(__version__)

self.about_dialog.set_website_label('Official Website')
self.about_dialog.set_website('https://hsbasu.github.io/battery-monitor/')
self.about_dialog.set_comments(_('Battery Monitor is a utility tool developed on Python3 and PyGtk3. It will notify the user about charging, discharging, not charging and critically low battery state of the battery on Linux (surely if the battery is present).'))
self.about_dialog.set_copyright(copyrights)

self.about_dialog.set_authors(authors)
self.about_dialog.set_documenters(documenters)
# self.about_dialog.add_credit_section('AUR maintained by', ['Yochanan Marqos <https://github.com/yochananmarqos>'])
self.about_dialog.add_credit_section(_('Maintainer'), mainatainers)

try:
h = open('/usr/share/common-licenses/GPL', encoding="utf-8")
s = h.readlines()
gpl = ""
for line in s:
gpl += line
h.close()
self.about_dialog.set_license(gpl)
except Exception as e:
print(e)

self.about_dialog.connect('response', self.__close)
# initiaing about dialog and params
self.about_dialog = Gtk.AboutDialog()
self.about_dialog.set_transient_for(widget)

self.about_dialog.set_icon_name("battery-monitor")
self.about_dialog.set_title(_("About"))

self.about_dialog.set_logo_icon_name("battery-monitor")
self.about_dialog.set_program_name(_('Battery Monitor'))
self.about_dialog.set_version(__version__)

self.about_dialog.set_website_label('Official Website')
self.about_dialog.set_website('https://hsbasu.github.io/battery-monitor/')
self.about_dialog.set_comments(_('Battery Monitor is a utility tool developed on Python3 and PyGtk3. It will notify the user about charging, discharging, not charging and critically low battery state of the battery on Linux (surely if the battery is present).'))
self.about_dialog.set_copyright(copyrights)

self.about_dialog.set_authors(authors)
self.about_dialog.set_documenters(documenters)
# self.about_dialog.add_credit_section('AUR maintained by', ['Yochanan Marqos <https://github.com/yochananmarqos>'])
self.about_dialog.add_credit_section(_('Maintainer'), mainatainers)

try:
h = open('/usr/share/common-licenses/GPL', encoding="utf-8")
s = h.readlines()
gpl = ""
for line in s:
gpl += line
h.close()
self.about_dialog.set_license(gpl)
except Exception as e:
print(e)

self.about_dialog.connect('response', self.__close)

def show(self):
# show the about dialog.
self.about_dialog.show()
def show(self):
# show the about dialog.
self.about_dialog.show()

def __close(self, action, parameter):
"""Called when the user wants to close the about dialog.
def __close(self, action, parameter):
"""Called when the user wants to close the about dialog.

@param: action
the window to close
"""
action.destroy()
@param: action
the window to close
"""
action.destroy()
46 changes: 46 additions & 0 deletions src/BatteryMonitor/cmd_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2021-2024 Himadri Sekhar Basu <hsb10@iitbbs.ac.in>
#
# This file is part of theme-manager.
#
# theme-manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# theme-manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with theme-manager. If not, see <http://www.gnu.org/licenses/>
# or write to the Free Software Foundation, Inc., 51 Franklin Street,
# Fifth Floor, Boston, MA 02110-1301, USA..
#
# Author: Himadri Sekhar Basu <hsb10@iitbbs.ac.in>
#
import argparse
import gettext
import locale


# i18n
APP = 'battery-monitor'
LOCALE_DIR = "/usr/share/locale"
locale.bindtextdomain(APP, LOCALE_DIR)
gettext.bindtextdomain(APP, LOCALE_DIR)
gettext.textdomain(APP)
_ = gettext.gettext

description = _('A Python3-based GUI application to notify user about charging, discharging and not charging state of the laptop battery on Linux.')

def command_line_args():
# Parse arguments
parser = argparse.ArgumentParser(prog=APP, description=description, conflict_handler='resolve')

parser.add_argument('-i', '--indicator', action='store_true', dest='start_indicator', default=False, help=_("Start Battery Monitor Indicator"))
parser.add_argument('-t', '--test', action='store_true', dest='test_mode', default=False, help=_("Test Battery Monitor by running indicator"))
parser.add_argument('-v', '--verbose', action='store_true', dest='show_debug', default=False, help=_("Print debug messages to stdout i.e. terminal"))
parser.add_argument('-V', '--version', action='store_true', dest='show_version', default=False, help=_("Show version and exit"))

return parser
6 changes: 3 additions & 3 deletions src/BatteryMonitor/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(self, application):
item = Gtk.ImageMenuItem()
item.set_image(Gtk.Image.new_from_icon_name("help-about-symbolic", Gtk.IconSize.MENU))
item.set_label(_("About"))
item.connect("activate", self.__about_window)
item.connect("activate", self.__about_window, self.window)
key, mod = Gtk.accelerator_parse("<Control>F1")
item.add_accelerator("activate", accel_group, key, mod, Gtk.AccelFlags.VISIBLE)
menu.append(item)
Expand Down Expand Up @@ -389,8 +389,8 @@ def on_reset_button(self, widget):
pass
dialog.destroy()

def __about_window(self, *args):
about_window = AboutWindow()
def __about_window(self, signal, widget):
about_window = AboutWindow(widget)
about_window.show()

def open_keyboard_shortcuts(self, widget):
Expand Down
4 changes: 2 additions & 2 deletions src/BatteryMonitor/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __create_menu(self):
# Add "About" option in drop-down menu
item_about = Gtk.ImageMenuItem(_('About'))
item_about.set_image(Gtk.Image.new_from_icon_name("help-about-symbolic", Gtk.IconSize.MENU))
item_about.connect("activate", BMIndicator.open_about, Gtk.Window())
item_about.connect("activate", self.open_about, Gtk.Window())
menu.append(item_about)

item_quit = Gtk.ImageMenuItem(_('Quit'))
Expand All @@ -95,7 +95,7 @@ def __create_menu(self):
def __settings_window(self, *args):
run_BMwindow()

def open_about(self, widget):
def open_about(self, signal, widget):
about_window = AboutWindow(widget)
about_window.show()

Expand Down
33 changes: 12 additions & 21 deletions src/BatteryMonitor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#
# Author: Himadri Sekhar Basu <hsb10@iitbbs.ac.in>
#
import argparse
import gettext
import locale
import logging
import sys

from BatteryMonitor.config import APP, LOCALE_DIR, LOGFILE, __version__
from BatteryMonitor.cmd_lines import command_line_args
from BatteryMonitor.indicator import BMIndicator
from BatteryMonitor.gui import run_BMwindow

Expand All @@ -36,22 +36,6 @@
gettext.textdomain(APP)
_ = gettext.gettext

description = 'A Python3-based GUI application to change different colour variants of GTK, Icon, Cursor and other themes.'

# Parse arguments
parser = argparse.ArgumentParser(prog=APP, description=description, conflict_handler='resolve')

parser.add_argument('-i', '--indicator', action='store_true', dest='start_indicator', default=False, help=("Start Battery Monitor Indicator"))
parser.add_argument('-t', '--test', action='store_true', dest='test_mode', default=False, help=("Test Battery Monitor by running indicator"))
parser.add_argument('-v', '--verbose', action='store_true', dest='show_debug', default=False, help=("Print debug messages to stdout i.e. terminal"))
parser.add_argument('-V', '--version', action='store_true', dest='show_version', default=False, help=("Show version and exit"))

args = parser.parse_args()

if args.show_version:
print("%s: version %s" % (APP, __version__))
sys.exit(0)

# Create logger
logger = logging.getLogger('BatteryMonitor')
# Set logging level
Expand All @@ -70,6 +54,16 @@
# add the handler to the logger
logger.addHandler(fHandler)

# module logger
module_logger = logging.getLogger('BatteryMonitor.main')

parser = command_line_args()
args = parser.parse_args()

if args.show_version:
print("%s: version %s" % (APP, __version__))
sys.exit(0)

if args.show_debug:
# be verbose only when "-v[erbose]" is supplied
# Create StreamHandler which logs even debug messages
Expand All @@ -88,10 +82,7 @@
else:
TEST_MODE = False

# module logger
module_logger = logging.getLogger('BatteryMonitor.main')

def start_BM ():
def start_BM():
if args.start_indicator:
args.start_window = False
# initiaing app indicator
Expand Down