Example #1
0
    def __init__(self, parent=None):
        super(AppFTD, self).__init__(parent)

        Registry.create()

        # self.style = 0
        self.modify_style.connect(self.change_style)

        # Initialize language manager
        LanguageManager(language='en_US')

        # Add predefined fonts
        #QFontDatabase.addApplicationFont(":/fonts/besmellah.ttf")
        QFontDatabase.addApplicationFont(":/fonts/capsuula.ttf")
        QFontDatabase.addApplicationFont(":/fonts/ubuntu.ttf")

        # Set stylesheet as Qt resource
        stylesheet = QFile(":/styles/default.css")
        stylesheet.open(QFile.ReadOnly | QFile.Text)

        self.stylesheet = QTextStream(stylesheet).readAll()
        self.setStyleSheet(self.stylesheet)

        self.setApplicationDisplayName("AppFTD")
        self.setApplicationName("AppFTD")

        self.setEffectEnabled(Qt.UI_AnimateCombo, False)
        self.setAttribute(Qt.AA_UseHighDpiPixmaps, True)

        Registry().register_signal("change_style", self.modify_style)
Example #2
0
    def __init__(self,
                 width,
                 height,
                 obj_name,
                 titlebar_name,
                 titlebar_icon,
                 parent=None):
        super(Dialog, self).__init__(parent)

        self.blur_effect = QtWidgets.QGraphicsBlurEffect()
        self.blur_effect.setBlurHints(
            QtWidgets.QGraphicsBlurEffect.PerformanceHint)

        self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
        self.setWindowFlags(self.windowFlags() & ~Qt.WindowStaysOnTopHint)

        self.setFixedSize(width, height)

        self.setObjectName(obj_name)

        self.layout = QtWidgets.QVBoxLayout()
        self.titlebar = AbstractTitleBar(self,
                                         title=titlebar_name,
                                         icon=titlebar_icon)
        self.dialog_frame = QtWidgets.QFrame(self)

        Registry().register_function("activate_dialog_blur",
                                     self.activate_blur)
        Registry().register_function("desactivate_dialog_blur",
                                     self.desactivate_blur)

        self.setup_ui()
Example #3
0
 def showEvent(self, event):
     # current_widget = QtWidgets.QApplication.instance().activeWindow()
     Registry().execute("activate_overlay")
     Registry().execute("activate_global_blur")
     # Center the dialog regarding its parent
     self.move(self.global_frame.frameGeometry().topLeft() +
               self.global_frame.rect().center() - self.rect().center())
     return super(AbstractDialog, self).showEvent(event)
Example #4
0
    def run(self):
        """
        Run the AppFTD application.x
        """
        activate_first_notification = False

        # First time checks in settings
        has_run_wizard = Settings().value('general_settings/wizard_runned')
        if not has_run_wizard:
            first_wizard = Wizard(parent=None)
            if first_wizard.exec_() == QtWidgets.QDialog.Accepted:
                Settings().setValue('general_settings/wizard_runned', 1)
                # Create the first notification only after wizard has been completed
                activate_first_notification = True
            elif first_wizard.was_cancelled:
                QCoreApplication.exit()
                sys.exit()

        # Show the SplashScreen
        show_splash = Settings().value('general_settings/splashscreen')
        if show_splash:
            splash = SplashScreen()
            splash.start_splashscreen.emit()

        # Start the main app window
        self.global_frame = GlobalFrame()

        # Make sure Qt really display the splash screen
        self.processEvents()
        self.global_frame.repaint()
        self.processEvents()

        Registry().execute('__application_init__')
        Registry().execute('__application_post_init__')

        self.processEvents()

        self.global_frame.show()

        # Show first notification program
        if activate_first_notification:
            WelcomeNotification(self.global_frame).notify(
                WelcomeNotification.OK,
                self.welcome_message,
                self.welcome_title,
                button_text='OK')

        if show_splash:
            # now kill the splashscreen
            splash.finish(self.global_frame)
            log.debug('Splashscreen closed')

        # Need to implement update checker
        # update_check = Settings().value('general_settings/update_check')
        # if update_check:
        #     process

        return self.exec_()
Example #5
0
    def _animate_main_frame_selector(self):
        """
        Animate main frame selector with position animation.

        :return:
        """
        if self.a:
            Registry().execute('expand_main_frame_selector')
        else:
            Registry().execute('hide_main_frame_selector')
        self.a = not self.a
Example #6
0
 def application(self):
     """
     Adds the app to the class dynamically.
     Windows needs to access the application in a dynamic manner.
     """
     if is_win():
         return Registry().get('application')
     else:
         if not hasattr(self, '_application') or not self._application:
             self._application = Registry().get('application')
         return self._application
