Un logiciel pour être averti quand un bus arrive

Description

Imaginez la situation : vous êtes en stage devant un écran toute la journée, et dans une boîte où on surveille pas trop vos horaires de départ. Vous avez plusieurs possibilités niveau horaires de bus pour le retour. Mais parfois vous êtes en train de geeker sur l'ordi ou alors même en train de travailler, et vous vous dites que vous prendrez le suivant. Bref en tous cas moi je me suis fait ce programme vite fait en FreePascal (avec Lazarus), avec un bus qui commence à traverser l'écran à M-10, à chaque horaire. Comme les horaires variaient, j'ai distingué horaires normaux et de vacances scolaires. A adapter bien sûr.

Ci-dessous le fichier principal :

Source / Exemple :


unit Unit1; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, StdCtrls, ComCtrls, EditBtn, Math,
  Grids, Menus, RTTICtrls, Windows, DateUtils, Unit2;

type

  { TForm1 }

  TForm1 = class(TForm)
    ImageBus: TImage;
    Label1: TLabel;
    Label2: TLabel;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    Periode: TMenuItem;
    TempsRestant: TMenuItem;
    PopupMenu1: TPopupMenu;
    Scolaire: TListBox;
    TimerSurveillance: TTimer;
    TrayIcon1: TTrayIcon;
    Vacances: TListBox;
    TimerVitesse: TTimer;
    procedure FormShow(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure MenuItem3Click(Sender: TObject);
    procedure TimerVitesseTimer(Sender: TObject);
    procedure TimerSurveillanceTimer(Sender: TObject);
    procedure TrayIcon1Click(Sender: TObject);
    procedure TrayIcon1DblClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end; 

var
  Form1: TForm1;
  ProchainHoraire: TDateTime;
  NumCorrespondant: Integer;
  Pas : Integer;
  ListeHoraire: TListBox;

implementation

{ TForm1, TForm2 }

procedure TForm1.TimerVitesseTimer(Sender: TObject);
begin
if ImageBus.Left < Form1.Width then
ImageBus.Left:= ImageBus.Left + Pas else
 begin
   TimerVitesse.Enabled := False;
   ImageBus.Left := - ImageBus.Width;
   if NumCorrespondant = ListeHoraire.Count-1 then TimerSurveillance.Enabled := False
   else
   begin
        NumCorrespondant := NumCorrespondant + 1;
        ProchainHoraire := StrToTime(ListeHoraire.Items[NumCorrespondant]);
        if NumCorrespondant = ListeHoraire.Count-1 then TrayIcon1.ShowBalloonHint;
   end;
 end;
end;

procedure TForm1.TimerSurveillanceTimer(Sender: TObject);
var
formattedDateTime : String;
Q : Float;
begin
if TimeToStr(ProchainHoraire) <> '00:00:00' then
if CompareTime(Now,ProchainHoraire-10*OneMinute) >= 0 then begin
if Form1.Visible = False then Form1.Show;
if TimerVitesse.Enabled = False then TimerVitesse.Enabled := True;
end else
if Form1.Visible then Form1.Hide;

// Régulation du pas d'avancement du bus
TempsRestant.Caption := 'Temps restant : '+IntToStr(Round(MinuteSpan(StrToTime(TimeToStr(Now)),ProchainHoraire)))+ ' min';
Q := 60*MinuteSpan(StrToTime(TimeToStr(Now)),ProchainHoraire);
If Q <> 0 then Pas := ceil((Screen.Width-ImageBus.Left)/Q);
DateTimeToString(formattedDateTime, 'hh:nn', ProchainHoraire);
TrayIcon1.Hint := 'Prochain bus à '+ formattedDateTime;
end;

procedure TForm1.TrayIcon1Click(Sender: TObject);
begin
  If Form2.Visible then Form2.Hide else Form2.Show;
end;

procedure TForm1.TrayIcon1DblClick(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.FormShow(Sender: TObject);
var I: integer;
begin
// Liste des horaires selon la date
if ((CompareDate(Today,StrToDate('11/04')) >= 0) and (CompareDate(Today,StrToDate('25/04')) <= 0)) then
begin
ListeHoraire := Vacances;
Form2.Vacances.Enabled := True;
end
else begin
ListeHoraire := Scolaire;
Form2.Scolaire.Enabled := True;
end;
Periode.Caption := 'Période : '+ ListeHoraire.Name;
// Calcul du pas d'avancement du bus selon la taille de l'écran
Pas := ceil((1000*(Screen.Width+ImageBus.Width))/600000);
// Etirement / position de la fenêtre selon l'écran
Form1.Width := Screen.Width;
Form1.Left := 0;
Form1.Top := Screen.Height - Form1.Height;
// Positionnement du bus en bas à gauche de l'écran, caché
ImageBus.Left := - ImageBus.Width;
// Transparence du fond couleur ClCream
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle,clCream,255,LWA_COLORKEY);
// Détermination du prochain horaire
for I:= ListeHoraire.Count-1 downto 0 do
if CompareTime(Now,StrToTime(ListeHoraire.Items[I])) < 0 then
begin
ProchainHoraire := StrToTime(ListeHoraire.Items[I]);
NumCorrespondant := I;
end;
if Form2.Vacances.Enabled = True then Form2.Vacances.ItemIndex := NumCorrespondant
else Form2.Scolaire.ItemIndex := NumCorrespondant;
if NumCorrespondant = Scolaire.Count-1 then TrayIcon1.ShowBalloonHint;
end;

procedure TForm1.MenuItem1Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.MenuItem2Click(Sender: TObject);
begin
  Form2.Show;
end;

procedure TForm1.MenuItem3Click(Sender: TObject);
begin

end;

initialization
  {$I unit1.lrs}

end.

Conclusion :


Je ne sais pas si c'est possible d'ouvrir les sources dans Delphi, mais ça n'est pas improbable. Vos retours m'intéressent!

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.