Exemple #1
0
 def __init__(self) -> None:
     LOG.debug("init EditSpeedProfilePresenter ")
     self.view: EditSpeedProfileViewInterface = EditSpeedProfileViewInterface(
     )
     self._profile = SpeedProfile()
     self._selected_step: Optional[SpeedStep] = None
     self._channel_name: str = ""
Exemple #2
0
    def __init__(self, database: SqliteDatabase, view: MainView,
                 presenter: MainPresenter, builder: MainBuilder,
                 udev_interactor: UdevInteractor, *args: Any,
                 **kwargs: Any) -> None:
        LOG.debug("init Application")
        GLib.set_application_name(_(APP_NAME))
        super().__init__(*args,
                         application_id=APP_ID,
                         flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
                         **kwargs)

        database.connect()
        database.create_tables(
            [SpeedProfile, SpeedStep, CurrentSpeedProfile, Setting])

        if SpeedProfile.select().count() == 0:
            load_db_default_data()

        self.add_main_option_entries(self._get_main_option_entries())
        self._view = view
        self._presenter = presenter
        self._presenter.application_quit = self.quit
        self._window: Optional[Gtk.ApplicationWindow] = None
        self._builder: Gtk.Builder = builder
        self._udev_interactor = udev_interactor
        self._start_hidden: bool = False
Exemple #3
0
 def show_add(self, channel: ChannelType) -> None:
     self._channel_name = channel.value
     profile = SpeedProfile()
     profile.name = 'New profile'
     profile.channel = channel.value
     profile.save()
     self.show_edit(profile)
Exemple #4
0
 def _select_speed_profile(self, profile_id: int,
                           channel: ChannelType) -> None:
     if profile_id == _ADD_NEW_PROFILE_INDEX:
         self.main_view.set_apply_button_enabled(channel, False)
         self.main_view.set_edit_button_enabled(channel, False)
         self.main_view.show_add_speed_profile_dialog(channel)
         self.main_view.refresh_chart(channel_to_reset=channel.value)
         self._edit_speed_profile_presenter.show_add(channel)
     else:
         profile: SpeedProfile = SpeedProfile.get(id=profile_id)
         self._profile_selected[profile.channel] = profile
         if profile.read_only:
             self.main_view.set_edit_button_enabled(channel, False)
         else:
             self.main_view.set_edit_button_enabled(channel, True)
         self.main_view.set_apply_button_enabled(channel, True)
         self.main_view.refresh_chart(profile)
Exemple #5
0
 def _get_profile_list(channel: ChannelType) -> List[Tuple[int, str]]:
     return [(p.id, p.name) for p in SpeedProfile.select().where(
         SpeedProfile.channel == channel.value)]
Exemple #6
0
class EditSpeedProfilePresenter:
    @inject
    def __init__(self) -> None:
        LOG.debug("init EditSpeedProfilePresenter ")
        self.view: EditSpeedProfileViewInterface = EditSpeedProfileViewInterface(
        )
        self._profile = SpeedProfile()
        self._selected_step: Optional[SpeedStep] = None
        self._channel_name: str = ""

    def show_add(self, channel: ChannelType) -> None:
        self._channel_name = channel.value
        profile = SpeedProfile()
        profile.name = 'New profile'
        profile.channel = channel.value
        profile.save()
        self.show_edit(profile)

    def show_edit(self, profile: SpeedProfile) -> None:
        self._channel_name = profile.channel
        self._profile = profile
        self.view.show(profile)

    def on_dialog_delete_event(self, widget: Gtk.Widget, *_: Any) -> Any:
        if self._profile is not None:
            name = self.view.get_profile_name()
            if name != self._profile.name:
                self._profile.name = name
                self._profile.save()
        return hide_on_delete(widget)

    def refresh_controls(self,
                         step: Optional[SpeedStep] = None,
                         unselect_list: bool = False) -> None:
        self._selected_step = step
        self.view.refresh_controls(step, unselect_list)

    def on_step_selected(self, tree_selection: Gtk.TreeSelection) -> None:
        LOG.debug("selected")
        list_store, tree_iter = tree_selection.get_selected()
        step = None if tree_iter is None else SpeedStep.get_or_none(
            id=list_store.get_value(tree_iter, 0))
        self.refresh_controls(step)

    def on_add_step_clicked(self, *_: Any) -> None:
        step = SpeedStep()
        step.profile = self._profile
        last_steps = (SpeedStep.select().where(
            SpeedStep.profile == step.profile).order_by(
                SpeedStep.temperature.desc()).limit(1))
        if not last_steps:
            step.temperature = MIN_TEMP
            step.duty = FAN_MIN_DUTY if step.profile.channel == ChannelType.FAN.value else PUMP_MIN_DUTY
        else:
            step.temperature = last_steps[0].temperature + 1
            step.duty = last_steps[0].duty

        self.refresh_controls(step, True)

    def on_add_profile_clicked(self, *_: Any) -> None:
        self._profile.delete_instance(recursive=True)
        self.view.hide()

    def on_delete_profile_clicked(self, *_: Any) -> None:
        self._profile.delete_instance(recursive=True)
        self.view.hide()

    def on_delete_step_clicked(self, *_: Any) -> None:
        self._selected_step.delete_instance()
        self.view.refresh_liststore(self._profile)

    def on_save_step_clicked(self, *_: Any) -> None:
        self._selected_step.temperature = self.view.get_temperature()
        self._selected_step.duty = self.view.get_duty()
        self._selected_step.save()
        self.view.refresh_liststore(self._profile)
        if not self.view.has_a_step_selected():
            self.refresh_controls()