Example #7
0
 def __init__(self, parent):
     """
     Register the class and initialization/clean hooks.
     """
     try:
         super(RegistryMixin, self).__init__(parent)
     except TypeError:
         super(RegistryMixin, self).__init__()
     Registry().register_function('__application_init__', self.__application_init__)
     Registry().register_function('__application_post_init__', self.__application_post_init__)
     Registry().register_function('__application_clean__', self.__application_clean__)
Example #8
0
    def close_option():
        """
        Handles the closing from application titlebar (close button).

        :return:
        """
        if Settings().value("general_settings/close") == 0:
            Registry().execute("hide_app_in_systray")
        elif Settings().value("general_settings/close") == 1:
            Registry().execute("close_application")
        else:
            log.warning("Not defined, by default, use hide in system tray")
            Registry().execute("hide_app_in_systray")
Example #9
0
 def global_frame(self):
     """
     Adds the global_frame to the class dynamically.
     """
     if not hasattr(self, '_global_frame') or not self._global_frame:
         self._global_frame = Registry().get('global_frame')
     return self._global_frame
Example #10
0
    def _close():
        """
        Close the whole program.

        :return:
        """
        Registry().execute("close_application")
Example #11
0
def main():
    """
    The main function which parses command line options and then runs
    """
    # Add path to qt_plugins instead of having mediaservice, platforms and sqldrivers in main
    # directory, currently : plugins/mediaservice - plugins/platforms - plugins/sqldrivers

    # This is required for adding furthur functionality.
    QtWidgets.QApplication.addLibraryPath(
        os.path.join(ResourcesLocation().root_dir, 'plugins'))

    # Now create and actually run the application.
    app = AppFTD(sys.argv)

    log.info('Running program')
    log.info('INI file: %s', Settings.file_path)

    Registry().register('application', app)
    app.setApplicationVersion("v0.0.1")
    app.setWindowIcon(QIcon(":/icons/app_icon.png"))
    # Registry().execute("restore_default_settings")

    # Instance check
    if app.is_already_running():
        sys.exit()

    sys.excepthook = hook_exception
    sys.exit(app.run())
Example #12
0
    def stop_athan(self):
        """
        Control the athan from notification to permit to stop athan without opening the application.

        :return:
        """
        log.debug("athan is stopped from system tray panel")
        Registry().execute("stop_current_athan")
Example #13
0
    def close_application():
        """
        This function handle the cleaning of all widgets and close the application.
        It is called when application is closed by user or a critical exception happens.

        :return:
        """
        Registry().execute("__application_clean__")
        QtWidgets.QApplication.instance().quit()
Example #14
0
 def __init__(self, parent):
     """
     Register the unique class.
     """
     try:
         super(UniqueRegistryMixin, self).__init__(parent)
     except TypeError:
         super(UniqueRegistryMixin, self).__init__()
     Registry().register(de_hump(self.__class__.__name__), self)
Example #15
0
def hook_exception(exc_type, exc_value, tracebackobj):
    """
    Global function to catch unhandled exceptions.
    Add an exception hook so that any uncaught exceptions are displayed in this window rather than somewhere where
    users cannot see it and cannot report when we encounter these problems.

    :param exc_type: The class of exception.
    :param exc_value: The actual exception object.
    :param tracebackobj: A traceback object with the details of where the exception occurred.
    """
    instance = AppFTD.instance()

    # KeyboardInterrupt is a special case.
    # We don't raise the error dialog when it occurs.
    if issubclass(exc_type, KeyboardInterrupt):
        if instance:
            instance.closeAllWindows()
        return

    separator = '-' * 80

    log_crash_file = ResourcesLocation().logs_dir + "/crash.log"
    log_dir = os.path.dirname(os.path.realpath(log_crash_file))

    # Create log dir to report crash and logging
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    notice = \
        """An unhandled exception occurred. Please report the problem\n""" \
        """using the error reporting dialog or raise issue to {}.\n""" \
        """A log has been written to "{}".\n\nError information:\n""".format("github.com/ns3098",
                                                                             log_crash_file)
    time_string = time.strftime("%Y-%m-%d, %H:%M:%S")

    tbinfofile = io.StringIO()
    traceback.print_tb(tracebackobj, None, tbinfofile)
    tbinfofile.seek(0)
    tbinfo = tbinfofile.read()
    errmsg = '%s: \n%s' % (str(exc_type), str(exc_value))

    sections = [separator, time_string, separator, errmsg, separator, tbinfo]
    msg = '\n'.join(sections)

    with open(log_crash_file, 'w') as f:
        try:
            f.write(msg)
        except OSError:
            pass

    error_box = CriticalExceptionDialog()
    error_box.text_edit.setText(str(notice) + str(msg))
    if not error_box.exec_():
        Registry().execute("close_application")
        QtWidgets.QApplication.instance().quit()
Example #16
0
    def hide_in_systray(self):
        """
        Hide the application in the system tray.

        :return:
        """
        # self.fade_out()
        self.hide()  # hide() function calls close() funtion
        log.debug("Running in background...")
        Registry().execute("show_floating_notification",
                           "program is still running in background", 3000)
Example #17
0
    def cleanup(self):
        """
        Clean up the shedulers and remove application to avoid crashed.

        :return:
        """
        self.tray_icon.hide()
        self.hide()

        # Needed for Windows to stop crashes on exit
        Registry().remove('application')
Example #18
0
    def __init__(self, parent=None):
        super(FloatingNotificationArea, self).__init__(parent)
        super(PMXMessageOverlay, self).__init__()

        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setWindowFlags(self.windowFlags() | Qt.ToolTip)
        self.setWindowFlags(self.windowFlags() & ~Qt.WindowStaysOnTopHint)

        self.setAttribute(Qt.WA_TranslucentBackground)

        Registry().register_function("show_floating_notification",
                                     self.show_message_sys)
Example #19
0
    def closeEvent(self, event):
        """
        Handles the closing from Windows taskbar.

        :param event:
        :return:
        """
        if Settings().value('general_settings/close') == 1:
            self.close_application()
        elif Settings().value('general_settings/close') == 0:
            self.hide_in_systray()
        else:
            log.warning("Not defined, by default, use hide in system tray")
            Registry().execute("hide_app_in_systray")
        event.ignore()
Example #20
0
    def __init__(self, parent=None):
        super(GlobalFrame, self).__init__(width=970,
                                          height=600,
                                          obj_name=self.__class__.__name__,
                                          parent=parent)

        self.main_layout = QtWidgets.QVBoxLayout(self)

        self.titlebar = GlobalTitlebar(self,
                                       title="AppFTD",
                                       icon=":icons/app_icon.png")
        self.frame = PrincipalFrame(self)

        # Set margin between frame and borders
        self.main_layout.setContentsMargins(0, 0, 0, 0)
        # Set margin between elements of layout
        self.main_layout.setSpacing(0)

        self.main_layout.addWidget(self.titlebar)
        self.main_layout.addWidget(self.frame)

        self.tray_icon = SystemTrayIcon(self)
        self.tray_icon.show()

        PrincipalOverlay(self)
        FloatingNotificationArea(self)
        SysTrayPanel()

        Registry().register_function("close_application",
                                     self.close_application)
        Registry().register_function("hide_app_in_systray",
                                     self.hide_in_systray)
        Registry().register_function("activate_global_blur",
                                     self.activate_blur)
        Registry().register_function("desactivate_global_blur",
                                     self.desactivate_blur)
Example #21
0
    def _modify_style_item(self, idx):
        """
        Handle changing style whether a new item is selected.

        :param idx: index of the new item.
        :return:
        """
        Registry().execute("set_main_stack", idx)

        for idx_item in range(self.listwidget_frame.count()):
            item = self.listwidget_frame.item(idx_item)
            if item.isSelected():
                side_label_instance = self.listwidget_frame.itemWidget(item)
                side_label_instance.selected.emit()
            else:
                side_label_instance = self.listwidget_frame.itemWidget(item)
                side_label_instance.unselected.emit()
Example #22
0
 def __application_init__(self):
     Registry().register_signal("show_systray_panel",
                                self.show_systray_signal)
     Registry().register_signal("hide_systray_panel",
                                self.hide_systray_signal)
Example #23
0
 def __application_init__(self):
     Registry().register_function('expand_main_frame_selector', self.set_expand_animation)
     Registry().register_function('hide_main_frame_selector', self.set_hide_animation)
Example #24
0
 def showEvent(self, event):
     Registry().execute("activate_overlay")
     Registry().execute("activate_global_blur")
     return super(WelcomeNotification, self).showEvent(event)
Example #25
0
 def __application_init__(self):
     self.hide()
     Registry().register_function("activate_overlay", self.show)
     Registry().register_function("desactivate_overlay", self.hide)
Example #26
0
 def fade_out_over(self):
     Registry().execute("desactivate_overlay")
     Registry().execute("desactivate_global_blur")
     return super(WelcomeNotification, self).fade_out_over()
Example #27
0
 def accept(self):
     Registry().execute("desactivate_overlay")
     Registry().execute("desactivate_global_blur")
     return super(AbstractDialog, self).accept()